diff options
Diffstat (limited to 'src/microhttpd/daemon.c')
-rw-r--r-- | src/microhttpd/daemon.c | 90 |
1 files changed, 45 insertions, 45 deletions
diff --git a/src/microhttpd/daemon.c b/src/microhttpd/daemon.c index c33455ac..6aafffcd 100644 --- a/src/microhttpd/daemon.c +++ b/src/microhttpd/daemon.c | |||
@@ -1279,15 +1279,7 @@ process_urh (struct MHD_UpgradeResponseHandle *urh) | |||
1279 | res = gnutls_record_recv (connection->tls_session, | 1279 | res = gnutls_record_recv (connection->tls_session, |
1280 | &urh->in_buffer[urh->in_buffer_used], | 1280 | &urh->in_buffer[urh->in_buffer_used], |
1281 | buf_size); | 1281 | buf_size); |
1282 | if (0 < res) | 1282 | if (0 >= res) |
1283 | { | ||
1284 | urh->in_buffer_used += res; | ||
1285 | if (buf_size > (size_t)res) | ||
1286 | urh->app.celi &= ~MHD_EPOLL_STATE_READ_READY; | ||
1287 | else if (0 < gnutls_record_check_pending (connection->tls_session)) | ||
1288 | connection->tls_read_ready = true; | ||
1289 | } | ||
1290 | else /* 0 >= res */ | ||
1291 | { | 1283 | { |
1292 | if (GNUTLS_E_INTERRUPTED != res) | 1284 | if (GNUTLS_E_INTERRUPTED != res) |
1293 | { | 1285 | { |
@@ -1301,6 +1293,14 @@ process_urh (struct MHD_UpgradeResponseHandle *urh) | |||
1301 | } | 1293 | } |
1302 | } | 1294 | } |
1303 | } | 1295 | } |
1296 | else /* 0 < res */ | ||
1297 | { | ||
1298 | urh->in_buffer_used += res; | ||
1299 | if (buf_size > (size_t)res) | ||
1300 | urh->app.celi &= ~MHD_EPOLL_STATE_READ_READY; | ||
1301 | else if (0 < gnutls_record_check_pending (connection->tls_session)) | ||
1302 | connection->tls_read_ready = true; | ||
1303 | } | ||
1304 | if (MHD_EPOLL_STATE_ERROR == | 1304 | if (MHD_EPOLL_STATE_ERROR == |
1305 | ((MHD_EPOLL_STATE_ERROR | MHD_EPOLL_STATE_READ_READY) & urh->app.celi)) | 1305 | ((MHD_EPOLL_STATE_ERROR | MHD_EPOLL_STATE_READ_READY) & urh->app.celi)) |
1306 | { | 1306 | { |
@@ -1327,13 +1327,7 @@ process_urh (struct MHD_UpgradeResponseHandle *urh) | |||
1327 | res = MHD_recv_ (urh->mhd.socket, | 1327 | res = MHD_recv_ (urh->mhd.socket, |
1328 | &urh->out_buffer[urh->out_buffer_used], | 1328 | &urh->out_buffer[urh->out_buffer_used], |
1329 | buf_size); | 1329 | buf_size); |
1330 | if (0 < res) | 1330 | if (0 >= res) |
1331 | { | ||
1332 | urh->out_buffer_used += res; | ||
1333 | if (buf_size > (size_t)res) | ||
1334 | urh->mhd.celi &= ~MHD_EPOLL_STATE_READ_READY; | ||
1335 | } | ||
1336 | else /* 0 >= res */ | ||
1337 | { | 1331 | { |
1338 | const int err = MHD_socket_get_error_ (); | 1332 | const int err = MHD_socket_get_error_ (); |
1339 | if ((0 == res) || | 1333 | if ((0 == res) || |
@@ -1354,6 +1348,12 @@ process_urh (struct MHD_UpgradeResponseHandle *urh) | |||
1354 | } | 1348 | } |
1355 | } | 1349 | } |
1356 | } | 1350 | } |
1351 | else /* 0 < res */ | ||
1352 | { | ||
1353 | urh->out_buffer_used += res; | ||
1354 | if (buf_size > (size_t)res) | ||
1355 | urh->mhd.celi &= ~MHD_EPOLL_STATE_READ_READY; | ||
1356 | } | ||
1357 | if ( (0 == (MHD_EPOLL_STATE_READ_READY & urh->mhd.celi)) && | 1357 | if ( (0 == (MHD_EPOLL_STATE_READ_READY & urh->mhd.celi)) && |
1358 | ( (0 != (MHD_EPOLL_STATE_ERROR & urh->mhd.celi)) || | 1358 | ( (0 != (MHD_EPOLL_STATE_ERROR & urh->mhd.celi)) || |
1359 | (was_closed) ) ) | 1359 | (was_closed) ) ) |
@@ -1381,20 +1381,7 @@ process_urh (struct MHD_UpgradeResponseHandle *urh) | |||
1381 | res = gnutls_record_send (connection->tls_session, | 1381 | res = gnutls_record_send (connection->tls_session, |
1382 | urh->out_buffer, | 1382 | urh->out_buffer, |
1383 | data_size); | 1383 | data_size); |
1384 | if (0 < res) | 1384 | if (0 >= res) |
1385 | { | ||
1386 | const size_t next_out_buffer_used = urh->out_buffer_used - res; | ||
1387 | if (0 != next_out_buffer_used) | ||
1388 | { | ||
1389 | memmove (urh->out_buffer, | ||
1390 | &urh->out_buffer[res], | ||
1391 | next_out_buffer_used); | ||
1392 | if (data_size > (size_t)res) | ||
1393 | urh->app.celi &= ~MHD_EPOLL_STATE_WRITE_READY; | ||
1394 | } | ||
1395 | urh->out_buffer_used = next_out_buffer_used; | ||
1396 | } | ||
1397 | else /* 0 >= res */ | ||
1398 | { | 1385 | { |
1399 | if (GNUTLS_E_INTERRUPTED != res) | 1386 | if (GNUTLS_E_INTERRUPTED != res) |
1400 | { | 1387 | { |
@@ -1418,6 +1405,19 @@ process_urh (struct MHD_UpgradeResponseHandle *urh) | |||
1418 | } | 1405 | } |
1419 | } | 1406 | } |
1420 | } | 1407 | } |
1408 | else /* 0 < res */ | ||
1409 | { | ||
1410 | const size_t next_out_buffer_used = urh->out_buffer_used - res; | ||
1411 | if (0 != next_out_buffer_used) | ||
1412 | { | ||
1413 | memmove (urh->out_buffer, | ||
1414 | &urh->out_buffer[res], | ||
1415 | next_out_buffer_used); | ||
1416 | if (data_size > (size_t)res) | ||
1417 | urh->app.celi &= ~MHD_EPOLL_STATE_WRITE_READY; | ||
1418 | } | ||
1419 | urh->out_buffer_used = next_out_buffer_used; | ||
1420 | } | ||
1421 | if ( (0 == urh->out_buffer_used) && | 1421 | if ( (0 == urh->out_buffer_used) && |
1422 | (0 != (MHD_EPOLL_STATE_ERROR & urh->app.celi)) ) | 1422 | (0 != (MHD_EPOLL_STATE_ERROR & urh->app.celi)) ) |
1423 | { | 1423 | { |
@@ -1447,20 +1447,7 @@ process_urh (struct MHD_UpgradeResponseHandle *urh) | |||
1447 | res = MHD_send_ (urh->mhd.socket, | 1447 | res = MHD_send_ (urh->mhd.socket, |
1448 | urh->in_buffer, | 1448 | urh->in_buffer, |
1449 | data_size); | 1449 | data_size); |
1450 | if (0 < res) | 1450 | if (0 >= res) |
1451 | { | ||
1452 | const size_t next_in_buffer_used = urh->in_buffer_used - res; | ||
1453 | if (0 != next_in_buffer_used) | ||
1454 | { | ||
1455 | memmove (urh->in_buffer, | ||
1456 | &urh->in_buffer[res], | ||
1457 | next_in_buffer_used); | ||
1458 | if (data_size > (size_t)res) | ||
1459 | urh->mhd.celi &= ~MHD_EPOLL_STATE_WRITE_READY; | ||
1460 | } | ||
1461 | urh->in_buffer_used = next_in_buffer_used; | ||
1462 | } | ||
1463 | else /* 0 >= res */ | ||
1464 | { | 1451 | { |
1465 | const int err = MHD_socket_get_error_ (); | 1452 | const int err = MHD_socket_get_error_ (); |
1466 | if ( (! MHD_SCKT_ERR_IS_EINTR_ (err)) && | 1453 | if ( (! MHD_SCKT_ERR_IS_EINTR_ (err)) && |
@@ -1487,7 +1474,20 @@ process_urh (struct MHD_UpgradeResponseHandle *urh) | |||
1487 | } | 1474 | } |
1488 | } | 1475 | } |
1489 | } | 1476 | } |
1490 | if ( (0 !=urh->in_buffer_used) && | 1477 | else /* 0 < res */ |
1478 | { | ||
1479 | const size_t next_in_buffer_used = urh->in_buffer_used - res; | ||
1480 | if (0 != next_in_buffer_used) | ||
1481 | { | ||
1482 | memmove (urh->in_buffer, | ||
1483 | &urh->in_buffer[res], | ||
1484 | next_in_buffer_used); | ||
1485 | if (data_size > (size_t)res) | ||
1486 | urh->mhd.celi &= ~MHD_EPOLL_STATE_WRITE_READY; | ||
1487 | } | ||
1488 | urh->in_buffer_used = next_in_buffer_used; | ||
1489 | } | ||
1490 | if ( (0 == urh->in_buffer_used) && | ||
1491 | (0 != (MHD_EPOLL_STATE_ERROR & urh->mhd.celi)) ) | 1491 | (0 != (MHD_EPOLL_STATE_ERROR & urh->mhd.celi)) ) |
1492 | { | 1492 | { |
1493 | /* Do not try to push data to application. */ | 1493 | /* Do not try to push data to application. */ |