Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Gets rid of more ancient code from the pre-new-events age. Basically,

we do not need to keep track of connections's I/O mode any longer.
  • Loading branch information...
commit 5be74194fa0cc783c1cec6f6a499902793b575b5 1 parent 772f779
@alobbs alobbs authored
View
2  cherokee/connection.c
@@ -1547,7 +1547,7 @@ cherokee_connection_linger_read (cherokee_connection_t *conn)
cherokee_thread_t *thread = CONN_THREAD(conn);
cherokee_buffer_t *tmp1 = THREAD_TMP_BUF1(thread);
- TRACE(ENTRIES",linger", "Linger read, socket status %d\n", conn->socket.status);
+ TRACE(ENTRIES",linger", "Linger read, socket %s closed\n", conn->socket.closed ? "is" : "isn't");
while (true) {
/* Read from the socket to nowhere
View
2  cherokee/handler_uwsgi.c
@@ -175,8 +175,6 @@ read_from_uwsgi (cherokee_handler_cgi_base_t *cgi_base,
case ret_eagain:
conn->polling_aim.fd = uwsgi->socket.socket;
conn->polling_aim.mode = poll_mode_read;
-
- cherokee_thread_deactive_to_polling (HANDLER_THREAD(cgi_base), conn);
return ret_eagain;
case ret_ok:
View
34 cherokee/socket.c
@@ -114,7 +114,7 @@ cherokee_socket_init (cherokee_socket_t *socket)
socket->client_addr_len = -1;
socket->socket = -1;
- socket->status = socket_closed;
+ socket->closed = true;
socket->is_tls = non_TLS;
socket->cryptor = NULL;
@@ -149,7 +149,7 @@ cherokee_socket_clean (cherokee_socket_t *socket)
/* Properties
*/
socket->socket = -1;
- socket->status = socket_closed;
+ socket->closed = true;
/* Client address
*/
@@ -210,7 +210,7 @@ cherokee_socket_close (cherokee_socket_t *socket)
socket->socket, socket->is_tls, (int) ret);
socket->socket = -1;
- socket->status = socket_closed;
+ socket->closed = true;
socket->is_tls = non_TLS;
return ret;
@@ -358,9 +358,9 @@ cherokee_socket_set_sockaddr (cherokee_socket_t *socket, int fd, cherokee_sockad
/* Status is no more closed.
*/
- socket->status = socket_reading;
-
+ socket->closed = false;
SOCKET_FD(socket) = fd;
+
return ret_ok;
}
@@ -698,7 +698,7 @@ cherokee_socket_write (cherokee_socket_t *socket,
#ifdef ENOTCONN
case ENOTCONN:
#endif
- socket->status = socket_closed;
+ socket->closed = true;
case ETIMEDOUT:
case EHOSTUNREACH:
return ret_error;
@@ -718,7 +718,7 @@ cherokee_socket_write (cherokee_socket_t *socket,
case ret_eagain:
return ret;
case ret_eof:
- socket->status = socket_closed;
+ socket->closed = true;
return ret_eof;
default:
RET_UNKNOWN(ret);
@@ -750,7 +750,7 @@ cherokee_socket_read (cherokee_socket_t *socket,
*/
return_if_fail (buf != NULL && buf_size > 0, ret_error);
- if (unlikely (socket->status == socket_closed)) {
+ if (unlikely (socket->closed)) {
TRACE(ENTRIES, "Reading a closed socket: fd=%d (TLS=%d)\n", SOCKET_FD(socket), (socket->is_tls == TLS));
return ret_eof;
}
@@ -768,7 +768,7 @@ cherokee_socket_read (cherokee_socket_t *socket,
}
if (len == 0) {
- socket->status = socket_closed;
+ socket->closed = true;
return ret_eof;
}
@@ -791,7 +791,7 @@ cherokee_socket_read (cherokee_socket_t *socket,
case ENOTCONN:
#endif
case ECONNRESET:
- socket->status = socket_closed;
+ socket->closed = true;
case ETIMEDOUT:
case EHOSTUNREACH:
return ret_error;
@@ -810,7 +810,7 @@ cherokee_socket_read (cherokee_socket_t *socket,
case ret_eagain:
return ret;
case ret_eof:
- socket->status = socket_closed;
+ socket->closed = true;
return ret_eof;
default:
RET_UNKNOWN(ret);
@@ -980,7 +980,7 @@ cherokee_socket_writev (cherokee_socket_t *socket,
case ENOTCONN:
#endif
case ECONNRESET:
- socket->status = socket_closed;
+ socket->closed = true;
case ETIMEDOUT:
case EHOSTUNREACH:
return ret_error;
@@ -1453,7 +1453,7 @@ cherokee_socket_connect (cherokee_socket_t *sock)
TRACE (ENTRIES",connect", "succeed. fd=%d\n", SOCKET_FD(sock));
- sock->status = socket_reading;
+ sock->closed = false;
return ret_ok;
}
@@ -1479,14 +1479,6 @@ cherokee_socket_init_client_tls (cherokee_socket_t *socket,
ret_t
-cherokee_socket_set_status (cherokee_socket_t *socket, cherokee_socket_status_t status)
-{
- socket->status = status;
- return ret_ok;
-}
-
-
-ret_t
cherokee_socket_set_cork (cherokee_socket_t *socket, cherokee_boolean_t enable)
{
int re;
View
10 cherokee/socket.h
@@ -37,6 +37,8 @@
/* Socket status
*/
+
+// TODO: Get rid of this type
typedef enum {
socket_reading = poll_mode_read,
socket_writing = poll_mode_write,
@@ -76,7 +78,7 @@ typedef struct {
int socket;
cherokee_sockaddr_t client_addr;
socklen_t client_addr_len;
- cherokee_socket_status_t status;
+ cherokee_boolean_t closed;
cherokee_socket_type_t is_tls;
cherokee_cryptor_socket_t *cryptor;
} cherokee_socket_t;
@@ -88,7 +90,6 @@ typedef struct {
#define SOCKET(s) ((cherokee_socket_t *)(s))
#define SOCKET_FD(s) (SOCKET(s)->socket)
#define SOCKET_AF(s) (SOCKET(s)->client_addr.sa.sa_family)
-#define SOCKET_STATUS(s) (SOCKET(s)->status)
#define SOCKET_ADDR(s) (SOCKET(s)->client_addr)
#define SOCKET_ADDR_UNIX(s) ((struct sockaddr_un *) &SOCKET_ADDR(s))
@@ -106,9 +107,7 @@ typedef struct {
#define cherokee_socket_configured(c) (SOCKET_FD(c) >= 0)
-#define cherokee_socket_is_connected(c) (cherokee_socket_configured(c) && \
- (SOCKET_STATUS(c) != socket_closed))
-
+#define cherokee_socket_is_connected(c) (cherokee_socket_configured(c) && (!SOCKET(c)->closed))
ret_t cherokee_socket_init (cherokee_socket_t *socket);
ret_t cherokee_socket_mrproper (cherokee_socket_t *socket);
@@ -137,7 +136,6 @@ ret_t cherokee_socket_connect (cherokee_socket_t *socket);
ret_t cherokee_socket_ntop (cherokee_socket_t *socket, char *buf, size_t buf_size);
ret_t cherokee_socket_pton (cherokee_socket_t *socket, cherokee_buffer_t *buf);
ret_t cherokee_socket_gethostbyname (cherokee_socket_t *socket, cherokee_buffer_t *hostname);
-ret_t cherokee_socket_set_status (cherokee_socket_t *socket, cherokee_socket_status_t status);
ret_t cherokee_socket_set_cork (cherokee_socket_t *socket, cherokee_boolean_t enable);
View
49 cherokee/thread.c
@@ -262,28 +262,6 @@ cherokee_thread_new (cherokee_thread_t **thd,
static void
-conn_set_mode (cherokee_thread_t *thd,
- cherokee_connection_t *conn,
- cherokee_socket_status_t s)
-{
- UNUSED(thd);
-
- if (conn->socket.status == s) {
- TRACE (ENTRIES, "Connection already in mode = %s\n",
- (s == socket_reading)? "reading" :
- (s == socket_writing)? "writing" : "???");
- return;
- }
-
- TRACE (ENTRIES, "Connection mode = %s\n",
- (s == socket_reading)? "reading" :
- (s == socket_writing)? "writing" : "???");
-
- cherokee_socket_set_status (&conn->socket, s);
-}
-
-
-static void
add_connection (cherokee_thread_t *thd, cherokee_connection_t *conn)
{
cherokee_list_add_tail (LIST(conn), &thd->active_list);
@@ -428,7 +406,6 @@ maybe_purge_closed_connection (cherokee_thread_t *thread, cherokee_connection_t
/* Clean the connection
*/
cherokee_connection_clean (conn);
- conn_set_mode (thread, conn, socket_reading);
/* Update the timeout value
*/
@@ -606,10 +583,8 @@ process_active_connections (cherokee_thread_t *thd)
list_for_each_safe (i, tmp, &thd->active_list) {
conn = CONN(i);
- TRACE (ENTRIES",active", " \\- processing conn (%p), phase %d '%s', socket=%d,%s\n",
- conn, conn->phase, cherokee_connection_get_phase_str (conn), conn->socket.socket,
- (conn->socket.status == socket_reading)? "read" :
- (conn->socket.status == socket_writing)? "writing" : "closed");
+ TRACE (ENTRIES",active", " \\- processing conn (%p), phase %d '%s', socket=%d\n",
+ conn, conn->phase, cherokee_connection_get_phase_str (conn), conn->socket.socket);
}
}
#endif
@@ -619,10 +594,8 @@ process_active_connections (cherokee_thread_t *thd)
list_for_each_safe (i, tmp, LIST(&thd->active_list)) {
conn = CONN(i);
- TRACE (ENTRIES, "processing conn (%p), phase %d '%s', socket=%d, %s\n",
- conn, conn->phase, cherokee_connection_get_phase_str (conn), conn->socket.socket,
- (conn->socket.status == socket_reading)? "read" :
- (conn->socket.status == socket_writing)? "writing" : "closed");
+ TRACE (ENTRIES, "processing conn (%p), phase %d '%s', socket=%d\n",
+ conn, conn->phase, cherokee_connection_get_phase_str (conn), conn->socket.socket);
/* Thread's properties
*/
@@ -707,11 +680,9 @@ process_active_connections (cherokee_thread_t *thd)
case ret_eagain:
switch (blocking) {
case socket_reading:
- conn_set_mode (thd, conn, socket_reading);
break;
case socket_writing:
- conn_set_mode (thd, conn, socket_writing);
break;
default:
@@ -725,7 +696,6 @@ process_active_connections (cherokee_thread_t *thd)
/* Set mode and update timeout
*/
- conn_set_mode (thd, conn, socket_reading);
cherokee_connection_update_timeout (conn);
conn->phase = phase_reading_header;
@@ -827,7 +797,6 @@ process_active_connections (cherokee_thread_t *thd)
default:
cherokee_connection_setup_error_handler (conn);
- conn_set_mode (thd, conn, socket_writing);
continue;
}
@@ -865,10 +834,6 @@ process_active_connections (cherokee_thread_t *thd)
cherokee_rule_list_t *rules;
cherokee_boolean_t is_userdir;
- /* Turn the connection in write mode
- */
- conn_set_mode (thd, conn, socket_writing);
-
/* HSTS support
*/
if ((conn->socket.is_tls != TLS) &&
@@ -1134,8 +1099,6 @@ process_active_connections (cherokee_thread_t *thd)
if (cherokee_connection_poll_is_set (&conn->polling_aim)) {
cherokee_thread_deactive_to_polling (thd, conn);
}
-
-// conn_set_mode (thd, conn, socket_reading);
continue;
case ret_eof:
case ret_error:
@@ -1148,7 +1111,6 @@ process_active_connections (cherokee_thread_t *thd)
/* Turn the connection in write mode
*/
-// conn_set_mode (thd, conn, socket_writing);
conn->phase = phase_add_headers;
case phase_add_headers:
@@ -1341,7 +1303,6 @@ process_active_connections (cherokee_thread_t *thd)
break;
case ret_eagain:
- conn_set_mode (thd, conn, socket_reading);
cherokee_thread_deactive_to_polling (thd, conn);
continue;
@@ -1365,7 +1326,6 @@ process_active_connections (cherokee_thread_t *thd)
/* Wait for the socket to be readable:
* FIN + ACK will have arrived by then
*/
- conn_set_mode (thd, conn, socket_reading);
conn->phase = phase_lingering;
break;
@@ -1627,7 +1587,6 @@ accept_new_connection (cherokee_thread_t *thd,
/* Lets add the new connection
*/
- conn_set_mode (thd, new_conn, socket_reading);
add_connection (thd, new_conn);
thd->conns_num++;
Please sign in to comment.
Something went wrong with that request. Please try again.