aboutsummaryrefslogtreecommitdiff
path: root/src/microhttpd/daemon.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/microhttpd/daemon.c')
-rw-r--r--src/microhttpd/daemon.c31
1 files changed, 30 insertions, 1 deletions
diff --git a/src/microhttpd/daemon.c b/src/microhttpd/daemon.c
index 29b61053..2f88b2d3 100644
--- a/src/microhttpd/daemon.c
+++ b/src/microhttpd/daemon.c
@@ -983,7 +983,8 @@ create_thread (pthread_t *thread,
983 * @param addrlen number of bytes in addr 983 * @param addrlen number of bytes in addr
984 * @return MHD_YES on success, MHD_NO if this daemon could 984 * @return MHD_YES on success, MHD_NO if this daemon could
985 * not handle the connection (i.e. malloc failed, etc). 985 * not handle the connection (i.e. malloc failed, etc).
986 * The socket will be closed in any case. 986 * The socket will be closed in any case; 'errno' is
987 * set to indicate further details about the error.
987 */ 988 */
988int 989int
989MHD_add_connection (struct MHD_Daemon *daemon, 990MHD_add_connection (struct MHD_Daemon *daemon,
@@ -994,6 +995,7 @@ MHD_add_connection (struct MHD_Daemon *daemon,
994 struct MHD_Connection *connection; 995 struct MHD_Connection *connection;
995 int res_thread_create; 996 int res_thread_create;
996 unsigned int i; 997 unsigned int i;
998 int eno;
997#if OSX 999#if OSX
998 static int on = 1; 1000 static int on = 1;
999#endif 1001#endif
@@ -1011,6 +1013,9 @@ MHD_add_connection (struct MHD_Daemon *daemon,
1011 /* all pools are at their connection limit, must refuse */ 1013 /* all pools are at their connection limit, must refuse */
1012 if (0 != CLOSE (client_socket)) 1014 if (0 != CLOSE (client_socket))
1013 MHD_PANIC ("close failed\n"); 1015 MHD_PANIC ("close failed\n");
1016#if ENFILE
1017 errno = ENFILE;
1018#endif
1014 return MHD_NO; 1019 return MHD_NO;
1015 } 1020 }
1016 1021
@@ -1026,6 +1031,9 @@ MHD_add_connection (struct MHD_Daemon *daemon,
1026#endif 1031#endif
1027 if (0 != CLOSE (client_socket)) 1032 if (0 != CLOSE (client_socket))
1028 MHD_PANIC ("close failed\n"); 1033 MHD_PANIC ("close failed\n");
1034#if EINVAL
1035 errno = EINVAL;
1036#endif
1029 return MHD_NO; 1037 return MHD_NO;
1030 } 1038 }
1031#endif 1039#endif
@@ -1046,6 +1054,9 @@ MHD_add_connection (struct MHD_Daemon *daemon,
1046#endif 1054#endif
1047 if (0 != CLOSE (client_socket)) 1055 if (0 != CLOSE (client_socket))
1048 MHD_PANIC ("close failed\n"); 1056 MHD_PANIC ("close failed\n");
1057#if ENFILE
1058 errno = ENFILE;
1059#endif
1049 return MHD_NO; 1060 return MHD_NO;
1050 } 1061 }
1051 1062
@@ -1062,6 +1073,9 @@ MHD_add_connection (struct MHD_Daemon *daemon,
1062 if (0 != CLOSE (client_socket)) 1073 if (0 != CLOSE (client_socket))
1063 MHD_PANIC ("close failed\n"); 1074 MHD_PANIC ("close failed\n");
1064 MHD_ip_limit_del (daemon, addr, addrlen); 1075 MHD_ip_limit_del (daemon, addr, addrlen);
1076#if EACCESS
1077 errno = EACCESS;
1078#endif
1065 return MHD_NO; 1079 return MHD_NO;
1066 } 1080 }
1067 1081
@@ -1077,6 +1091,7 @@ MHD_add_connection (struct MHD_Daemon *daemon,
1077 1091
1078 if (NULL == (connection = malloc (sizeof (struct MHD_Connection)))) 1092 if (NULL == (connection = malloc (sizeof (struct MHD_Connection))))
1079 { 1093 {
1094 eno = errno;
1080#if HAVE_MESSAGES 1095#if HAVE_MESSAGES
1081 MHD_DLOG (daemon, 1096 MHD_DLOG (daemon,
1082 "Error allocating memory: %s\n", 1097 "Error allocating memory: %s\n",
@@ -1085,6 +1100,7 @@ MHD_add_connection (struct MHD_Daemon *daemon,
1085 if (0 != CLOSE (client_socket)) 1100 if (0 != CLOSE (client_socket))
1086 MHD_PANIC ("close failed\n"); 1101 MHD_PANIC ("close failed\n");
1087 MHD_ip_limit_del (daemon, addr, addrlen); 1102 MHD_ip_limit_del (daemon, addr, addrlen);
1103 errno = eno;
1088 return MHD_NO; 1104 return MHD_NO;
1089 } 1105 }
1090 memset (connection, 0, sizeof (struct MHD_Connection)); 1106 memset (connection, 0, sizeof (struct MHD_Connection));
@@ -1100,12 +1116,16 @@ MHD_add_connection (struct MHD_Daemon *daemon,
1100 MHD_PANIC ("close failed\n"); 1116 MHD_PANIC ("close failed\n");
1101 MHD_ip_limit_del (daemon, addr, addrlen); 1117 MHD_ip_limit_del (daemon, addr, addrlen);
1102 free (connection); 1118 free (connection);
1119#if ENOMEM
1120 errno = ENOMEM;
1121#endif
1103 return MHD_NO; 1122 return MHD_NO;
1104 } 1123 }
1105 1124
1106 connection->connection_timeout = daemon->connection_timeout; 1125 connection->connection_timeout = daemon->connection_timeout;
1107 if (NULL == (connection->addr = malloc (addrlen))) 1126 if (NULL == (connection->addr = malloc (addrlen)))
1108 { 1127 {
1128 eno = errno;
1109#if HAVE_MESSAGES 1129#if HAVE_MESSAGES
1110 MHD_DLOG (daemon, 1130 MHD_DLOG (daemon,
1111 "Error allocating memory: %s\n", 1131 "Error allocating memory: %s\n",
@@ -1116,6 +1136,7 @@ MHD_add_connection (struct MHD_Daemon *daemon,
1116 MHD_ip_limit_del (daemon, addr, addrlen); 1136 MHD_ip_limit_del (daemon, addr, addrlen);
1117 MHD_pool_destroy (connection->pool); 1137 MHD_pool_destroy (connection->pool);
1118 free (connection); 1138 free (connection);
1139 errno = eno;
1119 return MHD_NO; 1140 return MHD_NO;
1120 } 1141 }
1121 memcpy (connection->addr, addr, addrlen); 1142 memcpy (connection->addr, addr, addrlen);
@@ -1196,6 +1217,9 @@ MHD_add_connection (struct MHD_Daemon *daemon,
1196 free (connection->addr); 1217 free (connection->addr);
1197 free (connection); 1218 free (connection);
1198 MHD_PANIC ("Unknown credential type"); 1219 MHD_PANIC ("Unknown credential type");
1220#if EINVAL
1221 errno = EINVAL;
1222#endif
1199 return MHD_NO; 1223 return MHD_NO;
1200 } 1224 }
1201 gnutls_transport_set_ptr (connection->tls_session, 1225 gnutls_transport_set_ptr (connection->tls_session,
@@ -1231,6 +1255,7 @@ MHD_add_connection (struct MHD_Daemon *daemon,
1231 &MHD_handle_connection, connection); 1255 &MHD_handle_connection, connection);
1232 if (0 != res_thread_create) 1256 if (0 != res_thread_create)
1233 { 1257 {
1258 eno = errno;
1234#if HAVE_MESSAGES 1259#if HAVE_MESSAGES
1235 MHD_DLOG (daemon, "Failed to create a thread: %s\n", 1260 MHD_DLOG (daemon, "Failed to create a thread: %s\n",
1236 STRERROR (res_thread_create)); 1261 STRERROR (res_thread_create));
@@ -1252,6 +1277,7 @@ MHD_add_connection (struct MHD_Daemon *daemon,
1252 client_socket, 1277 client_socket,
1253 &event)) 1278 &event))
1254 { 1279 {
1280 eno = errno;
1255#if HAVE_MESSAGES 1281#if HAVE_MESSAGES
1256 if (0 != (daemon->options & MHD_USE_DEBUG)) 1282 if (0 != (daemon->options & MHD_USE_DEBUG))
1257 MHD_DLOG (daemon, 1283 MHD_DLOG (daemon,
@@ -1294,6 +1320,9 @@ MHD_add_connection (struct MHD_Daemon *daemon,
1294 MHD_pool_destroy (connection->pool); 1320 MHD_pool_destroy (connection->pool);
1295 free (connection->addr); 1321 free (connection->addr);
1296 free (connection); 1322 free (connection);
1323#if EINVAL
1324 errno = eno;
1325#endif
1297 return MHD_NO; 1326 return MHD_NO;
1298#endif 1327#endif
1299} 1328}