void cgi_http_connection_write(cgi_http_connection_t *connection) { int tmpfd = connection->sockfd; int linger = connection->linger; cgi_event_dispatcher_t *dispatcher = connection->dispatcher; int state = 1; /* set TCP cork */ setsockopt(tmpfd, IPPROTO_TCP, TCP_CORK, &state, sizeof(state)); write(connection->sockfd, connection->wbuffer, connection->write_idx); if (connection->ffd != -1 && connection->fsize != -1) { if (sendfile(connection->sockfd, connection->ffd, NULL, connection->fsize) == -1) perror("sendfile"); /* uncork */ state = 0; setsockopt(tmpfd, IPPROTO_TCP, TCP_CORK, &state, sizeof(state)); close(connection->ffd); } cgi_http_connection_init(connection); if(linger == 1) { Dispatcher.modfd(dispatcher, tmpfd, EPOLLIN); clock_gettime(CLOCK_REALTIME, &connection->idle_start); } else { close(connection->sockfd); connection->dispatcher->isconn[tmpfd] = 0; } }
cgi_http_connection_t *cgi_http_connection_create() { cgi_http_connection_t *connection = (cgi_http_connection_t *) cgi_factory_create(HTTP_CONNECTION); cgi_http_connection_init(connection); return connection; }
void cgi_http_connection_init5(cgi_http_connection_t *connection, cgi_event_dispatcher_t *dispatcher,int sockfd, struct sockaddr *clientaddr,socklen_t clientlen) { cgi_http_connection_init(connection); connection->dispatcher = dispatcher; connection->sockfd = sockfd; connection->clientlen = clientlen; memcpy(&connection->clientaddr,clientaddr,clientlen); }
void cgi_http_connection_write(cgi_http_connection_t *connection, cgi_event_dispatcher_t *dispatcher) { write(connection->sockfd, connection->wbuffer, connection->write_idx); if (connection->ffd != -1 && connection->fsize != -1) { if (sendfile(connection->sockfd, connection->ffd, NULL, connection->fsize) == -1) perror("sendfile"); close(connection->ffd); cgi_http_connection_init(connection); } close(connection->sockfd); }