当前位置: 首页>>代码示例>>C++>>正文


C++ Rio_readinitb函数代码示例

本文整理汇总了C++中Rio_readinitb函数的典型用法代码示例。如果您正苦于以下问题:C++ Rio_readinitb函数的具体用法?C++ Rio_readinitb怎么用?C++ Rio_readinitb使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了Rio_readinitb函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: 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);
    }
}
开发者ID:bellatoris,项目名称:System_Programming,代码行数:50,代码来源:proxy.c

示例2: 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 */
}
开发者ID:gitbanshee,项目名称:proxy,代码行数:52,代码来源:proxy.c

示例3: check_clients

void check_clients(pool *p)
{
  int i, connfd, n;
  char buf[MAXLINE];
  rio_t rio;
  
  for (i = 0; (i <= p->maxi) && (p->nready > 0); i++) {
    connfd = p->clientfd[i];
    rio = p->clientrio[i];
    
    //if the descriptor is ready, echo a text line from it
    if ( (connfd > 0) && (FD_ISSET(connfd, &p->ready_set))) {
      p->nready--;
      if ( (n = Rio_readinitb(&rio, buf, MAXLINE)) != 0) {
        byte_cnt += n;
        printf("server received %d (%d total) bytes on fd %d\n", n, byte_cnt, connfd);
        Rio_writen(connfd, buf, n);
      }
      
      //EOF detected, remove descriptor from pool
      else {
        Close(connfd);
        FD_CLR(connfd, &p->read_set);
        p->clienfd[i] = -1;
      }
    }
  }
}
开发者ID:r00tjimmy,项目名称:codeBox,代码行数:28,代码来源:concurrency_mulio_pool.c

示例4: keyboard

void * keyboard(void * vargp) {
    char buf[MAXLINE];
    rio_t rio;

    fprintf(stderr,"fprintf 7\n");

    int clientfd = *((int*) vargp);

    fprintf(stderr,"fprintf 8\n");

    Rio_readinitb(&rio, clientfd);

    while(Fgets(buf, MAXLINE, stdin) != NULL) {
        fprintf(stderr,"fprintf 9\n");
        if(active)
            Rio_writen(clientfd, buf, strlen(buf));
        else
            break;
    }

    if(active) {
        fprintf(stderr,"fprintf 10\n");
        strcpy(buf, "$q\n");
        Rio_writen(clientfd, buf, strlen(buf));
    }

    return NULL;
}
开发者ID:pmkenned,项目名称:pimp,代码行数:28,代码来源:client.c

示例5: main

int main(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);

  printf("type:"); fflush(stdout);
  while (Fgets(buf, MAXLINE, stdin) != NULL) {
    Rio_writen(clientfd, buf, strlen(buf));
    Rio_readlineb(&rio, buf, MAXLINE);
    printf("echo:");
    Fputs(buf, stdout);
    printf("type:"); fflush(stdout);
  }
  Close(clientfd);
  exit(0);
}
开发者ID:kalaluthien,项目名称:proxylab,代码行数:28,代码来源:echoclient.c

示例6: 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;
}
开发者ID:jdbrandon,项目名称:proxy,代码行数:38,代码来源:proxy.c

示例7: receive_message

void receive_message(){
    char buf[MAXLINE];
    char header[MAXLINE];
    char buf1[MAXLINE];
    char buf2[MAXLINE];
    char buf3[MAXLINE];
    rio_t client;
    
    Rio_readinitb(&client, clientfd);
    while(1) {
        //rio_readp(clientfd,buf,MAXLINE);
        Rio_readlineb(&client,buf,MAXLINE);
        if (strcmp(buf,"error\r\n")==0){
            printf("The file you want to download doesn't exist!\n");
            close(clientfd);
            exit(1);
        }
        if (strcmp(buf, "finish\r\n") == 0){
            break;
        }
        sscanf(buf, "%s %s %s %s", header, buf1, buf2, buf3);
        if (strcmp(header, "total") == 0){
            total_num = atoi(buf1);
            user_list = malloc(sizeof(user_list)*total_num);
        }
        if (strcmp(header,"user")==0){
            int i = atoi(buf1);
            user_list[i-1].IP = strdup(buf2);
            user_list[i-1].port = atoi(buf3);
        }
        //printf("buf is %s\n",buf);
        memset(buf, 0, strlen(buf));
    }
    close(clientfd);
}
开发者ID:fredlumm,项目名称:BitTorrent_FileSharing,代码行数:35,代码来源:torrent.c

示例8: 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;
}
开发者ID:aumgn,项目名称:Cours,代码行数:33,代码来源:http.c

示例9: 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);
  }
}
开发者ID:mushahid6666,项目名称:MultiThreaded-WebServer,代码行数:31,代码来源:client.c

示例10: main

int main(int argc, char** argv) {
    int clientfd;
    char* hostname = argv[1];
    char* filename = argv[2];
    int port = atoi(argv[3]);

    char data[60];
    strcpy(data, "GET /");
    strcat(data, filename);
    strcat(data, " HTTP/1.1\r\nHost: ");
    strcat(data, hostname);
    strcat(data, "\r\n\r\n");
    printf("Constructed Data: %s\n", data);

    char buffer[MAXLINE];   // Using MAXLINE from csapp
    bzero(buffer, MAXLINE);
    buffer[0] = 'x';

    rio_t rio;

    clientfd = Open_clientfd(hostname, port);

    Rio_readinitb(&rio, clientfd);
    rio_writen(clientfd, data, strlen(data));

    while (strlen(buffer)>0) {

        Rio_readlineb (&rio, buffer, MAXLINE);
        printf("%s\n", buffer);
    }

    close(clientfd);
    exit(0);
}
开发者ID:sukritchhabra,项目名称:sc3349-cs283-winter2016,代码行数:34,代码来源:myClient.c

示例11: 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));

}
开发者ID:Jiaran,项目名称:MapReduce,代码行数:25,代码来源:reduce.cpp

示例12: main

int main(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) {
    printf("client get: %s\n",buf);
	Rio_writen(clientfd, buf, strlen(buf));
    printf("client buf: %s\n",buf);
	Rio_readlineb(&rio, buf, MAXLINE);
	Fputs(buf, stdout);
    }
    
//    printf("outside\n");
    Close(clientfd); //line:netp:echoclient:close
    exit(0);
}
开发者ID:MujingZhou,项目名称:Apr.2015_Caching-Web-Proxy,代码行数:28,代码来源:echoclient.c

示例13: main

int main(int argc, char **argv)
{
        int n;
        rio_t rio;
        char buf[MAXLINE];

        if (argc > 2) {
                fprintf(stderr, "usage: %s [filename]\n", argv[0]);
                return -1;
        }

        /* 这里将标准输入的文件描述符,重定位到输入文件的描述符 */
        if (argc == 2) {
                char *filename = argv[1];
                int fd = Open(filename, O_RDONLY, 0);
                int ret = dup2(fd, STDIN_FILENO); /* 将标准输入重定位到 fd */
                if (ret < 0) {
                        perror("dup2");
                        return -1;
                }
        }

        /* 没有输入文件名,将标准输入拷贝到标准输出 */
        Rio_readinitb(&rio, STDIN_FILENO);
        while ((n = Rio_readlineb(&rio, buf, MAXLINE)) != 0)
                Rio_writen(STDOUT_FILENO, buf, n);

        return 0;
}
开发者ID:09zwcbupt,项目名称:csapp,代码行数:29,代码来源:ex10-10.c

示例14: getSize

int getSize(int fd) {
  //stats.req_arrival = id.req_arrival;

  int is_static;
  struct stat sbuf;
  char buf[MAXLINE], method[MAXLINE], uri[MAXLINE], version[MAXLINE];
  char filename[MAXLINE], cgiargs[MAXLINE];
  rio_t rio;
   
  //stats.size = -1;

  Rio_readinitb(&rio, fd);
  Rio_readlineb(&rio, buf, MAXLINE);
  sscanf(buf, "%s %s %s", method, uri, version);
  //close(fd);

  printf("%s %s %s\n", method, uri, version);

  if (strcasecmp(method, "GET")) {
    requestError(fd, method, "501", "Not Implemented",
		 "CS537 Server does not implement this method");
    return 0;
  }
  requestReadhdrs(&rio);

  is_static = requestParseURI(uri, filename, cgiargs);
  if (stat(filename, &sbuf) < 0) {
    requestError(fd, filename, "404", "Not found", "CS537 Server could not find this file");
    return 0;
  }
  return sbuf.st_size;
}
开发者ID:BBP7,项目名称:Operating-Systems,代码行数:32,代码来源:request.c

示例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);
}
开发者ID:DeathPoem,项目名称:Practice,代码行数:25,代码来源:main.c


注:本文中的Rio_readinitb函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。