aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEvgeny Grin (Karlson2k) <k2k@narod.ru>2017-03-02 11:24:34 +0300
committerEvgeny Grin (Karlson2k) <k2k@narod.ru>2017-03-10 20:00:11 +0300
commit26b63fcb861aaab53c5a16fe43e8830ab3a61a19 (patch)
tree5ab90942ed9d53c4cd51fb38c7ce1250362ec093
parentd946118778d04839f928886f4463d3f43f5b3568 (diff)
downloadlibmicrohttpd-26b63fcb861aaab53c5a16fe43e8830ab3a61a19.tar.gz
libmicrohttpd-26b63fcb861aaab53c5a16fe43e8830ab3a61a19.zip
process_urh(): Rearranged comments, fixed wrong "unready" mark.
-rw-r--r--src/microhttpd/daemon.c56
1 files changed, 32 insertions, 24 deletions
diff --git a/src/microhttpd/daemon.c b/src/microhttpd/daemon.c
index f93dbd21..0049b562 100644
--- a/src/microhttpd/daemon.c
+++ b/src/microhttpd/daemon.c
@@ -1191,10 +1191,12 @@ process_urh (struct MHD_UpgradeResponseHandle *urh)
1191#endif 1191#endif
1192 1192
1193 } 1193 }
1194 urh->in_buffer_size = 0; 1194 /* Discard any data received form remote. */
1195 urh->in_buffer_used = 0; 1195 urh->in_buffer_used = 0;
1196 /* Do not try to push data to application. */
1196 urh->mhd.celi &= ~MHD_EPOLL_STATE_WRITE_READY; 1197 urh->mhd.celi &= ~MHD_EPOLL_STATE_WRITE_READY;
1197 /* Reading from remote client is not required anymore. */ 1198 /* Reading from remote client is not required anymore. */
1199 urh->in_buffer_size = 0;
1198 urh->app.celi &= ~MHD_EPOLL_STATE_READ_READY; 1200 urh->app.celi &= ~MHD_EPOLL_STATE_READ_READY;
1199 connection->tls_read_ready = false; 1201 connection->tls_read_ready = false;
1200 } 1202 }
@@ -1229,8 +1231,7 @@ process_urh (struct MHD_UpgradeResponseHandle *urh)
1229 (GNUTLS_E_INTERRUPTED != res) ) 1231 (GNUTLS_E_INTERRUPTED != res) )
1230 { 1232 {
1231 /* Connection was shut down or got unrecoverable error. 1233 /* Connection was shut down or got unrecoverable error.
1232 * signal by shrinking buffer so no more attempts will be 1234 * Reading from remote client is not required anymore. */
1233 * performed to receive data. */
1234 urh->in_buffer_size = 0; 1235 urh->in_buffer_size = 0;
1235 urh->app.celi &= ~MHD_EPOLL_STATE_READ_READY; 1236 urh->app.celi &= ~MHD_EPOLL_STATE_READ_READY;
1236 } 1237 }
@@ -1248,7 +1249,7 @@ process_urh (struct MHD_UpgradeResponseHandle *urh)
1248 res = MHD_send_ (urh->mhd.socket, 1249 res = MHD_send_ (urh->mhd.socket,
1249 urh->in_buffer, 1250 urh->in_buffer,
1250 data_size); 1251 data_size);
1251 if (-1 == res) 1252 if (0 > res)
1252 { 1253 {
1253 int err = MHD_socket_get_error_ (); 1254 int err = MHD_socket_get_error_ ();
1254 1255
@@ -1258,9 +1259,7 @@ process_urh (struct MHD_UpgradeResponseHandle *urh)
1258 (! MHD_SCKT_ERR_IS_LOW_RESOURCES_(err)) ) 1259 (! MHD_SCKT_ERR_IS_LOW_RESOURCES_(err)) )
1259 { 1260 {
1260 /* persistent / unrecoverable error, treat as 1261 /* persistent / unrecoverable error, treat as
1261 if connection was shut down. 1262 if connection was shut down. */
1262 Do not try to receive to 'in_buffer' and
1263 discard any unsent data. */
1264#ifdef HAVE_MESSAGES 1263#ifdef HAVE_MESSAGES
1265 MHD_DLOG (daemon, 1264 MHD_DLOG (daemon,
1266 _("Failed to forward to application " MHD_UNSIGNED_LONG_LONG_PRINTF \ 1265 _("Failed to forward to application " MHD_UNSIGNED_LONG_LONG_PRINTF \
@@ -1268,9 +1267,12 @@ process_urh (struct MHD_UpgradeResponseHandle *urh)
1268 (MHD_UNSIGNED_LONG_LONG) urh->in_buffer_used, 1267 (MHD_UNSIGNED_LONG_LONG) urh->in_buffer_used,
1269 MHD_socket_strerr_ (err)); 1268 MHD_socket_strerr_ (err));
1270#endif 1269#endif
1271 urh->in_buffer_size = 0; 1270 /* Discard any data received form remote. */
1272 urh->in_buffer_used = 0; 1271 urh->in_buffer_used = 0;
1272 /* Do not try to push data to application. */
1273 urh->mhd.celi &= ~MHD_EPOLL_STATE_WRITE_READY; 1273 urh->mhd.celi &= ~MHD_EPOLL_STATE_WRITE_READY;
1274 /* Reading from remote client is not required anymore. */
1275 urh->in_buffer_size = 0;
1274 urh->app.celi &= ~MHD_EPOLL_STATE_READ_READY; 1276 urh->app.celi &= ~MHD_EPOLL_STATE_READ_READY;
1275 connection->tls_read_ready = false; 1277 connection->tls_read_ready = false;
1276 } 1278 }
@@ -1294,15 +1296,16 @@ process_urh (struct MHD_UpgradeResponseHandle *urh)
1294 } 1296 }
1295 1297
1296 /* handle reading from application and writing to HTTPS client */ 1298 /* handle reading from application and writing to HTTPS client */
1299
1300 /* If application signaled MHD about socket closure then
1301 * check for any pending data even if socket is not marked
1302 * as 'ready' (signal may arrive after poll()/select()).
1303 * Socketpair for forwarding is always in non-blocking mode
1304 * so no risk that recv() will block the thread. */
1297 if ( ( (0 != (MHD_EPOLL_STATE_READ_READY & urh->mhd.celi)) || 1305 if ( ( (0 != (MHD_EPOLL_STATE_READ_READY & urh->mhd.celi)) ||
1298 (urh->was_closed) ) && 1306 (urh->was_closed) ) &&
1299 (urh->out_buffer_used < urh->out_buffer_size) ) 1307 (urh->out_buffer_used < urh->out_buffer_size) )
1300 { 1308 {
1301 /* If application signaled MHD about socket closure then
1302 * check for any pending data even if socket is not marked
1303 * as 'ready' (signal may arrive after poll()/select()).
1304 * Socketpair for forwarding is always in non-blocking mode
1305 * so no risk that recv() will block the thread. */
1306 ssize_t res; 1309 ssize_t res;
1307 size_t buf_size; 1310 size_t buf_size;
1308 1311
@@ -1313,12 +1316,13 @@ process_urh (struct MHD_UpgradeResponseHandle *urh)
1313 res = MHD_recv_ (urh->mhd.socket, 1316 res = MHD_recv_ (urh->mhd.socket,
1314 &urh->out_buffer[urh->out_buffer_used], 1317 &urh->out_buffer[urh->out_buffer_used],
1315 buf_size); 1318 buf_size);
1316 if (-1 == res) 1319 if (0 > res)
1317 { 1320 {
1318 if (urh->was_closed) 1321 if (urh->was_closed)
1319 { 1322 {
1320 /* Connection was shut down or all data received and 1323 /* All data was received and application will not
1321 * application will not forward any more data. */ 1324 * forward any more data. */
1325 /* Do not try to pull data from application. */
1322 urh->out_buffer_size = 0; 1326 urh->out_buffer_size = 0;
1323 urh->mhd.celi &= ~MHD_EPOLL_STATE_READ_READY; 1327 urh->mhd.celi &= ~MHD_EPOLL_STATE_READ_READY;
1324 } 1328 }
@@ -1332,6 +1336,7 @@ process_urh (struct MHD_UpgradeResponseHandle *urh)
1332 { 1336 {
1333 /* persistent / unrecoverable error, treat as 1337 /* persistent / unrecoverable error, treat as
1334 if connection was shut down */ 1338 if connection was shut down */
1339 /* Do not try to pull data from application. */
1335 urh->out_buffer_size = 0; 1340 urh->out_buffer_size = 0;
1336 urh->mhd.celi &= ~MHD_EPOLL_STATE_READ_READY; 1341 urh->mhd.celi &= ~MHD_EPOLL_STATE_READ_READY;
1337 } 1342 }
@@ -1346,10 +1351,9 @@ process_urh (struct MHD_UpgradeResponseHandle *urh)
1346 if (0 == res) 1351 if (0 == res)
1347 { 1352 {
1348 /* Connection was shut down or got unrecoverable error. 1353 /* Connection was shut down or got unrecoverable error.
1349 * signal by shrinking buffer so no more attempts will be 1354 /* Do not try to pull data from application. */
1350 * performed to receive data. */
1351 urh->out_buffer_size = 0; 1355 urh->out_buffer_size = 0;
1352 urh->mhd.celi &= ~MHD_EPOLL_STATE_WRITE_READY; 1356 urh->mhd.celi &= ~MHD_EPOLL_STATE_READ_READY;
1353 } 1357 }
1354 } 1358 }
1355 if ( (0 != (MHD_EPOLL_STATE_WRITE_READY & urh->app.celi)) && 1359 if ( (0 != (MHD_EPOLL_STATE_WRITE_READY & urh->app.celi)) &&
@@ -1388,9 +1392,7 @@ process_urh (struct MHD_UpgradeResponseHandle *urh)
1388 else if (GNUTLS_E_INTERRUPTED != res) 1392 else if (GNUTLS_E_INTERRUPTED != res)
1389 { 1393 {
1390 /* persistent / unrecoverable error, treat as 1394 /* persistent / unrecoverable error, treat as
1391 if connection was shut down. 1395 if connection was shut down. */
1392 Do not try to receive to 'out_buffer' and
1393 discard any unsent data. */
1394#ifdef HAVE_MESSAGES 1396#ifdef HAVE_MESSAGES
1395 MHD_DLOG (daemon, 1397 MHD_DLOG (daemon,
1396 _("Failed to forward to remote client " MHD_UNSIGNED_LONG_LONG_PRINTF \ 1398 _("Failed to forward to remote client " MHD_UNSIGNED_LONG_LONG_PRINTF \
@@ -1398,9 +1400,12 @@ process_urh (struct MHD_UpgradeResponseHandle *urh)
1398 (MHD_UNSIGNED_LONG_LONG) urh->out_buffer_used, 1400 (MHD_UNSIGNED_LONG_LONG) urh->out_buffer_used,
1399 gnutls_strerror(res)); 1401 gnutls_strerror(res));
1400#endif 1402#endif
1401 urh->out_buffer_size = 0; 1403 /* Discard any data unsent to remote. */
1402 urh->out_buffer_used = 0; 1404 urh->out_buffer_used = 0;
1405 /* Do not try to sent to remote anymore. */
1403 urh->app.celi &= ~MHD_EPOLL_STATE_WRITE_READY; 1406 urh->app.celi &= ~MHD_EPOLL_STATE_WRITE_READY;
1407 /* Do not try to pull more data from application. */
1408 urh->out_buffer_size = 0;
1404 urh->mhd.celi &= ~MHD_EPOLL_STATE_READ_READY; 1409 urh->mhd.celi &= ~MHD_EPOLL_STATE_READ_READY;
1405 } 1410 }
1406 } 1411 }
@@ -1424,9 +1429,12 @@ process_urh (struct MHD_UpgradeResponseHandle *urh)
1424 " bytes of data received from application: daemon shut down\n"), 1429 " bytes of data received from application: daemon shut down\n"),
1425 (MHD_UNSIGNED_LONG_LONG) urh->out_buffer_used); 1430 (MHD_UNSIGNED_LONG_LONG) urh->out_buffer_used);
1426#endif 1431#endif
1427 urh->out_buffer_size = 0; 1432 /* Discard any data unsent to remote. */
1428 urh->out_buffer_used = 0; 1433 urh->out_buffer_used = 0;
1434 /* Do not try to sent to remote anymore. */
1429 urh->app.celi &= ~MHD_EPOLL_STATE_WRITE_READY; 1435 urh->app.celi &= ~MHD_EPOLL_STATE_WRITE_READY;
1436 /* Do not try to pull more data from application. */
1437 urh->out_buffer_size = 0;
1430 urh->mhd.celi &= ~MHD_EPOLL_STATE_READ_READY; 1438 urh->mhd.celi &= ~MHD_EPOLL_STATE_READ_READY;
1431 } 1439 }
1432} 1440}