diff options
Diffstat (limited to 'src/daemon/connection.c')
-rw-r--r-- | src/daemon/connection.c | 52 |
1 files changed, 33 insertions, 19 deletions
diff --git a/src/daemon/connection.c b/src/daemon/connection.c index cdc8540b..1b7a04ed 100644 --- a/src/daemon/connection.c +++ b/src/daemon/connection.c | |||
@@ -181,6 +181,22 @@ MHD_need_100_continue (struct MHD_Connection *connection) | |||
181 | } | 181 | } |
182 | 182 | ||
183 | /** | 183 | /** |
184 | * A serious error occured, close the | ||
185 | * connection (and notify the application). | ||
186 | */ | ||
187 | static void | ||
188 | connection_close_error(struct MHD_Connection * connection) | ||
189 | { | ||
190 | CLOSE (connection->socket_fd); | ||
191 | connection->socket_fd = -1; | ||
192 | if (connection->daemon->notify_completed != NULL) | ||
193 | connection->daemon->notify_completed(connection->daemon->notify_completed_cls, | ||
194 | connection, | ||
195 | &connection->client_context, | ||
196 | MHD_REQUEST_TERMINATED_WITH_ERROR); | ||
197 | } | ||
198 | |||
199 | /** | ||
184 | * Prepare the response buffer of this connection for | 200 | * Prepare the response buffer of this connection for |
185 | * sending. Assumes that the response mutex is | 201 | * sending. Assumes that the response mutex is |
186 | * already held. If the transmission is complete, | 202 | * already held. If the transmission is complete, |
@@ -209,8 +225,7 @@ ready_response (struct MHD_Connection *connection) | |||
209 | "Closing connection (end of response)\n"); | 225 | "Closing connection (end of response)\n"); |
210 | #endif | 226 | #endif |
211 | response->total_size = connection->messagePos; | 227 | response->total_size = connection->messagePos; |
212 | CLOSE (connection->socket_fd); | 228 | connection_close_error(connection); |
213 | connection->socket_fd = -1; | ||
214 | return MHD_NO; | 229 | return MHD_NO; |
215 | } | 230 | } |
216 | response->data_start = connection->messagePos; | 231 | response->data_start = connection->messagePos; |
@@ -746,8 +761,7 @@ MHD_parse_connection_headers (struct MHD_Connection *connection) | |||
746 | DIE: | 761 | DIE: |
747 | MHD_DLOG (connection->daemon, | 762 | MHD_DLOG (connection->daemon, |
748 | "Closing connection (problem parsing headers)\n"); | 763 | "Closing connection (problem parsing headers)\n"); |
749 | CLOSE (connection->socket_fd); | 764 | connection_close_error(connection); |
750 | connection->socket_fd = -1; | ||
751 | } | 765 | } |
752 | 766 | ||
753 | 767 | ||
@@ -889,13 +903,13 @@ MHD_call_connection_handler (struct MHD_Connection *connection) | |||
889 | connection->url, | 903 | connection->url, |
890 | connection->method, | 904 | connection->method, |
891 | connection->version, | 905 | connection->version, |
892 | connection->read_buffer, &processed)) | 906 | connection->read_buffer, &processed, |
907 | &connection->client_context)) | ||
893 | { | 908 | { |
894 | /* serios internal error, close connection */ | 909 | /* serios internal error, close connection */ |
895 | MHD_DLOG (connection->daemon, | 910 | MHD_DLOG (connection->daemon, |
896 | "Internal application error, closing connection.\n"); | 911 | "Internal application error, closing connection.\n"); |
897 | CLOSE (connection->socket_fd); | 912 | connection_close_error(connection); |
898 | connection->socket_fd = -1; | ||
899 | return; | 913 | return; |
900 | } | 914 | } |
901 | /* dh left "processed" bytes in buffer for next time... */ | 915 | /* dh left "processed" bytes in buffer for next time... */ |
@@ -934,8 +948,7 @@ MHD_connection_handle_read (struct MHD_Connection *connection) | |||
934 | if (connection->pool == NULL) | 948 | if (connection->pool == NULL) |
935 | { | 949 | { |
936 | MHD_DLOG (connection->daemon, "Failed to create memory pool!\n"); | 950 | MHD_DLOG (connection->daemon, "Failed to create memory pool!\n"); |
937 | CLOSE (connection->socket_fd); | 951 | connection_close_error(connection); |
938 | connection->socket_fd = -1; | ||
939 | return MHD_NO; | 952 | return MHD_NO; |
940 | } | 953 | } |
941 | if ((connection->readLoc >= connection->read_buffer_size) && | 954 | if ((connection->readLoc >= connection->read_buffer_size) && |
@@ -973,8 +986,7 @@ MHD_connection_handle_read (struct MHD_Connection *connection) | |||
973 | return MHD_NO; | 986 | return MHD_NO; |
974 | MHD_DLOG (connection->daemon, | 987 | MHD_DLOG (connection->daemon, |
975 | "Failed to receive data: %s\n", STRERROR (errno)); | 988 | "Failed to receive data: %s\n", STRERROR (errno)); |
976 | CLOSE (connection->socket_fd); | 989 | connection_close_error(connection); |
977 | connection->socket_fd = -1; | ||
978 | return MHD_YES; | 990 | return MHD_YES; |
979 | } | 991 | } |
980 | if (bytes_read == 0) | 992 | if (bytes_read == 0) |
@@ -1150,8 +1162,7 @@ MHD_connection_handle_write (struct MHD_Connection *connection) | |||
1150 | return MHD_YES; | 1162 | return MHD_YES; |
1151 | MHD_DLOG (connection->daemon, | 1163 | MHD_DLOG (connection->daemon, |
1152 | "Failed to send data: %s\n", STRERROR (errno)); | 1164 | "Failed to send data: %s\n", STRERROR (errno)); |
1153 | CLOSE (connection->socket_fd); | 1165 | connection_close_error(connection); |
1154 | connection->socket_fd = -1; | ||
1155 | return MHD_YES; | 1166 | return MHD_YES; |
1156 | } | 1167 | } |
1157 | #if DEBUG_SEND_DATA | 1168 | #if DEBUG_SEND_DATA |
@@ -1176,8 +1187,7 @@ MHD_connection_handle_write (struct MHD_Connection *connection) | |||
1176 | /* oops - close! */ | 1187 | /* oops - close! */ |
1177 | MHD_DLOG (connection->daemon, | 1188 | MHD_DLOG (connection->daemon, |
1178 | "Closing connection (failed to create response header)\n"); | 1189 | "Closing connection (failed to create response header)\n"); |
1179 | CLOSE (connection->socket_fd); | 1190 | connection_close_error(connection); |
1180 | connection->socket_fd = -1; | ||
1181 | return MHD_NO; | 1191 | return MHD_NO; |
1182 | } | 1192 | } |
1183 | ret = SEND (connection->socket_fd, | 1193 | ret = SEND (connection->socket_fd, |
@@ -1189,8 +1199,7 @@ MHD_connection_handle_write (struct MHD_Connection *connection) | |||
1189 | return MHD_YES; | 1199 | return MHD_YES; |
1190 | MHD_DLOG (connection->daemon, | 1200 | MHD_DLOG (connection->daemon, |
1191 | "Failed to send data: %s\n", STRERROR (errno)); | 1201 | "Failed to send data: %s\n", STRERROR (errno)); |
1192 | CLOSE (connection->socket_fd); | 1202 | connection_close_error(connection); |
1193 | connection->socket_fd = -1; | ||
1194 | return MHD_YES; | 1203 | return MHD_YES; |
1195 | } | 1204 | } |
1196 | #if DEBUG_SEND_DATA | 1205 | #if DEBUG_SEND_DATA |
@@ -1240,8 +1249,7 @@ MHD_connection_handle_write (struct MHD_Connection *connection) | |||
1240 | return MHD_YES; | 1249 | return MHD_YES; |
1241 | MHD_DLOG (connection->daemon, | 1250 | MHD_DLOG (connection->daemon, |
1242 | "Failed to send data: %s\n", STRERROR (errno)); | 1251 | "Failed to send data: %s\n", STRERROR (errno)); |
1243 | CLOSE (connection->socket_fd); | 1252 | connection_close_error(connection); |
1244 | connection->socket_fd = -1; | ||
1245 | return MHD_YES; | 1253 | return MHD_YES; |
1246 | } | 1254 | } |
1247 | #if DEBUG_SEND_DATA | 1255 | #if DEBUG_SEND_DATA |
@@ -1259,6 +1267,12 @@ MHD_connection_handle_write (struct MHD_Connection *connection) | |||
1259 | (connection->headersReceived == 0)) | 1267 | (connection->headersReceived == 0)) |
1260 | abort (); /* internal error */ | 1268 | abort (); /* internal error */ |
1261 | MHD_destroy_response (response); | 1269 | MHD_destroy_response (response); |
1270 | if (connection->daemon->notify_completed != NULL) | ||
1271 | connection->daemon->notify_completed(connection->daemon->notify_completed_cls, | ||
1272 | connection, | ||
1273 | &connection->client_context, | ||
1274 | MHD_REQUEST_TERMINATED_COMPLETED_OK); | ||
1275 | connection->client_context = NULL; | ||
1262 | connection->continuePos = 0; | 1276 | connection->continuePos = 0; |
1263 | connection->responseCode = 0; | 1277 | connection->responseCode = 0; |
1264 | connection->response = NULL; | 1278 | connection->response = NULL; |