本文整理汇总了C++中Rio_readlineb函数的典型用法代码示例。如果您正苦于以下问题:C++ Rio_readlineb函数的具体用法?C++ Rio_readlineb怎么用?C++ Rio_readlineb使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Rio_readlineb函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: response_read
Response response_read(int fd) {
rio_t rio;
char buf[MAXLINE];
Rio_readinitb(&rio, fd);
ssize_t r = Rio_readlineb(&rio, buf, MAXLINE);
if (r == 0) {
printf("Received empty response\n");
return NULL;
}
Response response = malloc(sizeof(struct Response));
sscanf(buf, "%s %d %s", response->version, &response->status_code, response->status_name);
header_read(&rio, buf, &response->header);
HeaderEntry* content_length_entry = header_find_entry(&response->header, "Content-Length");
int content_length = content_length_entry == NULL
? 0
: atoi(content_length_entry->value);
response->content_length = content_length;
response->content = malloc(response->content_length * sizeof(char));
char *content = response->content;
while (content_length > 0) {
r = Rio_readlineb(&rio, content, (size_t) content_length);
if (r > 0) {
content += r;
content_length -= r;
}
}
return response;
}
示例2: process_request
/* Read a request from a connection socket and parses its information into a
* req_t struct.
* Initally based on csapp echo() p.911
* Allocates memory for request hdrs
* returns -1 on failure, 1 if the content is local, and 0 if the content is
* remote
*/
int process_request(int fd, req_t* req){
size_t n;
char buf[MAXLINE];
rio_t rio;
req->domain = NULL;
req->path = NULL;
req->hdrs = NULL;
//Parse domain and path information
Rio_readinitb(&rio, fd);
if((n = Rio_readlineb(&rio, buf, MAXLINE)) != 0){
if(parse_req(buf, req) == -1)
return -1;
}
else return -1;
//parse header information
while((n = Rio_readlineb(&rio, buf, MAXLINE)) != 0){
if(strcmp(buf, "\r\n") == 0)
break;
if(req->hdrs != NULL){
n = strlen(req->hdrs) + strlen(buf) + 1;
req->hdrs = Realloc(req->hdrs,strlen(req->hdrs)+ n);
strcat(req->hdrs, handle_hdr(buf));
} else {
req->hdrs = Malloc(n+1);
strcpy(req->hdrs, handle_hdr(buf));
}
}
return 0;
}
示例3: getInfo
void getInfo(int fd, rio_t client, int id){
char buf1[MAXLINE];
int jobID=id;
int numBytes;
char * saveptr=NULL;
Rio_readinitb( &client,fd);
while(true){
numBytes = Rio_readlineb(&client, buf1, MAXLINE);
id1 = strtok_r(buf1, " \r\n",&saveptr);
int fileStartID=atoi(id1);
id2 = strtok_r(buf1, " \r\n",&saveptr);
int fileEndID=atoi(id2);
numBytes = Rio_readlineb(c, buf, MAXLINE);
if(numBytes<0){
Close(fd);
return ans;
}
buf[numBytes]=0;
seperate(buf, &ans.pre);
fd=Open_clientfd(ipAddress, atoi(port));
}
示例4: clientPrint
/*
* Read the HTTP response and print it out
*/
void clientPrint(int fd)
{
rio_t rio;
char buf[MAXBUF];
int length = 0;
int n;
Rio_readinitb(&rio, fd);
/* Read and display the HTTP Header */
n = Rio_readlineb(&rio, buf, MAXBUF);
while (strcmp(buf, "\r\n") && (n > 0)) {
printf("Header: %s", buf);
n = Rio_readlineb(&rio, buf, MAXBUF);
/* If you want to look for certain HTTP tags... */
if (sscanf(buf, "Content-Length: %d ", &length) == 1) {
printf("Length = %d\n", length);
}
}
/* Read and display the HTTP Body */
n = Rio_readlineb(&rio, buf, MAXBUF);
while (n > 0) {
printf("%s", buf);
n = Rio_readlineb(&rio, buf, MAXBUF);
}
}
示例5: read_requesthdrs
/* $begin read_requesthdrs */
void read_requesthdrs(rio_t *rp)
{
char buf[MAXLINE];
Rio_readlineb(rp, buf, MAXLINE);
while(strcmp(buf, "\r\n"))
Rio_readlineb(rp, buf, MAXLINE);
return;
}
示例6: read_requesthdrs
void read_requesthdrs(const rio_t *rp) {
char buf[MAXLINE];
Rio_readlineb(rp, buf, MAXLINE);
while(strcmp(buf, "\r\n")) {
Rio_readlineb(rp, buf, MAXLINE);
printf("%s", buf);
}
return;
}
示例7: read_requesthdrs
/* $begin read_requesthdrs */
void read_requesthdrs(rio_t *rp)
{
char buf[MAXLINE];
Rio_readlineb(rp, buf, MAXLINE);
while(strcmp(buf, "\r\n")) { //line:netp:readhdrs:checkterm
Rio_readlineb(rp, buf, MAXLINE);
printf("%s", buf);
}
return;
}
示例8: read_requesthdrs
/*
* read_requesthdrs - read and ignore HTTP request headers, Tiny Server
* only need first line, like "GET / HTTP/1.0"
*/
void read_requesthdrs(rio_t *rp) {
char buf[MAXLINE];
Rio_readlineb(rp, buf, MAXLINE);
while(strcmp(buf, "\r\n")) { /* check temination */
Rio_readlineb(rp, buf, MAXLINE);
printf("%s", buf); /* print out received header */
printf("i gess\n");
}
return;
}
示例9: read_requesthdrs
/*
* read_requesthdrs: just bypass the request headers
*
*/
void read_requesthdrs(rio_t *rp) {
char buf[MAXLINE];
Rio_readlineb(rp, buf, MAXLINE);
while(strcmp(buf, "\r\n")) {
Rio_readlineb(rp, buf, MAXLINE);
#ifdef DEBUG
printf("%s", buf);
#endif
}
return;
}
示例10: forward_to_client
/*
* forward_to_client - forward without write to cache
*
* used for non GET methods;
*
* return -1 on error
* return 0 on success
*/
int forward_to_client(int to_client_fd, int to_server_fd) {
rio_t rio_server;
char buf[MAXLINE];
unsigned int length = 0, size = 0;
Rio_readinitb(&rio_server, to_server_fd);
// forward status line
if (Rio_readlineb(&rio_server, buf, MAXLINE) == -1) {
return -1;
}
if (Rio_writen(to_client_fd, buf, strlen(buf)) == -1) {
return -1;
}
// forward response headers
while (strcmp(buf, "\r\n") != 0 && strlen(buf) > 0) {
if (Rio_readlineb(&rio_server, buf, MAXLINE) == -1) {
return -1;
}
get_size(buf, &size);
if (Rio_writen(to_client_fd, buf, strlen(buf)) == -1) {
return -1;
}
}
// forward response body
if (size > 0) {
while (size > MAXLINE) {
if ((length = Rio_readnb(&rio_server, buf, MAXLINE)) == -1) {
return -1;
}
if (Rio_writen(to_client_fd, buf, length) == -1) {
return -1;
}
size -= MAXLINE;
}
if (size > 0) {
if ((length = Rio_readnb(&rio_server, buf, size)) == -1) {
return -1;
}
if (Rio_writen(to_client_fd, buf, length) == -1) {
return -1;
}
}
} else {
while ((length = Rio_readnb(&rio_server, buf, MAXLINE)) > 0) {
if (Rio_writen(to_client_fd, buf, length) == -1) {
return -1;
}
}
}
return 0;
}
示例11: doit
void doit(int fd)
{
int clientfd;
char buf[MAXLINE], method[MAXLINE], uri[MAXLINE];
char host[MAXLINE], port[MAXLINE];
char filename[MAXLINE];
char cache_buf[MAX_OBJECT_SIZE];
size_t buflen;
struct cache *cache;
int cache_size = 0, cache_flag = 1;
rio_t c_rio, s_rio;
/* Read request line and headers */
Rio_readinitb(&c_rio, fd);
if (!Rio_readlineb(&c_rio, buf, MAXLINE))
return;
printf("%s", buf);
sscanf(buf, "%s %s", method, uri);
if (strcasecmp(method, "GET")) {
printf("this proxy can handle only \"GET\"\n");
return;
}
construct_requesthdrs(&c_rio, buf, filename, uri, host, port);
if (find_cache(&cache, uri) == 1) {
Rio_writen(fd, cache->data, strlen(cache->data));
} else {
clientfd = Open_clientfd(host, port);
if (clientfd < 0) {
printf("there is no such server\n");
return;
}
Rio_readinitb(&s_rio, clientfd);
Rio_writen(clientfd, buf, strlen(buf));
while ((buflen = Rio_readlineb(&s_rio, buf, MAXLINE)) != 0) {
Rio_writen(fd, buf, buflen);
if (cache_size + buflen > MAX_OBJECT_SIZE) {
cache_flag = 0;
} else {
memcpy(cache_buf + cache_size, buf, buflen);
cache_size += buflen;
}
}
if (cache_flag == 1)
create_cache(cache_buf, uri);
Close(clientfd);
}
}
示例12: doit
/*
* doit - handle one HTTP request/response transaction
*/
void doit(int fd)
{
int is_static;
struct stat sbuf;
char buf[MAXLINE], method[MAXLINE], uri[MAXLINE], version[MAXLINE];
char filename[MAXLINE], cgiargs[MAXLINE];
rio_t rio_c, rio_h;
/* Ren's Local Vars */
char host[MAXLINE], url[MAXLINE], request[MAXLINE], header[MAXLINE];
int hostfd;
/* Ren's Local Vars END */
/* Read request line and headers */
Rio_readinitb(&rio_c, fd);
Rio_readlineb(&rio_c, buf, MAXLINE);
sscanf(buf, "%s %s %s", method, uri, version);
if (strcasecmp(method, "GET")) {
clienterror(fd, method, "501", "Not Implemented",
"Tiny does not implement this method");
return;
}
printf("STUFF FROM THE CLIENT:\n");
printf("%s\n",buf);
read_requesthdrs(&rio_c);
/* Ren's code */
parseURL(buf, host, uri, version); /* parse url for hostname and uri */
hostfd = Open_clientfd(host, PORT); /* connect to host as client */
Rio_readinitb(&rio_h, hostfd); /* set up host file discriptor */
/* generate and send request to host*/
genrequest(request, method, uri);
genheader(host, header);
strcat(request, header);
printf("%s\n",request);
Rio_writen(hostfd, request, strlen(request));
/* stream information from server to client */
printf("STUFF FROM THE SERVER:\n");
while(Rio_readlineb(&rio_h, buf, MAXLINE)){
printf("%s\n",buf);
Rio_writen(fd, buf, MAXLINE);
}
printf("stream ended\n");
/* Ren's code */
}
示例13: get_requesthdrs
/* $begin get_requesthdrs */
void get_requesthdrs(rio_t *rp)
{
char buf[MAXLINE];
Rio_readlineb(rp, buf, MAXLINE);
writetime(); /* write access time in log file */
printf("%s", buf);
while(strcmp(buf, "\r\n"))
{
Rio_readlineb(rp, buf, MAXLINE);
writelog(buf);
printf("%s", buf);
}
return;
}
示例14: read_requesthdrs
void read_requesthdrs(rio_t *rp) {
char buf[MAXLINE];
runtimeLogFmt("arrive line : %d", __LINE__);
printf("in read_requesthdrs\n");
Rio_readlineb(rp, buf, MAXLINE);
runtimeLogFmt("arrive line : %d, buf is : %s\n", __LINE__, buf);
while(strcmp(buf, "\r\n")) {
Rio_readlineb(rp, buf, MAXLINE);
printf("in strcmp");
runtimeLogFmt("arrive line : %d", __LINE__);
printf("%s", buf);
}
runtimeLogFmt("arrive line : %d", __LINE__);
return;
}
示例15: echoClient
int echoClient(int argc, char** argv) {
int clientfd, port;
char* host, buf[MAXLINE];
rio_t rio;
if (argc != 3) {
fprintf(stderr, "usage: %s <host> <port>\n", argv[0]);
exit(0);
}
host = argv[1];
port = atoi(argv[2]);
clientfd = Open_clientfd(host, port);
Rio_readinitb(&rio, clientfd);
while (Fgets(buf, MAXLINE, stdin) != NULL) {
Rio_writen(clientfd, buf, strlen(buf));
// get response from server
Rio_readlineb(&rio, buf, MAXLINE);
//Fputs(buf, stdout);
}
Close(clientfd);
exit(0);
}