aboutsummaryrefslogtreecommitdiff
path: root/src/daemon/connection.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/daemon/connection.c')
-rw-r--r--src/daemon/connection.c51
1 files changed, 49 insertions, 2 deletions
diff --git a/src/daemon/connection.c b/src/daemon/connection.c
index 6735147a..864e1190 100644
--- a/src/daemon/connection.c
+++ b/src/daemon/connection.c
@@ -43,6 +43,19 @@
43#define REQUEST_TOO_BIG "" 43#define REQUEST_TOO_BIG ""
44 44
45/** 45/**
46 * Add extra debug messages with reasons for closing connections
47 * (non-error reasons).
48 */
49#define DEBUG_CLOSE 0
50
51
52/**
53 * Should all data send be printed to stderr?
54 */
55#define DEBUG_SEND_DATA 0
56
57
58/**
46 * Get all of the headers from the request. 59 * Get all of the headers from the request.
47 * 60 *
48 * @param iterator callback to call on each header; 61 * @param iterator callback to call on each header;
@@ -179,6 +192,10 @@ ready_response (struct MHD_Connection *connection)
179 if (ret == -1) 192 if (ret == -1)
180 { 193 {
181 /* end of message, signal other side by closing! */ 194 /* end of message, signal other side by closing! */
195#if DEBUG_CLOSE
196 MHD_DLOG (connection->daemon,
197 "Closing connection (end of response)\n");
198#endif
182 response->total_size = connection->messagePos; 199 response->total_size = connection->messagePos;
183 CLOSE (connection->socket_fd); 200 CLOSE (connection->socket_fd);
184 connection->socket_fd = -1; 201 connection->socket_fd = -1;
@@ -693,6 +710,8 @@ MHD_parse_connection_headers (struct MHD_Connection *connection)
693 MHD_parse_cookie_header (connection); 710 MHD_parse_cookie_header (connection);
694 return; 711 return;
695DIE: 712DIE:
713 MHD_DLOG (connection->daemon,
714 "Closing connection (problem parsing headers)\n");
696 CLOSE (connection->socket_fd); 715 CLOSE (connection->socket_fd);
697 connection->socket_fd = -1; 716 connection->socket_fd = -1;
698} 717}
@@ -930,6 +949,10 @@ MHD_connection_handle_read (struct MHD_Connection *connection)
930 connection->read_close = MHD_YES; 949 connection->read_close = MHD_YES;
931 if (connection->readLoc > 0) 950 if (connection->readLoc > 0)
932 MHD_call_connection_handler (connection); 951 MHD_call_connection_handler (connection);
952#if DEBUG_CLOSE
953 MHD_DLOG (connection->daemon,
954 "Shutting down connection for reading (other side closed connection)\n");
955#endif
933 shutdown (connection->socket_fd, SHUT_RD); 956 shutdown (connection->socket_fd, SHUT_RD);
934 return MHD_YES; 957 return MHD_YES;
935 } 958 }
@@ -1096,7 +1119,12 @@ MHD_connection_handle_write (struct MHD_Connection *connection)
1096 connection->socket_fd = -1; 1119 connection->socket_fd = -1;
1097 return MHD_YES; 1120 return MHD_YES;
1098 } 1121 }
1099 connection->continuePos += ret; 1122#if DEBUG_SEND_DATA
1123 fprintf(stderr,
1124 "Sent 100 continue response: `%.*s'\n",
1125 ret,
1126 &HTTP_100_CONTINUE[connection->continuePos]);
1127#endif
1100 return MHD_YES; 1128 return MHD_YES;
1101 } 1129 }
1102 response = connection->response; 1130 response = connection->response;
@@ -1111,6 +1139,8 @@ MHD_connection_handle_write (struct MHD_Connection *connection)
1111 (MHD_NO == MHD_build_header_response (connection))) 1139 (MHD_NO == MHD_build_header_response (connection)))
1112 { 1140 {
1113 /* oops - close! */ 1141 /* oops - close! */
1142 MHD_DLOG (connection->daemon,
1143 "Closing connection (failed to create response header)\n");
1114 CLOSE (connection->socket_fd); 1144 CLOSE (connection->socket_fd);
1115 connection->socket_fd = -1; 1145 connection->socket_fd = -1;
1116 return MHD_NO; 1146 return MHD_NO;
@@ -1128,6 +1158,12 @@ MHD_connection_handle_write (struct MHD_Connection *connection)
1128 connection->socket_fd = -1; 1158 connection->socket_fd = -1;
1129 return MHD_YES; 1159 return MHD_YES;
1130 } 1160 }
1161#if DEBUG_SEND_DATA
1162 fprintf(stderr,
1163 "Sent HEADER response: `%.*s'\n",
1164 ret,
1165 &connection->write_buffer[connection->writePos]);
1166#endif
1131 connection->writePos += ret; 1167 connection->writePos += ret;
1132 if (connection->writeLoc == connection->writePos) 1168 if (connection->writeLoc == connection->writePos)
1133 { 1169 {
@@ -1173,6 +1209,12 @@ MHD_connection_handle_write (struct MHD_Connection *connection)
1173 connection->socket_fd = -1; 1209 connection->socket_fd = -1;
1174 return MHD_YES; 1210 return MHD_YES;
1175 } 1211 }
1212#if DEBUG_SEND_DATA
1213 fprintf(stderr,
1214 "Sent DATA response: `%.*s'\n",
1215 ret,
1216 &response->data[connection->messagePos - response->data_start]);
1217#endif
1176 connection->messagePos += ret; 1218 connection->messagePos += ret;
1177 if (connection->messagePos > response->total_size) 1219 if (connection->messagePos > response->total_size)
1178 abort (); /* internal error */ 1220 abort (); /* internal error */
@@ -1196,8 +1238,13 @@ MHD_connection_handle_write (struct MHD_Connection *connection)
1196 (0 != strcasecmp (MHD_HTTP_VERSION_1_1, connection->version))) 1238 (0 != strcasecmp (MHD_HTTP_VERSION_1_1, connection->version)))
1197 { 1239 {
1198 /* closed for reading => close for good! */ 1240 /* closed for reading => close for good! */
1199 if (connection->socket_fd != -1) 1241 if (connection->socket_fd != -1) {
1242#if DEBUG_CLOSE
1243 MHD_DLOG (connection->daemon,
1244 "Closing connection (http 1.0 or end-of-stream for unknown content length)\n");
1245#endif
1200 CLOSE (connection->socket_fd); 1246 CLOSE (connection->socket_fd);
1247 }
1201 connection->socket_fd = -1; 1248 connection->socket_fd = -1;
1202 } 1249 }
1203 connection->version = NULL; 1250 connection->version = NULL;