本文整理汇总了C++中rio_readlineb函数的典型用法代码示例。如果您正苦于以下问题:C++ rio_readlineb函数的具体用法?C++ rio_readlineb怎么用?C++ rio_readlineb使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了rio_readlineb函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: process_rstheader
void process_rstheader(rio_t *rp)
{
char buf[MAXLEN];
rio_readlineb(rp, buf, MAXLEN);
while(strcmp(buf, "\r\n"))
rio_readlineb(rp, buf, MAXLEN);
}
开发者ID:Zirconi,项目名称:whd,代码行数:7,代码来源:whd.c
示例2: echo
void echo(int connfd){
size_t n;
char buf[MAXLINE];
rio_t rio;
rio_readinitb(&rio, connfd);
if((n = rio_readlineb(&rio, buf, MAXLINE)) < 0){
fprintf(stderr, "rio_readlineb error \n");
exit(0);
}
while(n != 0){
printf("server received %d bytes\n", n);
if(rio_writen(connfd, buf, n) != n){
fprintf(stderr, "rio_writen error\n");
exit(0);
}
if((n = rio_readlineb(&rio, buf, MAXLINE)) < 0){
fprintf(stderr, "rio_readlineb error \n");
exit(0);
}
}
}
开发者ID:kshitijgupta,项目名称:all-code,代码行数:26,代码来源:server.c
示例3: send_requesthdrs
/* $begin read_requesthdrs */
void send_requesthdrs(rio_t *rp, int file, char* host)
{
char buf[MAXLINE];
int hosthdr = 0;
int bufLen;
bufLen = rio_readlineb(rp, buf, MAXLINE);
rio_writen(file, buf, bufLen);
while(strcmp(buf, "\r\n"))
{
bufLen = rio_readlineb(rp, buf, MAXLINE);
if(!strncasecmp(buf, "Connection", strlen("Connection")))
{
continue;
}
if(!strncasecmp(buf, "Proxy-Connection", strlen("Proxy-Connection")))
{
continue;
}
if(!strncasecmp(buf, "User-Agent", strlen("User-Agent")))
{
continue;
}
if(!strncasecmp(buf, "Accept", strlen("Accept")))
{
continue;
}
if(!strncasecmp(buf, "Accept-Encoding", strlen("Accept-Encoding")))
{
continue;
}
if(!strncasecmp(buf, "Host", strlen("Host")))
{
hosthdr = 1;
}
//this is broken. When we understand how to do Host, we'll fix it.
if(0 && !strncasecmp(buf,"\r\n",strlen("\r\n")) && !hosthdr)
{
char tmp[MAXLINE];
sprintf(tmp, "Host: %s\r\n",host);
rio_writen(file, tmp, strlen(tmp));
printf(tmp);
}
rio_writen(file, buf, bufLen);
if(!strncasecmp(buf,"Cookie",strlen("Cookie")))
{
printf("Cookie: <POTENTIALLY BINARY DATA REDACTED>\r\n");
}
else
{
printf(buf);
}
}
}
开发者ID:stale2000,项目名称:Computer-Systems,代码行数:59,代码来源:proxy.c
示例4: SendRequest
/* Send Request from browser to the server*/
int SendRequest(int clientfd, rio_t serverrio_t, char* hostname, char* uriname){
int i,byte;
int flag[5] = {0};
char headerBuff[MAXHEADERSIZE];
char requestLine[MAXHEADERSIZE];
sprintf(requestLine,"GET %s HTTP/1.0\r\n",uriname);
rio_writen(clientfd,requestLine,strlen(requestLine));
byte = rio_readlineb(&serverrio_t,headerBuff,sizeof(headerBuff));
if( strstr(headerBuff,"Host:") != NULL){
getHostname(headerBuff,hostname);
}
sprintf(requestLine,"Host: %s\r\n",hostname);
rio_writen(clientfd,requestLine,strlen(requestLine));
while( (byte = rio_readlineb(&serverrio_t,headerBuff,sizeof(headerBuff))) >0){
if(strncmp(headerBuff,"GET",3) == 0){
}
else if(strncmp(headerBuff,"Host",4) == 0){
}
else if(strncmp(headerBuff,"\r",1) == 0){
break;
}
else if(strncmp(headerBuff,"User-Agent:",11) == 0){
rio_writen(clientfd,headerSet[0],strlen(headerSet[0]));
flag[0] = 1;
}
else if(strncmp(headerBuff,"Accept:",7) == 0){
rio_writen(clientfd,headerSet[1],strlen(headerSet[1]));
flag[1] = 1;
}
else if(strncmp(headerBuff,"Accept-Encoding:",16) == 0){
rio_writen(clientfd,headerSet[2],strlen(headerSet[2]));
flag[2] = 1;
}
else if(strncmp(headerBuff,"Connection:",11) == 0){
rio_writen(clientfd,headerSet[3],strlen(headerSet[3]));
flag[3] = 1;
}
else if(strncmp(headerBuff,"Proxy-Connection:",17) == 0){
rio_writen(clientfd,headerSet[4],strlen(headerSet[4]));
flag[4] = 1;
}
else{
rio_writen(clientfd,headerBuff,strlen(headerBuff));
}
}
for(i = 0 ; i < 5 ;i++){
if(flag[i] == 0){
rio_writen(clientfd,headerSet[i],strlen(headerSet[i]));
flag[i] = 1;
}
}
rio_writen(clientfd,"\r\n",strlen("\r\n"));
return 1;
}
开发者ID:sam9595,项目名称:15213_Proxy,代码行数:59,代码来源:proxy.c
示例5: 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);
}
}
开发者ID:Viredery,项目名称:web_proxy,代码行数:9,代码来源:proxy.c
示例6: 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);
printf("%s", buf);
}
return;
}
开发者ID:Thomas-C-Voegeli,项目名称:web-server-c,代码行数:11,代码来源:tiny_server.c
示例7: parse_request
/* parse_request parses request from client and stores the
* information in a client_request structure */
int parse_request(struct client_request *request, int clientfd)
{
char buf[MAXBUF], method[MAXLINE], uri[MAXLINE], port[MAXLINE], *ptr;
rio_t rio;
port[0] = 0;
rio_readinitb(&rio, clientfd);
rio_readlineb(&rio, buf, MAXLINE - 1);
if (sscanf(buf, "%s %s %*s", method, uri) < 2)
{
printf("parsing error %s\n", buf);
return -1;
}
strcpy(request->request_line, buf);
if (sscanf(uri, "http://%[^:/]:%[^/]/%*s", request->host, port) < 1)
return -1;
if (*port == 0)
request->server_port = 80;
else
request->server_port = atoi(port);
if (strcmp(method, "GET"))
return -2;
sprintf(request->request, "GET %s HTTP/1.0\r\nHost: %s\r\n", uri, request->host);
/* reads all headers */
while (1)
{
rio_readlineb(&rio, buf, MAXLINE - 1);
/* need to change connection header to close */
if ((ptr = strstr(buf, "Connection:")) != NULL)
{
strcat(request->request, "Connection: close\n");
continue;
}
/* need to delete keep-alive header */
if ((ptr = strcasestr(buf, "keep-alive")) != NULL)
continue;
/* host is already in the header */
if ((ptr = strstr(buf, "Host:")) != NULL)
continue;
strcat(request->request, buf);
if (*buf == '\r' && *(buf + 1) == '\n')
break;
}
request->request_length = strlen(request->request);
return 0;
}
开发者ID:samzcmu,项目名称:proxy,代码行数:55,代码来源:proxy.c
示例8: hdr_concat
/* $begin hdr_concat */
void hdr_concat(rio_t *rio_client,char *hdr_server,char *hostname, char *pathname)
{
char add_info[MAXLINE];
char buf[MAXLINE];
char *ptr;
int n=0;
int off=0;
if (rio_readlineb(rio_client,buf,MAXLINE)!=0){
ptr=buf;
if (!strncmp(buf,"Host:",5)){
ptr+=5;
*ptr='\0';
strstr(hostname,ptr);
}
}
memset(buf,0,MAXLINE);
memset(add_info,0,MAXLINE);
while((n=rio_readlineb(rio_client,buf,MAXLINE))>0){
if (!strcmp(buf,"\r\n"))
break;
ptr=buf;
if (!strncmp(buf,"User-Agent:",11)||
!strncmp(buf,"Accept:",7)||
!strncmp(buf,"Accept-Encoding:",16)||
!strncmp(buf,"Connection:",11)||
!strncmp(buf,"Proxy-Connection:",17)){
continue;
}
else{
memcpy(add_info+off,buf,n);
memset(buf,0,MAXLINE);
off+=n;
}
}
sprintf(hdr_server,"GET %s HTTP/1.0\r\n",pathname);
sprintf(hdr_server,"%sHost: %s\r\n",hdr_server,hostname);
strcat(hdr_server,user_agent_hdr);
strcat(hdr_server,accept_hdr);
strcat(hdr_server,accept_encoding_hdr);
strcat(hdr_server,conn);
strcat(hdr_server,proxy_conn);
strcat(hdr_server,"\r\n");
strcat(hdr_server,add_info);
}
开发者ID:MujingZhou,项目名称:Apr.2015_Caching-Web-Proxy,代码行数:49,代码来源:proxy.c
示例9: 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((connfd > 0) && (FD_ISSET(connfd, &p->ready_set))){
p->nready --;
if((n = rio_readlineb(&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);
}
else {
close(connfd);
FD_CLR(connfd, &p->read_set);
p->clientfd[i] = -1;
}
}
}
}
开发者ID:jollywing,项目名称:jolly-code-snippets,代码行数:26,代码来源:select_server.c
示例10: send_request
int send_request(rio_t *rio, char *buf,
struct status_line *status, int serverfd, int clientfd) {
int len;
if (strcmp(status->method, "CONNECT")) {
len = snprintf(buf, MAXLINE, "%s %s %s\r\n" \
"Connection: close\r\n",
status->method,
*status->path ? status->path : "/",
status->version);
if ((len = rio_writen(serverfd, buf, len)) < 0)
return len;
while (len != 2) {
if ((len = rio_readlineb(rio, buf, MAXLINE)) < 0)
return len;
if (memcmp(buf, "Proxy-Connection: ", 18) == 0 ||
memcmp(buf, "Connection: ", 12) == 0)
continue;
if ((len = rio_writen(serverfd, buf, len)) < 0)
return len;
}
if (rio->rio_cnt &&
(len = rio_writen(serverfd,
rio->rio_bufptr, rio->rio_cnt)) < 0)
return len;
return 20;
} else {
len = snprintf(buf, MAXLINE,
"%s 200 OK\r\n\r\n", status->version);
if ((len = rio_writen(clientfd, buf, len)) < 0)
return len;
return 300;
}
}
开发者ID:HELLOWORLDxN,项目名称:CSAPP-3,代码行数:33,代码来源:proxy.c
示例11: Rio_readlineb
ssize_t Rio_readlineb(rio_t *rp, void *usrbuf, size_t maxlen) {
ssize_t rc;
if ((rc = rio_readlineb(rp, usrbuf, maxlen)) < 0)
unix_error("Rio_readlineb error");
return rc;
}
开发者ID:ZxMYS,项目名称:Xiaos-IPv4-IPv6-Transmit-Toolkit,代码行数:7,代码来源:csapp.c
示例12: parse_requestline
/******************************************************************************
* subroutine: parse_requestline *
* purpose: parse the content of request line *
* parameters: id - the index of the client in the pool *
* p - a pointer of the pool data structure *
* context - a pointer refers to HTTP context *
* is_closed - an indicator if the current transaction is closed *
* return: 0 on success -1 on error *
******************************************************************************/
int parse_requestline(int id, pool *p, HTTPContext *context, int *is_closed)
{
char buf[MAX_LINE];
memset(buf, 0, MAX_LINE);
if (rio_readlineb(&p->clientrio[id], buf, MAX_LINE) < 0)
{
*is_closed = 1;
Log("Error: rio_readlineb error in process_request \n");
serve_error(p->clientfd[id], "500", "Internal Server Error",
"The server encountered an unexpected condition.", *is_closed);
return -1;
}
if (sscanf(buf, "%s %s %s", context->method, context->uri, context->version) < 3)
{
*is_closed = 1;
Log("Info: Invalid request line: '%s' \n", buf);
serve_error(p->clientfd[id], "400", "Bad Request",
"The request is not understood by the server", *is_closed);
return -1;
}
Log("Request: method=%s, uri=%s, version=%s \n",
context->method, context->uri, context->version);
return 0;
}
开发者ID:ledinhminh,项目名称:Lisod,代码行数:37,代码来源:lisod.c
示例13: doit
void doit(int fd)
{
int clientfd, port, size = 0;
ssize_t linecounter;
rio_t client_rio, server_rio;
char buf[MAXLINE], method[MAXLINE], uri[MAXLINE], version[MAXLINE], serveraddr[MAXLINE], path[MAXLINE], message[MAXLINE];
//read the HTTP request
rio_readinitb(&client_rio, fd);
rio_readlineb(&client_rio, buf, MAXLINE);
sscanf(buf, "%s %s %s", method, uri, version);
if(strcasecmp(method, "GET") != 0)
{
clienterror(fd, method, "501", "Not Implemented", "Proxy does not implement this method");
return;
}
read_requesthdrs(&client_rio);
//parse it to determine the name of the end server
port = parse_uri(uri, serveraddr, path);
//filter
if(is_blocked_address(serveraddr))
{
clienterror(fd, serveraddr, "403", "Forbidden", "Proxy does not access this server");
return;
}
//open a connection to the end server
if((clientfd = open_clientfd(serveraddr, port)) < 0)
{
clienterror(fd, serveraddr, "404", "Not Found", "Proxy does not found this server");
return;
}
//send it the request
sprintf(message, "GET %s HTTP/1.0\r\n", path);
rio_writen(clientfd, message, strlen(message));
sprintf(message, "HOST: %s\r\n\r\n", serveraddr);
rio_writen(clientfd, message, strlen(message));
//receive the reply, and forward the reply to the browser if the request is not blocked.
rio_readinitb(&server_rio, clientfd);
while((linecounter = rio_readlineb(&server_rio, message, MAXLINE)) != 0)
{
rio_writen(fd, message, linecounter);
size += linecounter;
}
//log
sem_wait(&mutex);
log_report(serveraddr, size);
sem_post(&mutex);
}
开发者ID:Viredery,项目名称:web_proxy,代码行数:47,代码来源:proxy.c
示例14: Rio_readlineb
ssize_t Rio_readlineb(rio_t *rp, void *usrbuf, size_t maxlen)
{
ssize_t rt;
rt = rio_readlineb(rp, usrbuf, maxlen);
if (rt == -1)
unix_error("Rio_readlineb error");
return rt;
}
开发者ID:jack-lijing,项目名称:unix,代码行数:8,代码来源:csapp.c
示例15: Rio_readlineb_s
ssize_t Rio_readlineb_s(rio_t *rp, void *usrbuf, size_t maxlen){
ssize_t rc;
if ((rc = rio_readlineb(rp, usrbuf, maxlen)) < 0){
printf("Rio_readlineb error\n");
rc = 0;
}
return rc;
}
开发者ID:amaliujia,项目名称:Computer-System,代码行数:8,代码来源:wrapper.c
示例16: read_request_headers
/** @brief Reads all the request headers until CRLF.
* @param rio The Robust IO buffer.
* @return none.
*/
int read_request_headers(rio_t *rio)
{
char temp_buf[MAXLINE];
int rc;
if ((rc = rio_readlineb(rio, temp_buf, MAXLINE)) < 0) {
dbg_printf("rio_readlineb error\n");
return rc;
}
/* Keep reading header lines until CRLF */
while(strcmp(temp_buf, "\r\n") != 0) {
if ((rc = rio_readlineb(rio, temp_buf, MAXLINE)) < 0 ) {
dbg_printf("rio_readlineb error\n");
return rc;
}
}
return SUCCESS;
}
开发者ID:iscmu2012,项目名称:WebServerEval,代码行数:22,代码来源:basic.c
示例17: parse_requestheaders
/******************************************************************************
* subroutine: parse_requestheaders *
* purpose: parse the content of request headers *
* parameters: id - the index of the client in the pool *
* p - a pointer of the pool data structure *
* context - a pointer refers to HTTP context *
* is_closed - an indicator if the current transaction is closed *
* return: 0 on success -1 on error *
******************************************************************************/
int parse_requestheaders(int id, pool *p, HTTPContext *context, int *is_closed)
{
int ret, cnt = 0, has_contentlen = 0, port;
char buf[MAX_LINE], header[MIN_LINE], data[MIN_LINE], pbuf[MIN_LINE];
context->content_len = -1;
do
{
if ((ret = rio_readlineb(&p->clientrio[id], buf, MAX_LINE)) < 0)
break;
cnt += ret;
// if request header is larger than 8196, reject request
if (cnt > MAX_LINE)
{
*is_closed = 1;
serve_error(p->clientfd[id], "400", "Bad Request",
"Request header too long.", *is_closed);
return -1;
}
// parse Host header
if (strstr(buf, "Host:"))
{
if (sscanf(buf, "%s: %s:%s", header, data, pbuf) > 0) {
port = (int)strtol(pbuf, (char**)NULL, 10);
if (port == STATE.s_port)
{
context->is_secure = 1;
Log("Secure connection \n");
}
}
}
if (strstr(buf, "Connection: close")) *is_closed = 1;
if (strstr(buf, "Content-Length"))
{
has_contentlen = 1;
if (sscanf(buf, "%s %s", header, data) > 0)
context->content_len = (int)strtol(data, (char**)NULL, 10);
Log("Debug: content-length=%d \n", context->content_len);
}
} while(strcmp(buf, "\r\n"));
if ((!has_contentlen) && (!strcasecmp(context->method, "POST")))
{
serve_error(p->clientfd[id], "411", "Length Required",
"Content-Length is required.", *is_closed);
return -1;
}
return 0;
}
开发者ID:ledinhminh,项目名称:Lisod,代码行数:66,代码来源:lisod.c
示例18: Rio_readlineb
ssize_t Rio_readlineb(rio_t *rp, void *usrbuf, size_t maxlen)
{
ssize_t rc;
if ((rc = rio_readlineb(rp, usrbuf, maxlen)) < 0) {
if (errno != ECONNRESET)
unix_error("Rio_readlineb error");
}
return rc;
}
开发者ID:abapst,项目名称:15213-labs,代码行数:10,代码来源:csapp.c
示例19: echo
void echo(int connfd){
size_t n;
char buf[MAXLINE];
rio_t rio;
rio_readinitb(&rio,connfd);
while((n=rio_readlineb(&rio,buf,MAXLINE))!=0){
printf("server received %d bytes\n",n);
rio_writen(connfd,buf,n);
}
}
开发者ID:njutony1991,项目名称:CSAPPLabs-Examples,代码行数:10,代码来源:echoserver.c
示例20: read_msg
void read_msg(int fd, char *recvbuf)
{
rio_t rp;
int ret = 0;
rio_readinitb(&rp,fd);
int length = 1;
length = rio_readlineb(&rp,recvbuf,MAX_MSG_LEN);
if(length<=0) printf("end!!!");
return;
}
开发者ID:VikingMew,项目名称:network-lab,代码行数:11,代码来源:irc.c
注:本文中的rio_readlineb函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论