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


C++ rio_readinitb函数代码示例

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


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

示例1: load_mnist_dataset_blas

void load_mnist_dataset_blas(dataset_blas *train_set, dataset_blas *validate_set){
    uint32_t N, nrow, ncol, magic_n;
    rio_t rio_train_x, rio_train_y;
    int train_x_fd, train_y_fd;
    int train_set_size = 50000, validate_set_size = 10000;
    int i, nlabel = 10;

    train_x_fd = open("../data/train-images-idx3-ubyte", O_RDONLY);
    train_y_fd = open("../data/train-labels-idx1-ubyte", O_RDONLY);

    if(train_x_fd == -1){
        fprintf(stderr, "cannot open train-images-idx3-ubyte\n");
        exit(1);
    }
    if(train_y_fd == -1){
        fprintf(stderr, "cannot open train-labels-idx1-ubyte\n");
        exit(1);
    }

    rio_readinitb(&rio_train_x, train_x_fd, 0);
    rio_readinitb(&rio_train_y, train_y_fd, 0);

    read_uint32(&rio_train_x, &magic_n);
    read_uint32(&rio_train_x, &N);
    read_uint32(&rio_train_x, &nrow);
    read_uint32(&rio_train_x, &ncol);
    
    read_uint32(&rio_train_y, &magic_n);
    read_uint32(&rio_train_y, &N);
#ifdef DEBUG
    printf("magic number: %u\nN: %u\nnrow: %u\nncol: %u\n", magic_n, N, nrow, ncol);
    fflush(stdout);
#endif

    init_dataset_blas(train_set, train_set_size, nrow, ncol, nlabel);
    init_dataset_blas(validate_set, validate_set_size, nrow, ncol, nlabel);

    load_dataset_blas_input(&rio_train_x, train_set);
    load_dataset_blas_output(&rio_train_y, train_set);
    for(i = 0; i < train_set->N; i++){
        train_set->label[i*nlabel + train_set->output[i]] = 1;
    }

    load_dataset_blas_input(&rio_train_x, validate_set);
    load_dataset_blas_output(&rio_train_y, validate_set);

    //print_dataset(&validate_set);

    close(train_x_fd);
    close(train_y_fd);
}
开发者ID:roles,项目名称:deep_learning,代码行数:51,代码来源:dataset.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: doit

/* 
 * sends the request then it gets data from the outside server then sends to outside client
 */
void* doit(void * data){
  struct treadInfo *thread=(struct doitInfo *)data;
  int   portValue=0;
  int  *port=&portValue;

  //ignore SIGPIPE singal
  signal(SIGPIPE, SIG_IGN);

  //builds the request from client
  struct requestInfo getRequest=request(thread,port);
  
  //connecting to server  if fails closes //need to change to own function
  (*thread).serverfd=serverConnection((char *)getRequest.hostname,*getRequest.port,thread);
  
  //prints out the request will add to request function
  printf("Thread %d: Forwarding request to end server:\n",(*thread).ID);
  printf("%s",(char *)getRequest.request);
  printf("*** End of Request ***\n\n");
  
  //set Rio
  rio_readinitb(&(*thread).rioWithServer,(*thread).serverfd);

  //send request
  rio_writen_w((*thread).serverfd,getRequest.request,strlen((const char *)getRequest.request),thread);

  //transfer recieved data from server to client
  transferData(thread);
  
  //should never reach this exit()
  exit(0);
}
开发者ID:fx2323,项目名称:Graduate-Classes,代码行数:34,代码来源:old3proxy.c

示例4: add_client

void add_client(int connfd, Pool *p)
{
    int i;
    p->nready--;
    for(i = 0; i < FD_SETSIZE; i++){
        if(p->clientfd[i] < 0){
            /* add connected descriptor to the pool */
            p->clientfd[i] = connfd;
            rio_readinitb(&p->clientrio[i], connfd);
            /* add the descriptor to descriptor set */
            FD_SET(connfd, &p->read_set);

            if(connfd > p->maxfd)
                p->maxfd = connfd;
            if(i > p->maxi)
                p->maxi = i;
            break;
        }
    }

    if(i == FD_SETSIZE){
        fprintf(stderr, "add_client error: too many clients!\n");
        exit(1);
    }
}
开发者ID:jollywing,项目名称:jolly-code-snippets,代码行数:25,代码来源:select_server.c

示例5: forward_request

int forward_request(int client_fd, Request *request, Response *response) {
    rio_t   server_rio;
    int server_fd;
    char hostname[MAXLINE];
    int  port = 80;

    port = extract_port_number(request->request_str);
    extract_hostname(request->host_str, hostname);

    #ifdef DEBUG
    printf("hostname:%s\n", hostname);
    printf("port:%d\n", port);
    #endif

    if ((server_fd = open_clientfd(hostname, port)) < 0) {
       fprintf(stderr, "Warning connection refused !\n"); 
       return -1;
    }

    rio_readinitb(&server_rio, server_fd);
    #ifdef DEBUG
    printf("request_str:%s", request->request_str); 
    #endif
    
    rio_writen(server_fd, request->request_str, strlen(request->request_str));
    rio_writen(server_fd, request->host_str, strlen(request->host_str));
    rio_writen(server_fd, "\r\n", strlen("\r\n"));
    
    forward_response(client_fd, server_fd, response);
    Close(server_fd);
    return 1;
}
开发者ID:fxiang,项目名称:proxylab,代码行数:32,代码来源:proxy.c

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

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

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

示例9: miss_handler

/* miss_handler handles miss case. It passes client's request
 * to server and passes server's response to client. If the 
 * response satisfies size requirements, store the response 
 * into cache. */
void miss_handler(int clientfd, struct client_request *request)
{
	int serverfd, length, response_size;
	char buf[MAXBUF], object_buf[MAX_OBJECT_SIZE];
	struct cache_cell *cell;
	rio_t rio_server;
	
	response_size = length = 0;
	
	/* acts as a client and writes request to server */
	Pthread_mutex_lock(&open_mutex);
	serverfd = open_serverfd_h(request, clientfd);
	Pthread_mutex_unlock(&open_mutex);
	rio_readinitb(&rio_server, serverfd);
	
	if (rio_writen(serverfd, request->request, request->request_length) 
					!= request->request_length)
	{
		write(2, "write error\n", strlen("write error\n"));
		close_connection(request, clientfd, serverfd);
	}
	
	/* passes server's response to client */
	while (1)
	{
		if ((length = rio_readnb(&rio_server, buf, MAXBUF)) < 0)
			close_connection(request, clientfd, serverfd);
		if (response_size + length <= MAX_OBJECT_SIZE)
			memcpy(object_buf + response_size, buf, length);
		response_size += length;
		if (rio_writen(clientfd, buf, length) < length)
			break;
		if (length != MAXBUF)
			break;
	}
	
	/* if response satisfies size requirement, store the response 
	 * into cache */
	if (response_size <= MAX_OBJECT_SIZE)
	{
		/* need a mutex to prevent inserting the same cell twice 
		 * into cache in race condition */
		Pthread_mutex_lock(&dup_mutex);
		if (search_cell_variant(request->request_line) == 0)
		{
			cell = allocate_cell();
			set_cell(cell, request->request_line, object_buf, response_size);
			add_to_list(cell);
		}
		Pthread_mutex_unlock(&dup_mutex);
	}
	close_connection(request, clientfd, serverfd);
}
开发者ID:samzcmu,项目名称:proxy,代码行数:57,代码来源:proxy.c

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

示例11: main

int main()
{
	int n;
	rio_t rio;
	char buf[MAXLINE];

	rio_readinitb(&rio, STDIN_FILENO);

	whle((n= rio_readn(&rio, buf, MAXBUF)) != 0)
		Rio_writen(STDOUT_FILENO, buf, MAXBUF);

	return 0;
}
开发者ID:dreamsxin,项目名称:CSAPP,代码行数:13,代码来源:10_7.c

示例12: main

int main(int argc, char ** argv)
{
	int n;
	rio_t rio;
	char buf[MAXBUF];
	printf("%d\n",MAXBUF);

	rio_readinitb(&rio, STDIN_FILENO);
	while((n = rio_readnb(&rio, buf, MAXBUF)) != 0)
	{
		rio_writen(STDOUT_FILENO, buf, n);
	}
	return 0;
}
开发者ID:0x0nil,项目名称:csapp,代码行数:14,代码来源:11.7.c

示例13: echo

void echo(int fd)
{
    size_t n;
    char buf[MAXLINE];
    rio_t rio;
    
    rio_readinitb(&rio, fd);
    while((n = rio_readlineb(&rio, buf, MAXLINE)) != 0) {
        printf("server received %d bytes\n", n);
        memset(buf, 0, MAXLINE);
        snprintf(buf, sizeof(buf), "server roger that\n");
        rio_writen(fd, buf, strlen(buf));
    }
    
}
开发者ID:rainzq,项目名称:self-training,代码行数:15,代码来源:select-serv.c

示例14: Pthread_detach

void *proxy(void *vargp) {
	Pthread_detach(Pthread_self());

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

	rio_t rio;
	rio_readinitb(&rio, clientfd);

	struct status_line status;

	char buf[MAXLINE];
	int flag;

#ifdef PROXY_CACHE
	char objectbuf[MAX_OBJECT_SIZE];
#endif

	if ((flag = rio_readlineb(&rio, buf, MAXLINE)) > 0) {
		if (parseline(buf, &status) < 0)
			fprintf(stderr, "parseline error: '%s'\n", buf);
#ifdef PROXY_CACHE
		else if (cacheable(&status) &&
				(flag = cache_find(status.line, objectbuf))) {
			if (rio_writen(clientfd, objectbuf, flag) < 0)
				log(cache_write);
		}
#endif
		else if ((serverfd =
					open_clientfd(status.hostname, status.port)) < 0)
			log(open_clientfd);
		else {
			if ((flag = send_request(&rio, buf,
							&status, serverfd, clientfd)) < 0)
				log(send_request);
			else if (interrelate(serverfd, clientfd, buf, flag
#ifdef PROXY_CACHE
						,objectbuf, &status
#endif
						) < 0)
				log(interrelate);
			close(serverfd);
		}
	}
	close(clientfd);
	return NULL;
}
开发者ID:HELLOWORLDxN,项目名称:CSAPP-3,代码行数:48,代码来源:proxy.c

示例15: forward_request

/* 
 * forward_request - send request from client to its destination server 
 */
int forward_request(int client_fd, Request *request, Response *response) {
    rio_t   server_rio;
    int server_fd;
    char hostname[MAXLINE];
    int  port = 80;

    extract_hostname_port(request->host_str, hostname, &port);

    #ifdef DEBUG
    printf("extract hostname:%s\n", hostname);
    printf("extract port:%d\n", port);
    #endif
    if ((server_fd = open_clientfd(hostname, port)) < 0) {
        sleep(2);
        if ((server_fd = open_clientfd(hostname, port)) < 0) {
            sleep(2);
            if ((server_fd = open_clientfd(hostname, port)) < 0) {
                proxy_error(strcat(hostname, " connection refuesed"));
                close(server_fd);
                return -1;
            }
        }
    }

    rio_readinitb(&server_rio, server_fd);
    #ifdef DEBUG
    printf("request_str:%s", request->request_str); 
    #endif
    
    rio_writen(server_fd, request->request_str, strlen(request->request_str));
    rio_writen(server_fd, request->host_str, strlen(request->host_str));
    /* send cookie to server */
    if (request->cookie_size != 0) {
        rio_writen(server_fd, request->cookie, request->cookie_size);
    }
    /* send user-agent info to server */
    if (request->user_agent_size != 0) {
        rio_writen(server_fd, request->user_agent, request->user_agent_size);
    }
    rio_writen(server_fd, "\r\n", strlen("\r\n"));
    
    if (forward_response(client_fd, server_fd, response) < 0) {
        close(server_fd);
        return -1;
    }
    close(server_fd);
    return 1;
}
开发者ID:yuguess,项目名称:ProxyLabNew,代码行数:51,代码来源:proxy.c


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