aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEvgeny Grin (Karlson2k) <k2k@narod.ru>2016-10-24 19:43:22 +0300
committerEvgeny Grin (Karlson2k) <k2k@narod.ru>2016-10-27 22:45:00 +0300
commit55bc012c93d89944f8138ef0c5914c229aa13987 (patch)
treed60bb978d5dadb90dcf995ea2a05af952eb2620a
parentd528519166ae590ec3cc6b7d7dabb3e19616ff00 (diff)
downloadlibmicrohttpd-55bc012c93d89944f8138ef0c5914c229aa13987.tar.gz
libmicrohttpd-55bc012c93d89944f8138ef0c5914c229aa13987.zip
MHD_response_execute_upgrade_(): deduplicate code.
-rw-r--r--src/microhttpd/response.c34
1 files changed, 11 insertions, 23 deletions
diff --git a/src/microhttpd/response.c b/src/microhttpd/response.c
index 3ab5447f..b0fffe19 100644
--- a/src/microhttpd/response.c
+++ b/src/microhttpd/response.c
@@ -843,14 +843,6 @@ MHD_response_execute_upgrade_ (struct MHD_Response *response,
843 urh->out_buffer_size = avail - urh->in_buffer_size; 843 urh->out_buffer_size = avail - urh->in_buffer_size;
844 urh->in_buffer = buf; 844 urh->in_buffer = buf;
845 urh->out_buffer = &buf[urh->in_buffer_size]; 845 urh->out_buffer = &buf[urh->in_buffer_size];
846 /* hand over internal socket to application */
847 response->upgrade_handler (response->upgrade_handler_cls,
848 connection,
849 connection->client_context,
850 connection->read_buffer,
851 rbo,
852 urh->app.socket,
853 urh);
854#ifdef EPOLL_SUPPORT 846#ifdef EPOLL_SUPPORT
855 /* Launch IO processing by the event loop */ 847 /* Launch IO processing by the event loop */
856 if (0 != (daemon->options & MHD_USE_EPOLL)) 848 if (0 != (daemon->options & MHD_USE_EPOLL))
@@ -908,10 +900,6 @@ MHD_response_execute_upgrade_ (struct MHD_Response *response,
908#endif /* EPOLL_SUPPORT */ 900#endif /* EPOLL_SUPPORT */
909 if (0 == (daemon->options & MHD_USE_THREAD_PER_CONNECTION) ) 901 if (0 == (daemon->options & MHD_USE_THREAD_PER_CONNECTION) )
910 { 902 {
911 /* As far as MHD's event loops are concerned, this connection
912 is suspended; it will be resumed once we are done in the
913 #MHD_upgrade_action() function */
914 MHD_suspend_connection (connection);
915 /* This takes care of further processing for most event loops: 903 /* This takes care of further processing for most event loops:
916 simply add to DLL for bi-direcitonal processing */ 904 simply add to DLL for bi-direcitonal processing */
917 DLL_insert (daemon->urh_head, 905 DLL_insert (daemon->urh_head,
@@ -920,20 +908,18 @@ MHD_response_execute_upgrade_ (struct MHD_Response *response,
920 /* Keep reference for later removal from the DLL */ 908 /* Keep reference for later removal from the DLL */
921 connection->urh = urh; 909 connection->urh = urh;
922 } 910 }
923 else
924 {
925 /* Our caller will set 'connection->state' to
926 MHD_CONNECTION_UPGRADE, thereby triggering the main method
927 of the thread to switch to bi-directional forwarding. */
928 connection->urh = urh;
929 }
930 return MHD_YES;
931 } 911 }
932 urh->app.socket = MHD_INVALID_SOCKET; 912 else
933 urh->mhd.socket = MHD_INVALID_SOCKET; 913 {
914 urh->app.socket = MHD_INVALID_SOCKET;
915 urh->mhd.socket = MHD_INVALID_SOCKET;
916 }
934#endif 917#endif
935 if (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION) ) 918 if (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION) )
936 { 919 {
920 /* Our caller will set 'connection->state' to
921 MHD_CONNECTION_UPGRADE, thereby triggering the main method
922 of the thread to switch to bi-directional forwarding or exit. */
937 connection->urh = urh; 923 connection->urh = urh;
938 } 924 }
939 else 925 else
@@ -943,12 +929,14 @@ MHD_response_execute_upgrade_ (struct MHD_Response *response,
943 #MHD_upgrade_action() function */ 929 #MHD_upgrade_action() function */
944 MHD_suspend_connection (connection); 930 MHD_suspend_connection (connection);
945 } 931 }
932 /* hand over socket to application */
946 response->upgrade_handler (response->upgrade_handler_cls, 933 response->upgrade_handler (response->upgrade_handler_cls,
947 connection, 934 connection,
948 connection->client_context, 935 connection->client_context,
949 connection->read_buffer, 936 connection->read_buffer,
950 rbo, 937 rbo,
951 connection->socket_fd, 938 (0 == (daemon->options & MHD_USE_TLS) ) ?
939 connection->socket_fd : urh->app.socket,
952 urh); 940 urh);
953 return MHD_YES; 941 return MHD_YES;
954} 942}