aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEvgeny Grin (Karlson2k) <k2k@narod.ru>2021-04-18 20:47:38 +0300
committerEvgeny Grin (Karlson2k) <k2k@narod.ru>2021-04-18 20:47:38 +0300
commite53b8c0b2898d16997be6037c308846c561073a0 (patch)
treed155bdc3a10e131d41c4c5a61e2e931c9fe65332
parentc5b661b67239534f976da20f95a4f0ff53e7700e (diff)
downloadlibmicrohttpd-e53b8c0b2898d16997be6037c308846c561073a0.tar.gz
libmicrohttpd-e53b8c0b2898d16997be6037c308846c561073a0.zip
connection: report socket error in MHD log
-rw-r--r--src/microhttpd/connection.c77
1 files changed, 69 insertions, 8 deletions
diff --git a/src/microhttpd/connection.c b/src/microhttpd/connection.c
index db130e18..baf0fcb4 100644
--- a/src/microhttpd/connection.c
+++ b/src/microhttpd/connection.c
@@ -126,6 +126,47 @@
126#define MHD_SENFILE_CHUNK_THR_P_C_ (0x200000) 126#define MHD_SENFILE_CHUNK_THR_P_C_ (0x200000)
127 127
128/** 128/**
129 * Return text description for MHD_ERR_*_ codes
130 * @param mhd_err_code the error code
131 * @return pointer to static string with error description
132 */
133static const char *
134str_conn_error_ (ssize_t mhd_err_code)
135{
136#ifdef HAVE_MESSAGES
137 switch (mhd_err_code)
138 {
139 case MHD_ERR_AGAIN_:
140 return _ ("The operation would block, retry later");
141 case MHD_ERR_CONNRESET_:
142 return _ ("The connection was forcibly closed by remote peer");
143 case MHD_ERR_NOTCONN_:
144 return _ ("The socket is not connected");
145 case MHD_ERR_NOMEM_:
146 return _ ("Not enough system resources to serve the request");
147 case MHD_ERR_BADF_:
148 return _ ("Bad FD value");
149 case MHD_ERR_INVAL_:
150 return _ ("Argument value is invalid");
151 case MHD_ERR_OPNOTSUPP_:
152 return _ ("Argument value is not supported");
153 case MHD_ERR_PIPE_:
154 return _ ("The socket is no longer available for sending");
155 default:
156 break; /* Mute compiler warning */
157 }
158 if (0 <= mhd_err_code)
159 return _ ("Not an error code");
160
161 mhd_assert (0); /* Should never be reachable */
162 return _ ("Wrong error code value");
163#else /* ! HAVE_MESSAGES */
164 return "";
165#endif /* ! HAVE_MESSAGES */
166}
167
168
169/**
129 * Callback for receiving data from the socket. 170 * Callback for receiving data from the socket.
130 * 171 *
131 * @param connection the MHD connection structure 172 * @param connection the MHD connection structure
@@ -2999,9 +3040,15 @@ MHD_connection_handle_write (struct MHD_Connection *connection)
2999 { 3040 {
3000 if (MHD_ERR_AGAIN_ == ret) 3041 if (MHD_ERR_AGAIN_ == ret)
3001 return; 3042 return;
3043#ifdef HAVE_MESSAGES
3044 MHD_DLOG (connection->daemon,
3045 _ ("Failed to send the response headers for the " \
3046 "request for `%s'. Error: %s\n"),
3047 connection->url,
3048 str_conn_error_ (ret));
3049#endif
3002 CONNECTION_CLOSE_ERROR (connection, 3050 CONNECTION_CLOSE_ERROR (connection,
3003 _ ( 3051 NULL);
3004 "Connection was closed while sending response headers.\n"));
3005 return; 3052 return;
3006 } 3053 }
3007 /* 'ret' is not negative, it's safe to cast it to 'size_t'. */ 3054 /* 'ret' is not negative, it's safe to cast it to 'size_t'. */
@@ -3087,8 +3134,10 @@ MHD_connection_handle_write (struct MHD_Connection *connection)
3087 return; 3134 return;
3088#ifdef HAVE_MESSAGES 3135#ifdef HAVE_MESSAGES
3089 MHD_DLOG (connection->daemon, 3136 MHD_DLOG (connection->daemon,
3090 _ ("Failed to send data in request for `%s'.\n"), 3137 _ ("Failed to send the response body for the " \
3091 connection->url); 3138 "request for `%s'. Error: %s\n"),
3139 connection->url,
3140 str_conn_error_ (ret));
3092#endif 3141#endif
3093 CONNECTION_CLOSE_ERROR (connection, 3142 CONNECTION_CLOSE_ERROR (connection,
3094 NULL); 3143 NULL);
@@ -3115,9 +3164,15 @@ MHD_connection_handle_write (struct MHD_Connection *connection)
3115 { 3164 {
3116 if (MHD_ERR_AGAIN_ == ret) 3165 if (MHD_ERR_AGAIN_ == ret)
3117 return; 3166 return;
3167#ifdef HAVE_MESSAGES
3168 MHD_DLOG (connection->daemon,
3169 _ ("Failed to send the chunked response body for the " \
3170 "request for `%s'. Error: %s\n"),
3171 connection->url,
3172 str_conn_error_ (ret));
3173#endif
3118 CONNECTION_CLOSE_ERROR (connection, 3174 CONNECTION_CLOSE_ERROR (connection,
3119 _ ( 3175 NULL);
3120 "Connection was closed while sending response body.\n"));
3121 return; 3176 return;
3122 } 3177 }
3123 connection->write_buffer_send_offset += ret; 3178 connection->write_buffer_send_offset += ret;
@@ -3145,9 +3200,15 @@ MHD_connection_handle_write (struct MHD_Connection *connection)
3145 { 3200 {
3146 if (MHD_ERR_AGAIN_ == ret) 3201 if (MHD_ERR_AGAIN_ == ret)
3147 return; 3202 return;
3203#ifdef HAVE_MESSAGES
3204 MHD_DLOG (connection->daemon,
3205 _ ("Failed to send the footers for the " \
3206 "request for `%s'. Error: %s\n"),
3207 connection->url,
3208 str_conn_error_ (ret));
3209#endif
3148 CONNECTION_CLOSE_ERROR (connection, 3210 CONNECTION_CLOSE_ERROR (connection,
3149 _ ( 3211 NULL);
3150 "Connection was closed while sending response body.\n"));
3151 return; 3212 return;
3152 } 3213 }
3153 connection->write_buffer_send_offset += ret; 3214 connection->write_buffer_send_offset += ret;