diff options
author | Evgeny Grin (Karlson2k) <k2k@narod.ru> | 2017-03-15 18:15:02 +0300 |
---|---|---|
committer | Evgeny Grin (Karlson2k) <k2k@narod.ru> | 2017-03-15 18:20:29 +0300 |
commit | 4b6e4c630dc6027ee5046d3c558864d94c6758c7 (patch) | |
tree | 54baf9681cb94fb66d85abe1bef877afeb41831d | |
parent | b8c844ae6acfa03b0e3390e44b77714674ca83b6 (diff) | |
download | libmicrohttpd-4b6e4c630dc6027ee5046d3c558864d94c6758c7.tar.gz libmicrohttpd-4b6e4c630dc6027ee5046d3c558864d94c6758c7.zip |
upgraded connections: removed redundant states and checks and unified processing logic.
Fixed early close in TLS thread-per-connection mode.
-rw-r--r-- | src/microhttpd/connection.c | 6 | ||||
-rw-r--r-- | src/microhttpd/daemon.c | 24 | ||||
-rw-r--r-- | src/microhttpd/internal.h | 7 | ||||
-rw-r--r-- | src/microhttpd/response.c | 3 |
4 files changed, 8 insertions, 32 deletions
diff --git a/src/microhttpd/connection.c b/src/microhttpd/connection.c index f192a1bb..7380c662 100644 --- a/src/microhttpd/connection.c +++ b/src/microhttpd/connection.c | |||
@@ -2446,8 +2446,6 @@ MHD_connection_handle_read (struct MHD_Connection *connection) | |||
2446 | case MHD_CONNECTION_UPGRADE: | 2446 | case MHD_CONNECTION_UPGRADE: |
2447 | EXTRA_CHECK (0); | 2447 | EXTRA_CHECK (0); |
2448 | break; | 2448 | break; |
2449 | case MHD_CONNECTION_UPGRADE_CLOSED: | ||
2450 | break; | ||
2451 | #endif /* UPGRADE_SUPPORT */ | 2449 | #endif /* UPGRADE_SUPPORT */ |
2452 | default: | 2450 | default: |
2453 | /* shrink read buffer to how much is actually used */ | 2451 | /* shrink read buffer to how much is actually used */ |
@@ -2635,8 +2633,6 @@ MHD_connection_handle_write (struct MHD_Connection *connection) | |||
2635 | case MHD_CONNECTION_UPGRADE: | 2633 | case MHD_CONNECTION_UPGRADE: |
2636 | EXTRA_CHECK (0); | 2634 | EXTRA_CHECK (0); |
2637 | break; | 2635 | break; |
2638 | case MHD_CONNECTION_UPGRADE_CLOSED: | ||
2639 | break; | ||
2640 | #endif /* UPGRADE_SUPPORT */ | 2636 | #endif /* UPGRADE_SUPPORT */ |
2641 | default: | 2637 | default: |
2642 | EXTRA_CHECK (0); | 2638 | EXTRA_CHECK (0); |
@@ -3202,8 +3198,6 @@ MHD_connection_handle_idle (struct MHD_Connection *connection) | |||
3202 | #ifdef UPGRADE_SUPPORT | 3198 | #ifdef UPGRADE_SUPPORT |
3203 | case MHD_CONNECTION_UPGRADE: | 3199 | case MHD_CONNECTION_UPGRADE: |
3204 | return MHD_YES; /* keep open */ | 3200 | return MHD_YES; /* keep open */ |
3205 | case MHD_CONNECTION_UPGRADE_CLOSED: | ||
3206 | return MHD_YES; /* "Upgraded" connection should be closed in special way. */ | ||
3207 | #endif /* UPGRADE_SUPPORT */ | 3201 | #endif /* UPGRADE_SUPPORT */ |
3208 | default: | 3202 | default: |
3209 | EXTRA_CHECK (0); | 3203 | EXTRA_CHECK (0); |
diff --git a/src/microhttpd/daemon.c b/src/microhttpd/daemon.c index 6f0fe9f2..84d9afe3 100644 --- a/src/microhttpd/daemon.c +++ b/src/microhttpd/daemon.c | |||
@@ -1620,7 +1620,9 @@ thread_main_connection_upgrade (struct MHD_Connection *con) | |||
1620 | if ( (0 != (daemon->options & MHD_USE_TLS)) && | 1620 | if ( (0 != (daemon->options & MHD_USE_TLS)) && |
1621 | (0 == (daemon->options & MHD_USE_POLL))) | 1621 | (0 == (daemon->options & MHD_USE_POLL))) |
1622 | { | 1622 | { |
1623 | while ( (MHD_CONNECTION_UPGRADE == con->state) || | 1623 | while ( (0 != urh->in_buffer_size) || |
1624 | (0 != urh->out_buffer_size) || | ||
1625 | (0 != urh->in_buffer_used) || | ||
1624 | (0 != urh->out_buffer_used) ) | 1626 | (0 != urh->out_buffer_used) ) |
1625 | { | 1627 | { |
1626 | /* use select */ | 1628 | /* use select */ |
@@ -1690,11 +1692,6 @@ thread_main_connection_upgrade (struct MHD_Connection *con) | |||
1690 | &ws, | 1692 | &ws, |
1691 | &es); | 1693 | &es); |
1692 | process_urh (urh); | 1694 | process_urh (urh); |
1693 | if ( (0 == urh->in_buffer_size) && | ||
1694 | (0 == urh->out_buffer_size) && | ||
1695 | (0 == urh->in_buffer_used) && | ||
1696 | (0 == urh->out_buffer_used) ) | ||
1697 | break; /* connections died, we have no more purpose here */ | ||
1698 | } | 1695 | } |
1699 | } | 1696 | } |
1700 | #ifdef HAVE_POLL | 1697 | #ifdef HAVE_POLL |
@@ -1708,7 +1705,9 @@ thread_main_connection_upgrade (struct MHD_Connection *con) | |||
1708 | p[0].fd = urh->connection->socket_fd; | 1705 | p[0].fd = urh->connection->socket_fd; |
1709 | p[1].fd = urh->mhd.socket; | 1706 | p[1].fd = urh->mhd.socket; |
1710 | 1707 | ||
1711 | while ( (MHD_CONNECTION_UPGRADE == con->state) || | 1708 | while ( (0 != urh->in_buffer_size) || |
1709 | (0 != urh->out_buffer_size) || | ||
1710 | (0 != urh->in_buffer_used) || | ||
1712 | (0 != urh->out_buffer_used) ) | 1711 | (0 != urh->out_buffer_used) ) |
1713 | { | 1712 | { |
1714 | int timeout; | 1713 | int timeout; |
@@ -1738,11 +1737,6 @@ thread_main_connection_upgrade (struct MHD_Connection *con) | |||
1738 | } | 1737 | } |
1739 | urh_from_pollfd(urh, p); | 1738 | urh_from_pollfd(urh, p); |
1740 | process_urh (urh); | 1739 | process_urh (urh); |
1741 | if ( (0 == urh->in_buffer_size) && | ||
1742 | (0 == urh->out_buffer_size) && | ||
1743 | (0 == urh->in_buffer_used) && | ||
1744 | (0 == urh->out_buffer_used) ) | ||
1745 | break; /* connections died, we have no more purpose here */ | ||
1746 | } | 1740 | } |
1747 | } | 1741 | } |
1748 | /* end POLL */ | 1742 | /* end POLL */ |
@@ -2070,11 +2064,7 @@ thread_main_handle_connection (void *data) | |||
2070 | } | 2064 | } |
2071 | #endif | 2065 | #endif |
2072 | #ifdef UPGRADE_SUPPORT | 2066 | #ifdef UPGRADE_SUPPORT |
2073 | /* Check for 'MHD_CONNECTION_UPGRADE_CLOSED' too: | 2067 | if (MHD_CONNECTION_UPGRADE == con->state) |
2074 | * application can finish with "upgraded" connection | ||
2075 | * before this thread process it for the first time. */ | ||
2076 | if ( (MHD_CONNECTION_UPGRADE == con->state) || | ||
2077 | (MHD_CONNECTION_UPGRADE_CLOSED == con->state) ) | ||
2078 | { | 2068 | { |
2079 | /* Normal HTTP processing is finished, | 2069 | /* Normal HTTP processing is finished, |
2080 | * notify application. */ | 2070 | * notify application. */ |
diff --git a/src/microhttpd/internal.h b/src/microhttpd/internal.h index 62c60a31..f9172372 100644 --- a/src/microhttpd/internal.h +++ b/src/microhttpd/internal.h | |||
@@ -514,13 +514,6 @@ enum MHD_CONNECTION_STATE | |||
514 | * control of the application. | 514 | * control of the application. |
515 | */ | 515 | */ |
516 | MHD_CONNECTION_UPGRADE = MHD_TLS_CONNECTION_INIT + 1, | 516 | MHD_CONNECTION_UPGRADE = MHD_TLS_CONNECTION_INIT + 1, |
517 | |||
518 | /** | ||
519 | * Connection was "upgraded" and subsequently closed | ||
520 | * by the application. We now need to do our own | ||
521 | * internal cleanup. | ||
522 | */ | ||
523 | MHD_CONNECTION_UPGRADE_CLOSED = MHD_CONNECTION_UPGRADE + 1 | ||
524 | #endif /* UPGRADE_SUPPORT */ | 517 | #endif /* UPGRADE_SUPPORT */ |
525 | 518 | ||
526 | }; | 519 | }; |
diff --git a/src/microhttpd/response.c b/src/microhttpd/response.c index 26ad649b..9004013f 100644 --- a/src/microhttpd/response.c +++ b/src/microhttpd/response.c | |||
@@ -678,9 +678,8 @@ MHD_upgrade_action (struct MHD_UpgradeResponseHandle *urh, | |||
678 | SHUT_RDWR); | 678 | SHUT_RDWR); |
679 | } | 679 | } |
680 | #endif /* HTTPS_SUPPORT */ | 680 | #endif /* HTTPS_SUPPORT */ |
681 | urh->was_closed = true; | ||
682 | EXTRA_CHECK (MHD_CONNECTION_UPGRADE == connection->state); | 681 | EXTRA_CHECK (MHD_CONNECTION_UPGRADE == connection->state); |
683 | connection->state = MHD_CONNECTION_UPGRADE_CLOSED; | 682 | urh->was_closed = true; |
684 | /* As soon as connection will be marked with BOTH | 683 | /* As soon as connection will be marked with BOTH |
685 | * 'urh->was_closed' AND 'urh->clean_ready', it will | 684 | * 'urh->was_closed' AND 'urh->clean_ready', it will |
686 | * be moved to cleanup list by MHD_resume_connection(). */ | 685 | * be moved to cleanup list by MHD_resume_connection(). */ |