void hammer_sched_add_connection(hammer_connection_t *c, hammer_sched_t *sched, hammer_connection_t *rc) { int ret; ret = hammer_epoll_add(sched->epoll_fd, remote_fd, HAMMER_EPOLL_READ, HAMMER_EPOLL_LEVEL_TRIGGERED, (void *)c); if (hammer_likely(ret == 0)) { if (r_conn != NULL) { /* r_conn != NULL, this connection is added by connect(), to server */ c->r_conn = rc; rc->r_conn = c; sched->connected_connections ++; } else { /* r_conn == NULL, this connection is added by accept(), from client */ sched->accepted_connections ++; } } else { /* fails, close the connection */ hammer_close_connection(c); hammer_err("epoll add fails\n"); exit(0); } return; }
// we delete both the two connections int hammer_sched_del_connection(hammer_connection_t *c) { hammer_sched_t *sched = hammer_sched_get_sched_struct(); /* remove this connection */ hammer_epoll_del(sched->epoll_fd, c->socket); hammer_close_connection(c); sched->closed_connections ++; /* remove its corresponding connection */ if (c->rc != NULL) { hammer_epoll_del(sched->epoll_fd, c->rc->socket); hammer_close_connection(c->rc); sched->closed_connections ++; } return 0; }
void hammer_sched_add_connection(hammer_connection_t *c, hammer_sched_t *sched) { int ret; ret = hammer_epoll_add(sched->epoll_fd, c->socket, HAMMER_EPOLL_READ, HAMMER_EPOLL_LEVEL_TRIGGERED, (void *)c); if (hammer_likely(ret == 0)) { if (c->type == HAMMER_CONN_CLIENT) { sched->client_connections ++; } else { /* HAMMER_CONN_SERVER */ sched->server_connections ++; } } else { /* fails, close the connection */ hammer_close_connection(c); hammer_err("epoll add fails\n"); exit(0); } return; }