int mk_http_request_end(int socket) { int ka; struct client_session *cs; struct sched_list_node *sched; sched = mk_sched_get_thread_conf(); cs = mk_session_get(socket); if (!cs) { MK_TRACE("[FD %i] Not found", socket); return -1; } if (mk_unlikely(!sched)) { MK_TRACE("Could not find sched list node :/"); return -1; } /* * We need to ask to http_keepalive if this * connection can continue working or we must * close it. */ ka = mk_http_keepalive_check(cs); mk_request_free_list(cs); if (ka < 0) { MK_TRACE("[FD %i] No KeepAlive mode, remove", socket); mk_session_remove(socket); } else { mk_request_ka_next(cs); mk_epoll_change_mode(sched->epoll_fd, socket, MK_EPOLL_READ, MK_EPOLL_LEVEL_TRIGGERED); return 0; } return -1; }
int mk_conn_write(int socket) { int ret = -1; struct client_session *cs; struct sched_list_node *sched; struct sched_connection *conx; MK_TRACE("[FD %i] Connection Handler / write", socket); /* Plugin hook */ ret = mk_plugin_event_write(socket); switch(ret) { case MK_PLUGIN_RET_EVENT_OWNED: return MK_PLUGIN_RET_CONTINUE; case MK_PLUGIN_RET_EVENT_CLOSE: return -1; case MK_PLUGIN_RET_EVENT_CONTINUE: break; /* just return controller to invoker */ } MK_TRACE("[FD %i] Normal connection write handling", socket); sched = mk_sched_get_thread_conf(); conx = mk_sched_get_connection(sched, socket); if (!conx) { MK_TRACE("[FD %i] Registering new connection"); if (mk_sched_register_client(socket, sched) == -1) { MK_TRACE("[FD %i] Close requested", socket); return -1; } mk_epoll_change_mode(sched->epoll_fd, socket, MK_EPOLL_READ, MK_EPOLL_LEVEL_TRIGGERED); return 0; } mk_sched_update_conn_status(sched, socket, MK_SCHEDULER_CONN_PROCESS); /* Get node from schedule list node which contains * the information regarding to the current client/socket */ cs = mk_session_get(socket); if (!cs) { /* This is a ghost connection that doesn't exist anymore. * Closing it could accidentally close some other thread's * socket, so pass it to remove_client that checks it's ours. */ mk_sched_remove_client(sched, socket); return 0; } ret = mk_handler_write(socket, cs); /* if ret < 0, means that some error * happened in the writer call, in the * other hand, 0 means a successful request * processed, if ret > 0 means that some data * still need to be send. */ if (ret < 0) { mk_request_free_list(cs); mk_session_remove(socket); return -1; } else if (ret == 0) { return mk_http_request_end(socket); } else if (ret > 0) { return 0; } /* avoid to make gcc cry :_( */ return -1; }