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


C++ Rio_writen函数代码示例

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


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

示例1: not_found

/* Helper function that writes a simple html error page to a file descriptor
 * for 404 error: not found
 */
void not_found(int fd){
    Rio_writen(fd,"<html>\r\n", 8);
    Rio_writen(fd,"<body>\r\n", 8);
    Rio_writen(fd,"404: not found", 14);
    Rio_writen(fd,"</body>\r\n", 9);
    Rio_writen(fd,"</html>\r\n", 9);
}
开发者ID:jdbrandon,项目名称:proxy,代码行数:10,代码来源:proxy.c

示例2: requestError

void requestError(	int fd,
			char *cause,
			char *errnum,
			char *shortmsg,
			char *longmsg )
{
	char buf[MAXLINE], body[MAXBUF];

	printf("Request ERROR\n");

	/* Create the body of the error message */
	sprintf(body, "<html><title>CS537 Error</title>");
	sprintf(body, "%s<body bgcolor=""fffff"">\r\n", body);
	sprintf(body, "%s%s: %s\r\n", body, errnum, shortmsg);
	sprintf(body, "%s<p>%s: %s\r\n", body, longmsg, cause);
	sprintf(body, "%s<hr>CS537 Web Server\r\n", body);

	/* Write out the header information for this response */
	sprintf(buf, "HTTP/1.0 %s %s\r\n", errnum, shortmsg);
	Rio_writen(fd, buf, strlen(buf));
	printf("%s", buf);

	sprintf(buf, "Content-Type: text/html\r\n");
	Rio_writen(fd, buf, strlen(buf));
	printf("%s", buf);

	sprintf(buf, "Content-Length: %lu\r\n\r\n", strlen(body));
	Rio_writen(fd, buf, strlen(buf));

	/* Write out the content */
	Rio_writen(fd, body, strlen(body));
	printf("%s", body);
}
开发者ID:JTReed,项目名称:OSUndergrad,代码行数:33,代码来源:request.c

示例3: serve_static

/* $begin serve_static */
void serve_static(int fd, char *filename, int filesize) 
{
    int srcfd;
    char *srcp, filetype[MAXLINE], buf[MAXBUF];

	int n;
	srcp = malloc(filesize);
 
    /* Send response headers to client */
    get_filetype(filename, filetype);       //line:netp:servestatic:getfiletype
    sprintf(buf, "HTTP/1.0 200 OK\r\n");    //line:netp:servestatic:beginserve
    sprintf(buf, "%sServer: Tiny Web Server\r\n", buf);
    sprintf(buf, "%sContent-length: %d\r\n", buf, filesize);
    sprintf(buf, "%sContent-type: %s\r\n\r\n", buf, filetype);
    Rio_writen(fd, buf, strlen(buf));       //line:netp:servestatic:endserve

    /* Send response body to client */
    srcfd = Open(filename, O_RDONLY, 0);    //line:netp:servestatic:open
    //srcp = Mmap(0, filesize, PROT_READ, MAP_PRIVATE, srcfd, 0);//line:netp:servestatic:mmap
    while ((n = rio_readn(srcfd, srcp, filesize + 1)) != 0)
	 { Rio_writen(fd, srcp, filesize); }
	 Close(srcfd);                           //line:netp:servestatic:close
    free(srcp);
	 // Rio_writen(fd, srcp, filesize);         //line:netp:servestatic:write
    // Munmap(srcp, filesize);                 //line:netp:servestatic:munmap
}
开发者ID:Zak-Olyarnik,项目名称:CS-283,代码行数:27,代码来源:server.c

示例4: serve_static

/* $begin serve_static */
void serve_static(int fd, char *filename, int filesize) 
{
    int srcfd;
    char *srcp, filetype[MAXLINE], buf[MAXBUF];
 
    /* Send response headers to client */
    get_filetype(filename, filetype);
    sprintf(buf, "HTTP/1.0 200 OK\r\n");
    sprintf(buf, "%sServer: Tiny Web Server\r\n", buf);
    sprintf(buf, "%sContent-length: %d\r\n", buf, filesize);
    sprintf(buf, "%sContent-type: %s\r\n\r\n", buf, filetype);

    /* Send response body to client */
    srcfd = Open(filename, O_RDONLY, 0);
    srcp = Mmap(0, filesize, PROT_READ, MAP_PRIVATE, srcfd, 0);
    Close(srcfd);

    if(ishttps)
    {
    	SSL_write(ssl, buf, strlen(buf));
	SSL_write(ssl, srcp, filesize);
    }
    else
    {
	Rio_writen(fd, buf, strlen(buf));
	Rio_writen(fd, srcp, filesize);
    }
    Munmap(srcp, filesize);
}
开发者ID:BeginMan,项目名称:Linux-C-Web-Server,代码行数:30,代码来源:back.c

示例5: serve_static

/*
 * serve_static - serve static content
 */
void serve_static(int connfd, char* filename, struct stat filestat) {

    int srcfd;
    char *srcp;
    char filetype[MAXLINE], body[MAXBUF];
    
    /* get file type */
    if (strstr(filename, ".html"))
	strcpy(filetype, "text/html");
    else if (strstr(filename, ".gif"))
	strcpy(filetype, "text/gif");
    else if (strstr(filename, ".jpg"))
	strcpy(filetype, "text/jpg");
    else
	strcpy(filetype, "text/plain");

    /* send response headers to client */
    sprintf(body, "HTTP/1.0 200 OK\r\n");
    sprintf(body, "%sServer: Tiny Web Server\r\n", body);
    sprintf(body, "%sContent-length: %d\r\n", body, (int)filestat.st_size);
    sprintf(body, "%sContent-type: %s\r\n\r\n", body, filetype);
    Rio_writen(connfd, body, strlen(body));
    
    /* send response body to client */
    srcfd = Open(filename, O_RDONLY, 0);
    /* map the file into a chunk of virtual memory */
    srcp = Mmap(NULL, filestat.st_size, PROT_READ, MAP_PRIVATE, srcfd, 0);
    Close(srcfd);
    Rio_writen(connfd, srcp, filestat.st_size);
    Munmap(srcp, filestat.st_size);
}
开发者ID:minhajksm,项目名称:code,代码行数:34,代码来源:my_tiny.c

示例6: clienterror

/*
 * clienterror - returns an error message to the client
 */
void clienterror(int fd, char *cause, char *errnum, 
		 char *shortmsg, char *longmsg) {

    char buf[MAXLINE], body[MAXBUF];

    /* Build HTTP response, like
     * 	HTTP/1.0 404 Not Found
     *	Content-type: text/html
     *	Content-length: xxx
     *
     *	Tiny couldn't find file.
     *	Server: 'The Tiny Web Server'
    */
    /* Build the HTTP response body */
    sprintf(body, "<html><title>Tiny Error</title>");
    sprintf(body, "%s<body bgcolor=""ffffff"">\r\n", body);
    sprintf(body, "%s%s: %s\r\n", body, errnum, shortmsg);
    sprintf(body, "%s<p>%s: %s\r\n", body, longmsg, cause);
    sprintf(body, "%s<hr><em>The Tiny Web server</em>\r\n", body);

    /* Print the HTTP response */
    sprintf(buf, "HTTP/1.0 %s %s\r\n", errnum, shortmsg);
    Rio_writen(fd, buf, strlen(buf));
    sprintf(buf, "Content-type: text/html\r\n");
    Rio_writen(fd, buf, strlen(buf));
    sprintf(buf, "Content-length: %d\r\n\r\n", (int)strlen(body));
    Rio_writen(fd, buf, strlen(buf));
    Rio_writen(fd, body, strlen(body));
}
开发者ID:minhajksm,项目名称:code,代码行数:32,代码来源:my_tiny.c

示例7: serve_static

/* $begin serve_static */
void serve_static(int fd, char *filename, int filesize, int is_head) {
  int srcfd;
  char *srcp, filetype[MAXLINE], buf[MAXBUF];

  /* Send response headers to client */
  get_filetype(filename, filetype);     // line:netp:servestatic:getfiletype
  sprintf(buf, "HTTP/1.0 200 OK\r\n");  // line:netp:servestatic:beginserve
  sprintf(buf, "%sServer: Tiny Web Server\r\n", buf);
  // char c;
  // c = getchar();
  // printf("%c\n", c);/*to ignore the EPIPE error!!! */
  sprintf(buf, "%sContent-length: %d\r\n", buf, filesize);
  sprintf(buf, "%sContent-type: %s\r\n\r\n", buf, filetype);
  Rio_writen(fd, buf, strlen(buf));  // line:netp:servestatic:endserve

  if (is_head) {
    return;  // the request is head
  }

  /* Send response body to client */
  srcfd = Open(filename, O_RDONLY, 0);  // line:netp:servestatic:open
  srcp = Mmap(0, filesize, PROT_READ, MAP_PRIVATE, srcfd, 0);  //
  Close(srcfd);                                                //
  Rio_writen(fd, srcp, filesize);                              //
  Munmap(srcp, filesize);                                      //
}
开发者ID:xibaohe,项目名称:tiny_server,代码行数:27,代码来源:do_task_nonblock.c

示例8: requestServeStatic

void requestServeStatic(int fd, char *filename, int filesize) 
{
   int srcfd;
   char *srcp, filetype[MAXLINE], buf[MAXBUF];

   requestGetFiletype(filename, filetype);

   srcfd = Open(filename, O_RDONLY, 0);

   // Rather than call read() to read the file into memory, 
   // which would require that we allocate a buffer, we memory-map the file
   srcp = Mmap(0, filesize, PROT_READ, MAP_PRIVATE, srcfd, 0);
   Close(srcfd);

   // put together response
   sprintf(buf, "HTTP/1.0 200 OK\r\n");
   sprintf(buf, "%sServer: CS537 Web Server\r\n", buf);
   sprintf(buf, "%sContent-Length: %d\r\n", buf, filesize);
   sprintf(buf, "%sContent-Type: %s\r\n\r\n", buf, filetype);

   Rio_writen(fd, buf, strlen(buf));

   //  Writes out to the client socket the memory-mapped file 
   Rio_writen(fd, srcp, filesize);
   Munmap(srcp, filesize);

}
开发者ID:jimbokroneus,项目名称:OS-Projects,代码行数:27,代码来源:request.c

示例9: remove_channel

void remove_channel(int fd, const char *channel, char *sendbuf) {

    node_t *prev, *node;

    printf("Removing Channel %s\n", channel);

    for (prev = NULL, node = LocalIRCList.ChannelList.header; node != NULL; prev = node, node = node->next) {
        printf("Existing Channel: %s", node->data);
        if (strcasecmp(node->data, channel) == 0) {
            printf("...Found!\n");
            break;
        }
        printf("\n");
    }
    if (node != NULL) {
        if (prev == NULL)
            LocalIRCList.ChannelList.header = node->next;
        else
            prev->next = node->next;
        LocalIRCList.ChannelList.Count--;

        printf("Removed Channel: %s\n", node->data);
        free(node->data);
        free(node);       
        // BroadcastSelf();
        sprintf(sendbuf, "OK\r\n");
        Rio_writen(fd, sendbuf, strlen(sendbuf));
        return;
    }
    printf("Cannot Find Channel\n");
    sprintf(sendbuf, "OK\r\n");
    Rio_writen(fd, sendbuf, strlen(sendbuf));
    return;
	
}
开发者ID:VikingMew,项目名称:network-lab,代码行数:35,代码来源:irc.c

示例10: request_write

void request_write(Request request, int fd) {
    char buf[MAXLINE];
    sprintf(buf, "%s %s %s\r\n", request->method, request->uri, request->version);
    Rio_writen(fd, buf, strlen(buf));
    header_write(request->header, buf, fd);
    Rio_writen(fd, "\r\n", 2);
}
开发者ID:aumgn,项目名称:Cours,代码行数:7,代码来源:http.c

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

示例12: bad_request

/* Helper function that writes a simple html error page to a file descriptor
 * for 400 error: bad request 
 */
void bad_request(int fd){
    Rio_writen(fd,"<html>\r\n", 8);
    Rio_writen(fd,"<body>\r\n", 8);
    Rio_writen(fd,"400: bad request", 16);
    Rio_writen(fd,"</body>\r\n", 9);
    Rio_writen(fd,"</html>\r\n", 9);
}
开发者ID:jdbrandon,项目名称:proxy,代码行数:10,代码来源:proxy.c

示例13: sendResponse

/*
 * Sends the necessary headers and data to the client
 *
*/
void sendResponse(int fd, char *data, char *type, char *version, int size)
{
	char buffer[MAXLINE];

	if (strcmp(version, "HTTP/1.1") == 0)
	{
		sprintf(buffer, "%s 100 Continue\r\n", version);
	}
	else
	{
		sprintf(buffer, "%s 200 OK\r\n", version);
	}
	
	Rio_writen(fd, buffer, strlen(buffer));
	printf("\n%s", buffer);
	sprintf(buffer, "Content-length: %d\r\n", size);

	Rio_writen(fd, buffer, strlen(buffer));
	printf("%s", buffer);	
	sprintf(buffer, "Content-type: %s\r\n\r\n", type);

	Rio_writen(fd, buffer, strlen(buffer));
	printf("%s", buffer);
	Rio_writen(fd, data, size);
	printf("%s", data);
}
开发者ID:brandj94,项目名称:WebServer,代码行数:30,代码来源:sysstatd.c

示例14: clienterror

/* $begin clienterror */
void clienterror(int fd, char *cause, char *errnum, 
		 char *shortmsg, char *longmsg) 
{
    char buf[MAXLINE], body[MAXBUF];

    /* Build the HTTP response body */
    sprintf(body, "<html><title>Tiny Error</title>");
    sprintf(body, "%s<body bgcolor=""ffffff"">\r\n", body);
    sprintf(body, "%s%s: %s\r\n", body, errnum, shortmsg);
    sprintf(body, "%s<p>%s: %s\r\n", body, longmsg, cause);
    sprintf(body, "%s<hr><em>The Tiny Web server</em>\r\n", body);

    /* Print the HTTP response */
    sprintf(buf, "HTTP/1.0 %s %s\r\n", errnum, shortmsg);
    sprintf(buf, "%sContent-type: text/html\r\n",buf);
    sprintf(buf, "%sContent-length: %d\r\n\r\n",buf,(int)strlen(body));

    printf("...................\n");
    printf("%s\n",buf);
    printf("%s\n",body);
    printf("...................\n");

    if(ishttps)
    {
	SSL_write(ssl,buf,strlen(buf));
	SSL_write(ssl,body,strlen(body));
    }
    else
    {
    	Rio_writen(fd, buf, strlen(buf));
	Rio_writen(fd, body, strlen(body));
    }
}
开发者ID:BeginMan,项目名称:Linux-C-Web-Server,代码行数:34,代码来源:back.c

示例15: requestServeStatic

void requestServeStatic(request_t request, char *filename, int filesize, thread_t * thread)
{
    int fd = request.connfd;
    int srcfd;
    char *srcp, filetype[MAXLINE], buf[MAXBUF];
    char tmp = 0;
    int i;
    
    requestGetFiletype(filename, filetype);
    
    srcfd = Open(filename, O_RDONLY, 0);
    
	double time_start_read = get_time();
    // Rather than call read() to read the file into memory, 
    // which would require that we allocate a buffer, we memory-map the file
    srcp = Mmap(0, filesize, PROT_READ, MAP_PRIVATE, srcfd, 0);
    Close(srcfd);
    
    // The following code is only needed to help you time the "read" given 
    // that the file is memory-mapped.  
    // This code ensures that the memory-mapped file is brought into memory 
    // from disk.
    
    // When you time this, you will see that the first time a client 
    //requests a file, the read is much slower than subsequent requests.
    for (i = 0; i < filesize; i++) {
	tmp += *(srcp + i);
    }
    
    double time_end_read = get_time();
	request.Stat_req_read = time_end_read - time_start_read;
	
	double time_start_write = get_time();
	request.Stat_req_complete = time_start_write - request.Stat_req_arrival;
	
    sprintf(buf, "HTTP/1.0 200 OK\r\n");
    sprintf(buf, "%s Server: CS537 Web Server\r\n", buf);
    
    // CS537: Your statistics go here -- fill in the 0's with something useful!
    sprintf(buf, "%s Stat-req-arrival: %d\r\n", buf, request.Stat_req_arrival);
    sprintf(buf, "%s Stat-req-dispatch: %d\r\n", buf, request.Stat_req_dispatch);
    sprintf(buf, "%s Stat-req-read: %d\r\n", buf, request.Stat_req_read);
    sprintf(buf, "%s Stat-req-complete: %d\r\n", buf, request.Stat_req_complete);
    sprintf(buf, "%s Stat-req-age: %d\r\n", buf, request.Stat_req_age);
    sprintf(buf, "%s Stat-thread-id: %d\r\n", buf, thread->Stat_thread_id);
    sprintf(buf, "%s Stat-thread-count: %d\r\n", buf, thread->Stat_thread_count);
    sprintf(buf, "%s Stat-thread-static: %d\r\n", buf, thread->Stat_thread_static);
    sprintf(buf, "%s Stat-thread-dynamic: %d\r\n", buf, thread->Stat_thread_dynamic);
    
    sprintf(buf, "%s Content-Length: %d\r\n", buf, filesize);
    sprintf(buf, "%s Content-Type: %s\r\n\r\n", buf, filetype);
    
    Rio_writen(fd, buf, strlen(buf));
    
    //  Writes out to the client socket the memory-mapped file 
    Rio_writen(fd, srcp, filesize);
    Munmap(srcp, filesize);
    
}
开发者ID:tshao4,项目名称:CS537,代码行数:59,代码来源:request.c


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