Example #1
0
void *thread(void *vargp)
{
	Pthread_detach(Pthread_self());
	while (1)
	{
		int connfd = sbuf_remove(&sbuf);
		echo_cnt(connfd);
		Close(connfd);
	}
}
Example #2
0
void *thread(void *vargp){
    int connfd=*((int *)vargp);
    Pthread_detach(Pthread_self());
    Free(vargp);
    
    doit(connfd);
    
    display_cache(cache_head);
    
    printf("return doit\n");
    Close(connfd);

    return NULL;
}
Example #3
0
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;
}
Example #4
0
void *proxy_thread(void *vargp) {
	int fd = *(int *)vargp;
	struct stat sbuf;
	char buf[MAXLINE], method[MAXLINE], uri[MAXLINE], version[MAXLINE];
	rio_t rio;

	Pthread_detach(Pthread_self());

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

	if (strcasecmp(method, "GET")) {
		clienterror(fd, method, "501", "Not Implemented",
			"Proxy does not support this method");
		return;
	}

	read_requesthdrs(&rio);
}