diff options
Diffstat (limited to 'src/microhttpd/response.c')
-rw-r--r-- | src/microhttpd/response.c | 38 |
1 files changed, 37 insertions, 1 deletions
diff --git a/src/microhttpd/response.c b/src/microhttpd/response.c index 5b67b983..e778ed7f 100644 --- a/src/microhttpd/response.c +++ b/src/microhttpd/response.c | |||
@@ -32,6 +32,8 @@ | |||
32 | #include "mhd_sockets.h" | 32 | #include "mhd_sockets.h" |
33 | #include "mhd_itc.h" | 33 | #include "mhd_itc.h" |
34 | #include "connection.h" | 34 | #include "connection.h" |
35 | #include "memorypool.h" | ||
36 | |||
35 | 37 | ||
36 | #if defined(_WIN32) && defined(MHD_W32_MUTEX_) | 38 | #if defined(_WIN32) && defined(MHD_W32_MUTEX_) |
37 | #ifndef WIN32_LEAN_AND_MEAN | 39 | #ifndef WIN32_LEAN_AND_MEAN |
@@ -667,12 +669,19 @@ MHD_response_execute_upgrade_ (struct MHD_Response *response, | |||
667 | urh = malloc (sizeof (struct MHD_UpgradeResponseHandle)); | 669 | urh = malloc (sizeof (struct MHD_UpgradeResponseHandle)); |
668 | if (NULL == urh) | 670 | if (NULL == urh) |
669 | return MHD_NO; | 671 | return MHD_NO; |
672 | memset (urh, | ||
673 | 0, | ||
674 | sizeof (struct MHD_UpgradeResponseHandle)); | ||
670 | urh->connection = connection; | 675 | urh->connection = connection; |
671 | rbo = connection->read_buffer_offset; | 676 | rbo = connection->read_buffer_offset; |
672 | connection->read_buffer_offset = 0; | 677 | connection->read_buffer_offset = 0; |
673 | #if HTTPS_SUPPORT | 678 | #if HTTPS_SUPPORT |
674 | if (0 != (daemon->options & MHD_USE_SSL) ) | 679 | if (0 != (daemon->options & MHD_USE_SSL) ) |
675 | { | 680 | { |
681 | struct MemoryPool *pool; | ||
682 | size_t avail; | ||
683 | char *buf; | ||
684 | |||
676 | /* FIXME: this is non-portable for now; W32 port pending... */ | 685 | /* FIXME: this is non-portable for now; W32 port pending... */ |
677 | if (0 != socketpair (AF_UNIX, | 686 | if (0 != socketpair (AF_UNIX, |
678 | SOCK_STREAM, | 687 | SOCK_STREAM, |
@@ -698,9 +707,34 @@ MHD_response_execute_upgrade_ (struct MHD_Response *response, | |||
698 | free (urh); | 707 | free (urh); |
699 | return MHD_NO; | 708 | return MHD_NO; |
700 | } | 709 | } |
701 | |||
702 | urh->app_socket = sv[0]; | 710 | urh->app_socket = sv[0]; |
703 | urh->mhd_socket = sv[1]; | 711 | urh->mhd_socket = sv[1]; |
712 | pool = connection->pool; | ||
713 | avail = MHD_pool_get_free (pool); | ||
714 | if (avail < 8) | ||
715 | { | ||
716 | /* connection's pool is totally at the limit, | ||
717 | use our 'emergency' buffer of #RESERVE_EBUF_SIZE bytes. */ | ||
718 | avail = RESERVE_EBUF_SIZE; | ||
719 | buf = urh->e_buf; | ||
720 | } | ||
721 | else | ||
722 | { | ||
723 | /* Normal case: grab all remaining memory from the | ||
724 | connection's pool for the IO buffers; the connection | ||
725 | certainly won't need it anymore as we've upgraded | ||
726 | to another protocol. */ | ||
727 | buf = MHD_pool_allocate (pool, | ||
728 | avail, | ||
729 | MHD_NO); | ||
730 | } | ||
731 | /* use half the buffer for inbound, half for outbound */ | ||
732 | avail /= 2; | ||
733 | urh->in_buffer_size = avail; | ||
734 | urh->out_buffer_size = avail; | ||
735 | urh->in_buffer = buf; | ||
736 | urh->out_buffer = &buf[avail]; | ||
737 | /* hand over internal socket to application */ | ||
704 | response->upgrade_handler (response->upgrade_handler_cls, | 738 | response->upgrade_handler (response->upgrade_handler_cls, |
705 | connection, | 739 | connection, |
706 | connection->client_context, | 740 | connection->client_context, |
@@ -717,6 +751,8 @@ MHD_response_execute_upgrade_ (struct MHD_Response *response, | |||
717 | /* FIXME: is it possible we did not fully drain the client | 751 | /* FIXME: is it possible we did not fully drain the client |
718 | socket yet and are thus read-ready already? This may | 752 | socket yet and are thus read-ready already? This may |
719 | matter if we are in epoll() edge triggered mode... */ | 753 | matter if we are in epoll() edge triggered mode... */ |
754 | /* Launch IO processing by the event loop */ | ||
755 | /* FIXME: this will not work (yet) for thread-per-connection processing */ | ||
720 | DLL_insert (connection->daemon->urh_head, | 756 | DLL_insert (connection->daemon->urh_head, |
721 | connection->daemon->urh_tail, | 757 | connection->daemon->urh_tail, |
722 | urh); | 758 | urh); |