@@ -74,19 +74,24 @@ static bool connection_event_update(int fd, uint32_t events) {
7474 return res == 0 ;
7575}
7676
77- bool connection_register_write (int fd) {
78- return connection_event_update (fd, EPOLLOUT | EPOLLHUP );
77+ bool connection_register_write (struct scache_connection * c) {
78+ c->epollout = true ;
79+ c->epollin = false ;
80+ return connection_event_update (c->client_sock , EPOLLOUT | EPOLLHUP );
7981}
8082
81- bool connection_register_read (int fd) {
82- return connection_event_update (fd, EPOLLIN | EPOLLHUP | EPOLLRDHUP );
83+ bool connection_register_read (struct scache_connection * c) {
84+ c->epollout = false ;
85+ c->epollin = true ;
86+ return connection_event_update (c->client_sock , EPOLLIN | EPOLLHUP | EPOLLRDHUP );
8387}
8488
8589void connection_setup (struct scache_binds cache_binds, struct scache_binds monitor_binds) {
8690 int i;
8791
8892 for (i = 0 ; i < CONNECTION_HASH_ENTRIES ; i++) {
8993 ctable[i].connection .client_sock = -1 ;
94+ ctable[i].connection .epollin = ctable[i].connection .epollout = false ;
9095 }
9196
9297 // Allocate for all listeners
@@ -291,6 +296,7 @@ static scache_connection* connection_add(int fd, listener_type client_type) {
291296
292297 // do last as marks connection slot as used
293298 newNode->connection .client_sock = fd;
299+ newNode->connection .epollout = newNode->connection .epollin = false ;
294300
295301 // this is a chained connection
296302 if (node != newNode){
@@ -634,6 +640,7 @@ void connection_event_loop(void (*connection_handler)(scache_connection* connect
634640 DEBUG (" [#%d] A new %s socket was accepted %d\n " , fd, listener_type_string (client_type), client_sock);
635641 scache_connection* connection = connection_add (client_sock, client_type);
636642 assert (connection->client_sock == client_sock);
643+ connection->epollin = true ;
637644 connection_handler (connection);
638645 }
639646 }
@@ -729,6 +736,8 @@ void connection_cleanup_http(scache_connection_node* connection, bool toFree = f
729736 close_fd (fd);
730737 }
731738
739+ connection->connection .epollout = connection->connection .epollin = false ;
740+
732741 // Handle chained connections
733742 if (connection->next != NULL ) {
734743 connection_cleanup_http (connection->next , true );
0 commit comments