aboutsummaryrefslogtreecommitdiff
path: root/src/microhttpd/mhd_send.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/microhttpd/mhd_send.c')
-rw-r--r--src/microhttpd/mhd_send.c61
1 files changed, 32 insertions, 29 deletions
diff --git a/src/microhttpd/mhd_send.c b/src/microhttpd/mhd_send.c
index 18328e7e..84c9c06e 100644
--- a/src/microhttpd/mhd_send.c
+++ b/src/microhttpd/mhd_send.c
@@ -125,7 +125,7 @@ iov_max_init_ (void)
125{ 125{
126 long res = sysconf (_SC_IOV_MAX); 126 long res = sysconf (_SC_IOV_MAX);
127 if (res >= 0) 127 if (res >= 0)
128 mhd_iov_max_ = res; 128 mhd_iov_max_ = (unsigned long) res;
129#if defined(IOV_MAX) 129#if defined(IOV_MAX)
130 else 130 else
131 mhd_iov_max_ = IOV_MAX; 131 mhd_iov_max_ = IOV_MAX;
@@ -1399,7 +1399,6 @@ send_iov_nontls (struct MHD_Connection *connection,
1399 bool push_data) 1399 bool push_data)
1400{ 1400{
1401 ssize_t res; 1401 ssize_t res;
1402 ssize_t total_sent;
1403 size_t items_to_send; 1402 size_t items_to_send;
1404#ifdef HAVE_SENDMSG 1403#ifdef HAVE_SENDMSG
1405 struct msghdr msg; 1404 struct msghdr msg;
@@ -1501,35 +1500,38 @@ send_iov_nontls (struct MHD_Connection *connection,
1501 } 1500 }
1502 1501
1503 /* Some data has been sent */ 1502 /* Some data has been sent */
1504 total_sent = res; 1503 if (1)
1505 /* Adjust the internal tracking information for the iovec to
1506 * take this last send into account. */
1507 while ((0 != res) && (r_iov->iov[r_iov->sent].iov_len <= (size_t) res))
1508 { 1504 {
1509 res -= r_iov->iov[r_iov->sent].iov_len; 1505 size_t track_sent = (size_t) res;
1510 r_iov->sent++; /* The iov element has been completely sent */ 1506 /* Adjust the internal tracking information for the iovec to
1511 mhd_assert ((r_iov->cnt > r_iov->sent) || (0 == res)); 1507 * take this last send into account. */
1512 } 1508 while ((0 != track_sent) && (r_iov->iov[r_iov->sent].iov_len <= track_sent))
1509 {
1510 track_sent -= r_iov->iov[r_iov->sent].iov_len;
1511 r_iov->sent++; /* The iov element has been completely sent */
1512 mhd_assert ((r_iov->cnt > r_iov->sent) || (0 == track_sent));
1513 }
1513 1514
1514 if (r_iov->cnt == r_iov->sent) 1515 if (r_iov->cnt == r_iov->sent)
1515 post_send_setopt (connection, true, push_data); 1516 post_send_setopt (connection, true, push_data);
1516 else 1517 else
1517 { 1518 {
1518#ifdef EPOLL_SUPPORT 1519#ifdef EPOLL_SUPPORT
1519 connection->epoll_state &= 1520 connection->epoll_state &=
1520 ~((enum MHD_EpollState) MHD_EPOLL_STATE_WRITE_READY); 1521 ~((enum MHD_EpollState) MHD_EPOLL_STATE_WRITE_READY);
1521#endif /* EPOLL_SUPPORT */ 1522#endif /* EPOLL_SUPPORT */
1522 if (0 != res) 1523 if (0 != track_sent)
1523 { 1524 {
1524 mhd_assert (r_iov->cnt > r_iov->sent); 1525 mhd_assert (r_iov->cnt > r_iov->sent);
1525 /* The last iov element has been partially sent */ 1526 /* The last iov element has been partially sent */
1526 r_iov->iov[r_iov->sent].iov_base = 1527 r_iov->iov[r_iov->sent].iov_base =
1527 (void *) ((uint8_t *) r_iov->iov[r_iov->sent].iov_base + (size_t) res); 1528 (void *) ((uint8_t *) r_iov->iov[r_iov->sent].iov_base + track_sent);
1528 r_iov->iov[r_iov->sent].iov_len -= (MHD_iov_size_) res; 1529 r_iov->iov[r_iov->sent].iov_len -= (MHD_iov_size_) track_sent;
1530 }
1529 } 1531 }
1530 } 1532 }
1531 1533
1532 return total_sent; 1534 return res;
1533} 1535}
1534 1536
1535 1537
@@ -1567,7 +1569,7 @@ send_iov_emu (struct MHD_Connection *connection,
1567 do 1569 do
1568 { 1570 {
1569 if ((size_t) SSIZE_MAX - total_sent < r_iov->iov[r_iov->sent].iov_len) 1571 if ((size_t) SSIZE_MAX - total_sent < r_iov->iov[r_iov->sent].iov_len)
1570 return total_sent; /* return value would overflow */ 1572 return (ssize_t) total_sent; /* return value would overflow */
1571 1573
1572 res = MHD_send_data_ (connection, 1574 res = MHD_send_data_ (connection,
1573 r_iov->iov[r_iov->sent].iov_base, 1575 r_iov->iov[r_iov->sent].iov_base,
@@ -1580,7 +1582,7 @@ send_iov_emu (struct MHD_Connection *connection,
1580 return res; /* Nothing was sent, return result as is */ 1582 return res; /* Nothing was sent, return result as is */
1581 1583
1582 if (MHD_ERR_AGAIN_ == res) 1584 if (MHD_ERR_AGAIN_ == res)
1583 return total_sent; /* Some data has been sent, return the amount */ 1585 return (ssize_t) total_sent; /* Return the amount of the sent data */
1584 1586
1585 return res; /* Any kind of a hard error */ 1587 return res; /* Any kind of a hard error */
1586 } 1588 }
@@ -1589,13 +1591,14 @@ send_iov_emu (struct MHD_Connection *connection,
1589 1591
1590 if (r_iov->iov[r_iov->sent].iov_len != (size_t) res) 1592 if (r_iov->iov[r_iov->sent].iov_len != (size_t) res)
1591 { 1593 {
1594 const size_t sent = (size_t) res;
1592 /* Incomplete buffer has been sent. 1595 /* Incomplete buffer has been sent.
1593 * Adjust buffer of the last element. */ 1596 * Adjust buffer of the last element. */
1594 r_iov->iov[r_iov->sent].iov_base = 1597 r_iov->iov[r_iov->sent].iov_base =
1595 (void *) ((uint8_t *) r_iov->iov[r_iov->sent].iov_base + (size_t) res); 1598 (void *) ((uint8_t *) r_iov->iov[r_iov->sent].iov_base + sent);
1596 r_iov->iov[r_iov->sent].iov_len -= res; 1599 r_iov->iov[r_iov->sent].iov_len -= sent;
1597 1600
1598 return total_sent; 1601 return (ssize_t) total_sent;
1599 } 1602 }
1600 /* The iov element has been completely sent */ 1603 /* The iov element has been completely sent */
1601 r_iov->sent++; 1604 r_iov->sent++;