Skip to content
This repository
Browse code

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
Alvaro Lopez Ortega authored January 04, 2012
2  cherokee/connection.c
@@ -1547,7 +1547,7 @@ cherokee_connection_linger_read (cherokee_connection_t *conn)
1547 1547
 	cherokee_thread_t *thread   = CONN_THREAD(conn);
1548 1548
 	cherokee_buffer_t *tmp1     = THREAD_TMP_BUF1(thread);
1549 1549
 
1550  
-	TRACE(ENTRIES",linger", "Linger read, socket status %d\n", conn->socket.status);
  1550
+	TRACE(ENTRIES",linger", "Linger read, socket %s closed\n", conn->socket.closed ? "is" : "isn't");
1551 1551
 
1552 1552
 	while (true) {
1553 1553
 		/* Read from the socket to nowhere
2  cherokee/handler_uwsgi.c
@@ -175,8 +175,6 @@ read_from_uwsgi (cherokee_handler_cgi_base_t *cgi_base,
175 175
 	case ret_eagain:
176 176
 		conn->polling_aim.fd   = uwsgi->socket.socket;
177 177
 		conn->polling_aim.mode = poll_mode_read;
178  
-
179  
-		cherokee_thread_deactive_to_polling (HANDLER_THREAD(cgi_base), conn);
180 178
 		return ret_eagain;
181 179
 
182 180
 	case ret_ok:
34  cherokee/socket.c
@@ -114,7 +114,7 @@ cherokee_socket_init (cherokee_socket_t *socket)
114 114
 	socket->client_addr_len = -1;
115 115
 
116 116
 	socket->socket  = -1;
117  
-	socket->status  = socket_closed;
  117
+	socket->closed  = true;
118 118
 	socket->is_tls  = non_TLS;
119 119
 	socket->cryptor = NULL;
120 120
 
@@ -149,7 +149,7 @@ cherokee_socket_clean (cherokee_socket_t *socket)
149 149
 	/* Properties
150 150
 	 */
151 151
 	socket->socket = -1;
152  
-	socket->status = socket_closed;
  152
+	socket->closed = true;
153 153
 
154 154
 	/* Client address
155 155
 	 */
@@ -210,7 +210,7 @@ cherokee_socket_close (cherokee_socket_t *socket)
210 210
 	       socket->socket, socket->is_tls, (int) ret);
211 211
 
212 212
 	socket->socket = -1;
213  
-	socket->status = socket_closed;
  213
+	socket->closed = true;
214 214
 	socket->is_tls = non_TLS;
215 215
 
216 216
 	return ret;
@@ -358,9 +358,9 @@ cherokee_socket_set_sockaddr (cherokee_socket_t *socket, int fd, cherokee_sockad
358 358
 
359 359
 	/* Status is no more closed.
360 360
 	 */
361  
-	socket->status = socket_reading;
362  
-
  361
+	socket->closed = false;
363 362
 	SOCKET_FD(socket) = fd;
  363
+
364 364
 	return ret_ok;
365 365
 }
366 366
 
@@ -698,7 +698,7 @@ cherokee_socket_write (cherokee_socket_t *socket,
698 698
 #ifdef ENOTCONN
699 699
 		case ENOTCONN:
700 700
 #endif
701  
-			socket->status = socket_closed;
  701
+			socket->closed = true;
702 702
 		case ETIMEDOUT:
703 703
 		case EHOSTUNREACH:
704 704
 			return ret_error;
@@ -718,7 +718,7 @@ cherokee_socket_write (cherokee_socket_t *socket,
718 718
 		case ret_eagain:
719 719
 			return ret;
720 720
 		case ret_eof:
721  
-			socket->status = socket_closed;
  721
+			socket->closed = true;
722 722
 			return ret_eof;
723 723
 		default:
724 724
 			RET_UNKNOWN(ret);
@@ -750,7 +750,7 @@ cherokee_socket_read (cherokee_socket_t *socket,
750 750
 	 */
751 751
 	return_if_fail (buf != NULL && buf_size > 0, ret_error);
752 752
 
753  
-	if (unlikely (socket->status == socket_closed)) {
  753
+	if (unlikely (socket->closed)) {
754 754
 		TRACE(ENTRIES, "Reading a closed socket: fd=%d (TLS=%d)\n", SOCKET_FD(socket), (socket->is_tls == TLS));
755 755
 		return ret_eof;
756 756
 	}
@@ -768,7 +768,7 @@ cherokee_socket_read (cherokee_socket_t *socket,
768 768
 		}
769 769
 
770 770
 		if (len == 0) {
771  
-			socket->status = socket_closed;
  771
+			socket->closed = true;
772 772
 			return ret_eof;
773 773
 		}
774 774
 
@@ -791,7 +791,7 @@ cherokee_socket_read (cherokee_socket_t *socket,
791 791
 		case ENOTCONN:
792 792
 #endif
793 793
 		case ECONNRESET:
794  
-			socket->status = socket_closed;
  794
+			socket->closed = true;
795 795
 		case ETIMEDOUT:
796 796
 		case EHOSTUNREACH:
797 797
 			return ret_error;
@@ -810,7 +810,7 @@ cherokee_socket_read (cherokee_socket_t *socket,
810 810
 		case ret_eagain:
811 811
 			return ret;
812 812
 		case ret_eof:
813  
-			socket->status = socket_closed;
  813
+			socket->closed = true;
814 814
 			return ret_eof;
815 815
 		default:
816 816
 			RET_UNKNOWN(ret);
@@ -980,7 +980,7 @@ cherokee_socket_writev (cherokee_socket_t  *socket,
980 980
 			case ENOTCONN:
981 981
 #endif
982 982
 			case ECONNRESET:
983  
-				socket->status = socket_closed;
  983
+				socket->closed = true;
984 984
 			case ETIMEDOUT:
985 985
 			case EHOSTUNREACH:
986 986
 				return ret_error;
@@ -1453,7 +1453,7 @@ cherokee_socket_connect (cherokee_socket_t *sock)
1453 1453
 
1454 1454
 	TRACE (ENTRIES",connect", "succeed. fd=%d\n", SOCKET_FD(sock));
1455 1455
 
1456  
-	sock->status = socket_reading;
  1456
+	sock->closed = false;
1457 1457
 	return ret_ok;
1458 1458
 }
1459 1459
 
@@ -1479,14 +1479,6 @@ cherokee_socket_init_client_tls (cherokee_socket_t *socket,
1479 1479
 
1480 1480
 
1481 1481
 ret_t
1482  
-cherokee_socket_set_status (cherokee_socket_t *socket, cherokee_socket_status_t status)
1483  
-{
1484  
-	socket->status = status;
1485  
-	return ret_ok;
1486  
-}
1487  
-
1488  
-
1489  
-ret_t
1490 1482
 cherokee_socket_set_cork (cherokee_socket_t *socket, cherokee_boolean_t enable)
1491 1483
 {
1492 1484
 	int re;
10  cherokee/socket.h
@@ -37,6 +37,8 @@
37 37
 
38 38
 /* Socket status
39 39
  */
  40
+
  41
+// TODO: Get rid of this type
40 42
 typedef enum {
41 43
 	socket_reading = poll_mode_read,
42 44
 	socket_writing = poll_mode_write,
@@ -76,7 +78,7 @@ typedef struct {
76 78
 	int                        socket;
77 79
 	cherokee_sockaddr_t        client_addr;
78 80
 	socklen_t                  client_addr_len;
79  
-	cherokee_socket_status_t   status;
  81
+	cherokee_boolean_t         closed;
80 82
 	cherokee_socket_type_t     is_tls;
81 83
 	cherokee_cryptor_socket_t *cryptor;
82 84
 } cherokee_socket_t;
@@ -88,7 +90,6 @@ typedef struct {
88 90
 #define SOCKET(s)              ((cherokee_socket_t *)(s))
89 91
 #define SOCKET_FD(s)           (SOCKET(s)->socket)
90 92
 #define SOCKET_AF(s)           (SOCKET(s)->client_addr.sa.sa_family)
91  
-#define SOCKET_STATUS(s)       (SOCKET(s)->status)
92 93
 
93 94
 #define SOCKET_ADDR(s)         (SOCKET(s)->client_addr)
94 95
 #define SOCKET_ADDR_UNIX(s)    ((struct sockaddr_un  *) &SOCKET_ADDR(s))
@@ -106,9 +107,7 @@ typedef struct {
106 107
 
107 108
 
108 109
 #define cherokee_socket_configured(c)    (SOCKET_FD(c) >= 0)
109  
-#define cherokee_socket_is_connected(c)  (cherokee_socket_configured(c) && \
110  
-					  (SOCKET_STATUS(c) != socket_closed))
111  
-
  110
+#define cherokee_socket_is_connected(c)  (cherokee_socket_configured(c) && (!SOCKET(c)->closed))
112 111
 
113 112
 ret_t cherokee_socket_init              (cherokee_socket_t *socket);
114 113
 ret_t cherokee_socket_mrproper          (cherokee_socket_t *socket);
@@ -137,7 +136,6 @@ ret_t cherokee_socket_connect           (cherokee_socket_t *socket);
137 136
 ret_t cherokee_socket_ntop              (cherokee_socket_t *socket, char *buf, size_t buf_size);
138 137
 ret_t cherokee_socket_pton              (cherokee_socket_t *socket, cherokee_buffer_t *buf);
139 138
 ret_t cherokee_socket_gethostbyname     (cherokee_socket_t *socket, cherokee_buffer_t *hostname);
140  
-ret_t cherokee_socket_set_status        (cherokee_socket_t *socket, cherokee_socket_status_t status);
141 139
 ret_t cherokee_socket_set_cork          (cherokee_socket_t *socket, cherokee_boolean_t enable);
142 140
 
143 141
 
49  cherokee/thread.c
@@ -262,28 +262,6 @@ cherokee_thread_new  (cherokee_thread_t      **thd,
262 262
 
263 263
 
264 264
 static void
265  
-conn_set_mode (cherokee_thread_t        *thd,
266  
-	       cherokee_connection_t    *conn,
267  
-	       cherokee_socket_status_t  s)
268  
-{
269  
-	UNUSED(thd);
270  
-
271  
-	if (conn->socket.status == s) {
272  
-		TRACE (ENTRIES, "Connection already in mode = %s\n",
273  
-		       (s == socket_reading)? "reading" :
274  
-		       (s == socket_writing)? "writing" : "???");
275  
-		return;
276  
-	}
277  
-
278  
-	TRACE (ENTRIES, "Connection mode = %s\n",
279  
-	       (s == socket_reading)? "reading" :
280  
-	       (s == socket_writing)? "writing" : "???");
281  
-
282  
-	cherokee_socket_set_status (&conn->socket, s);
283  
-}
284  
-
285  
-
286  
-static void
287 265
 add_connection (cherokee_thread_t *thd, cherokee_connection_t *conn)
288 266
 {
289 267
 	cherokee_list_add_tail (LIST(conn), &thd->active_list);
@@ -428,7 +406,6 @@ maybe_purge_closed_connection (cherokee_thread_t *thread, cherokee_connection_t
428 406
 	/* Clean the connection
429 407
 	 */
430 408
 	cherokee_connection_clean (conn);
431  
-	conn_set_mode (thread, conn, socket_reading);
432 409
 
433 410
 	/* Update the timeout value
434 411
 	 */
@@ -606,10 +583,8 @@ process_active_connections (cherokee_thread_t *thd)
606 583
 		list_for_each_safe (i, tmp, &thd->active_list) {
607 584
 			conn = CONN(i);
608 585
 
609  
-			TRACE (ENTRIES",active", "   \\- processing conn (%p), phase %d '%s', socket=%d,%s\n",
610  
-			       conn, conn->phase, cherokee_connection_get_phase_str (conn), conn->socket.socket,
611  
-			       (conn->socket.status == socket_reading)? "read" :
612  
-			       (conn->socket.status == socket_writing)? "writing" : "closed");
  586
+			TRACE (ENTRIES",active", "   \\- processing conn (%p), phase %d '%s', socket=%d\n",
  587
+			       conn, conn->phase, cherokee_connection_get_phase_str (conn), conn->socket.socket);
613 588
 		}
614 589
 	}
615 590
 #endif
@@ -619,10 +594,8 @@ process_active_connections (cherokee_thread_t *thd)
619 594
 	list_for_each_safe (i, tmp, LIST(&thd->active_list)) {
620 595
 		conn = CONN(i);
621 596
 
622  
-		TRACE (ENTRIES, "processing conn (%p), phase %d '%s', socket=%d, %s\n",
623  
-		       conn, conn->phase, cherokee_connection_get_phase_str (conn), conn->socket.socket,
624  
-		       (conn->socket.status == socket_reading)? "read" :
625  
-		       (conn->socket.status == socket_writing)? "writing" : "closed");
  597
+		TRACE (ENTRIES, "processing conn (%p), phase %d '%s', socket=%d\n",
  598
+		       conn, conn->phase, cherokee_connection_get_phase_str (conn), conn->socket.socket);
626 599
 
627 600
 		/* Thread's properties
628 601
 		 */
@@ -707,11 +680,9 @@ process_active_connections (cherokee_thread_t *thd)
707 680
 			case ret_eagain:
708 681
 				switch (blocking) {
709 682
 				case socket_reading:
710  
-					conn_set_mode (thd, conn, socket_reading);
711 683
 					break;
712 684
 
713 685
 				case socket_writing:
714  
-					conn_set_mode (thd, conn, socket_writing);
715 686
 					break;
716 687
 
717 688
 				default:
@@ -725,7 +696,6 @@ process_active_connections (cherokee_thread_t *thd)
725 696
 
726 697
 				/* Set mode and update timeout
727 698
 				 */
728  
-				conn_set_mode (thd, conn, socket_reading);
729 699
 				cherokee_connection_update_timeout (conn);
730 700
 
731 701
 				conn->phase = phase_reading_header;
@@ -827,7 +797,6 @@ process_active_connections (cherokee_thread_t *thd)
827 797
 
828 798
 			default:
829 799
 				cherokee_connection_setup_error_handler (conn);
830  
-				conn_set_mode (thd, conn, socket_writing);
831 800
 				continue;
832 801
 			}
833 802
 
@@ -865,10 +834,6 @@ process_active_connections (cherokee_thread_t *thd)
865 834
 			cherokee_rule_list_t *rules;
866 835
 			cherokee_boolean_t    is_userdir;
867 836
 
868  
-			/* Turn the connection in write mode
869  
-			 */
870  
-			conn_set_mode (thd, conn, socket_writing);
871  
-
872 837
 			/* HSTS support
873 838
 			 */
874 839
 			if ((conn->socket.is_tls != TLS) &&
@@ -1134,8 +1099,6 @@ process_active_connections (cherokee_thread_t *thd)
1134 1099
 				if (cherokee_connection_poll_is_set (&conn->polling_aim)) {
1135 1100
 					cherokee_thread_deactive_to_polling (thd, conn);
1136 1101
 				}
1137  
-
1138  
-//				conn_set_mode (thd, conn, socket_reading);
1139 1102
 				continue;
1140 1103
 			case ret_eof:
1141 1104
 			case ret_error:
@@ -1148,7 +1111,6 @@ process_active_connections (cherokee_thread_t *thd)
1148 1111
 
1149 1112
 			/* Turn the connection in write mode
1150 1113
 			 */
1151  
-//			conn_set_mode (thd, conn, socket_writing);
1152 1114
 			conn->phase = phase_add_headers;
1153 1115
 
1154 1116
 		case phase_add_headers:
@@ -1341,7 +1303,6 @@ process_active_connections (cherokee_thread_t *thd)
1341 1303
 					break;
1342 1304
 
1343 1305
 				case ret_eagain:
1344  
-					conn_set_mode (thd, conn, socket_reading);
1345 1306
 					cherokee_thread_deactive_to_polling (thd, conn);
1346 1307
 					continue;
1347 1308
 
@@ -1365,7 +1326,6 @@ process_active_connections (cherokee_thread_t *thd)
1365 1326
 				/* Wait for the socket to be readable:
1366 1327
 				 * FIN + ACK will have arrived by then
1367 1328
 				 */
1368  
-				conn_set_mode (thd, conn, socket_reading);
1369 1329
 				conn->phase = phase_lingering;
1370 1330
 
1371 1331
 				break;
@@ -1627,7 +1587,6 @@ accept_new_connection (cherokee_thread_t *thd,
1627 1587
 
1628 1588
 	/* Lets add the new connection
1629 1589
 	 */
1630  
-	conn_set_mode (thd, new_conn, socket_reading);
1631 1590
 	add_connection (thd, new_conn);
1632 1591
 
1633 1592
 	thd->conns_num++;

0 notes on commit 5be7419

Please sign in to comment.
Something went wrong with that request. Please try again.