diff options
Diffstat (limited to 'src/microhttpd/response.c')
-rw-r--r-- | src/microhttpd/response.c | 78 |
1 files changed, 63 insertions, 15 deletions
diff --git a/src/microhttpd/response.c b/src/microhttpd/response.c index 670be983..ca729765 100644 --- a/src/microhttpd/response.c +++ b/src/microhttpd/response.c | |||
@@ -605,7 +605,23 @@ MHD_upgrade_action (struct MHD_UpgradeResponseHandle *urh, | |||
605 | switch (action) | 605 | switch (action) |
606 | { | 606 | { |
607 | case MHD_UPGRADE_ACTION_CLOSE: | 607 | case MHD_UPGRADE_ACTION_CLOSE: |
608 | /* transition to special 'closed' state for start of cleanup */ | ||
609 | connection->state = MHD_CONNECTION_UPGRADE_CLOSED; | ||
608 | /* Application is done with this connection, tear it down! */ | 610 | /* Application is done with this connection, tear it down! */ |
611 | if (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION) ) | ||
612 | { | ||
613 | if (0 == (daemon->options & MHD_USE_SSL) ) | ||
614 | { | ||
615 | /* just need to signal the thread that we are done */ | ||
616 | MHD_semaphore_up (connection->upgrade_sem); | ||
617 | } | ||
618 | else | ||
619 | { | ||
620 | /* signal thread by shutdown() of 'app' socket */ | ||
621 | shutdown (urh->app.socket, SHUT_RDWR); | ||
622 | } | ||
623 | return MHD_YES; | ||
624 | } | ||
609 | #if HTTPS_SUPPORT | 625 | #if HTTPS_SUPPORT |
610 | if (0 != (daemon->options & MHD_USE_SSL) ) | 626 | if (0 != (daemon->options & MHD_USE_SSL) ) |
611 | { | 627 | { |
@@ -658,6 +674,9 @@ MHD_upgrade_action (struct MHD_UpgradeResponseHandle *urh, | |||
658 | case MHD_UPGRADE_ACTION_CORK: | 674 | case MHD_UPGRADE_ACTION_CORK: |
659 | /* FIXME: not implemented */ | 675 | /* FIXME: not implemented */ |
660 | return MHD_NO; | 676 | return MHD_NO; |
677 | case MHD_UPGRADE_ACTION_FLUSH: | ||
678 | /* FIXME: not implemented */ | ||
679 | return MHD_NO; | ||
661 | default: | 680 | default: |
662 | /* we don't understand this one */ | 681 | /* we don't understand this one */ |
663 | return MHD_NO; | 682 | return MHD_NO; |
@@ -784,11 +803,6 @@ MHD_response_execute_upgrade_ (struct MHD_Response *response, | |||
784 | rbo, | 803 | rbo, |
785 | urh->app.socket, | 804 | urh->app.socket, |
786 | urh); | 805 | urh); |
787 | /* As far as MHD is concerned, this connection is | ||
788 | suspended; it will be resumed once we are done | ||
789 | in the #MHD_upgrade_action() function */ | ||
790 | MHD_suspend_connection (connection); | ||
791 | |||
792 | /* Launch IO processing by the event loop */ | 806 | /* Launch IO processing by the event loop */ |
793 | if (0 != (daemon->options & MHD_USE_EPOLL)) | 807 | if (0 != (daemon->options & MHD_USE_EPOLL)) |
794 | { | 808 | { |
@@ -846,12 +860,25 @@ MHD_response_execute_upgrade_ (struct MHD_Response *response, | |||
846 | return MHD_NO; | 860 | return MHD_NO; |
847 | } | 861 | } |
848 | } | 862 | } |
849 | 863 | if (0 == (daemon->options & MHD_USE_THREAD_PER_CONNECTION) ) | |
850 | /* This takes care of most event loops: simply add to DLL */ | 864 | { |
851 | DLL_insert (daemon->urh_head, | 865 | /* As far as MHD's event loops are concerned, this connection |
852 | daemon->urh_tail, | 866 | is suspended; it will be resumed once we are done in the |
853 | urh); | 867 | #MHD_upgrade_action() function */ |
854 | /* FIXME: None of the above will not work (yet) for thread-per-connection processing */ | 868 | MHD_suspend_connection (connection); |
869 | /* This takes care of further processing for most event loops: | ||
870 | simply add to DLL for bi-direcitonal processing */ | ||
871 | DLL_insert (daemon->urh_head, | ||
872 | daemon->urh_tail, | ||
873 | urh); | ||
874 | } | ||
875 | else | ||
876 | { | ||
877 | /* Our caller will set 'connection->state' to | ||
878 | MHD_CONNECTION_UPGRADE, thereby triggering the main method | ||
879 | of the thread to switch to bi-directional forwarding. */ | ||
880 | connection->urh = urh; | ||
881 | } | ||
855 | return MHD_YES; | 882 | return MHD_YES; |
856 | } | 883 | } |
857 | urh->app.socket = MHD_INVALID_SOCKET; | 884 | urh->app.socket = MHD_INVALID_SOCKET; |
@@ -864,10 +891,31 @@ MHD_response_execute_upgrade_ (struct MHD_Response *response, | |||
864 | rbo, | 891 | rbo, |
865 | connection->socket_fd, | 892 | connection->socket_fd, |
866 | urh); | 893 | urh); |
867 | /* As far as MHD is concerned, this connection is | 894 | if (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION) ) |
868 | suspended; it will be resumed once we are done | 895 | { |
869 | in the #MHD_upgrade_action() function */ | 896 | /* Need to give the thread something to block on... */ |
870 | MHD_suspend_connection (connection); | 897 | connection->upgrade_sem = MHD_semaphore_create (0); |
898 | if (NULL == connection->upgrade_sem) | ||
899 | { | ||
900 | #ifdef HAVE_MESSAGES | ||
901 | MHD_DLOG (daemon, | ||
902 | "Failed to create semaphore for upgrade handling\n"); | ||
903 | #endif | ||
904 | MHD_connection_close_ (connection, | ||
905 | MHD_REQUEST_TERMINATED_WITH_ERROR); | ||
906 | return MHD_NO; | ||
907 | } | ||
908 | /* Our caller will set 'connection->state' to | ||
909 | MHD_CONNECTION_UPGRADE, thereby triggering the | ||
910 | main method of the thread to block on the semaphore. */ | ||
911 | } | ||
912 | else | ||
913 | { | ||
914 | /* As far as MHD's event loops are concerned, this connection is | ||
915 | suspended; it will be resumed once we are done in the | ||
916 | #MHD_upgrade_action() function */ | ||
917 | MHD_suspend_connection (connection); | ||
918 | } | ||
871 | return MHD_YES; | 919 | return MHD_YES; |
872 | } | 920 | } |
873 | 921 | ||