diff options
Diffstat (limited to 'src/microhttpd/connection.c')
-rw-r--r-- | src/microhttpd/connection.c | 61 |
1 files changed, 60 insertions, 1 deletions
diff --git a/src/microhttpd/connection.c b/src/microhttpd/connection.c index 52b67b05..d3ccdf26 100644 --- a/src/microhttpd/connection.c +++ b/src/microhttpd/connection.c | |||
@@ -22,6 +22,7 @@ | |||
22 | * @brief Methods for managing connections | 22 | * @brief Methods for managing connections |
23 | * @author Daniel Pittman | 23 | * @author Daniel Pittman |
24 | * @author Christian Grothoff | 24 | * @author Christian Grothoff |
25 | * @author Karlson2k (Evgeny Grin) | ||
25 | */ | 26 | */ |
26 | 27 | ||
27 | #include "internal.h" | 28 | #include "internal.h" |
@@ -527,6 +528,63 @@ MHD_connection_close_ (struct MHD_Connection *connection, | |||
527 | 528 | ||
528 | 529 | ||
529 | /** | 530 | /** |
531 | * Stop TLS forwarding on upgraded connection and | ||
532 | * reflect remote disconnect state to socketpair. | ||
533 | * @remark In thread-per-connection mode this function | ||
534 | * can be called from any thread, in other modes this | ||
535 | * function must be called only from thread that process | ||
536 | * daemon's select()/poll()/etc. | ||
537 | * | ||
538 | * @param connection the upgraded connection | ||
539 | */ | ||
540 | void | ||
541 | MHD_connection_finish_forward_ (struct MHD_Connection *connection) | ||
542 | { | ||
543 | struct MHD_Daemon *daemon = connection->daemon; | ||
544 | struct MHD_UpgradeResponseHandle *urh = connection->urh; | ||
545 | |||
546 | if (0 == (daemon->options & MHD_USE_TLS)) | ||
547 | return; /* Nothing to do with non-TLS connection. */ | ||
548 | |||
549 | if (0 == (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) | ||
550 | DLL_remove (daemon->urh_head, | ||
551 | daemon->urh_tail, | ||
552 | urh); | ||
553 | #if EPOLL_SUPPORT | ||
554 | if ( (0 != (daemon->options & MHD_USE_EPOLL)) && | ||
555 | (0 != epoll_ctl (daemon->epoll_upgrade_fd, | ||
556 | EPOLL_CTL_DEL, | ||
557 | connection->socket_fd, | ||
558 | NULL)) ) | ||
559 | { | ||
560 | MHD_PANIC (_("Failed to remove FD from epoll set\n")); | ||
561 | } | ||
562 | #endif /* EPOLL_SUPPORT */ | ||
563 | if (MHD_INVALID_SOCKET != urh->mhd.socket) | ||
564 | { | ||
565 | #if EPOLL_SUPPORT | ||
566 | if ( (0 != (daemon->options & MHD_USE_EPOLL)) && | ||
567 | (0 != epoll_ctl (daemon->epoll_upgrade_fd, | ||
568 | EPOLL_CTL_DEL, | ||
569 | urh->mhd.socket, | ||
570 | NULL)) ) | ||
571 | { | ||
572 | MHD_PANIC (_("Failed to remove FD from epoll set\n")); | ||
573 | } | ||
574 | #endif /* EPOLL_SUPPORT */ | ||
575 | /* Reflect remote disconnect to application by breaking | ||
576 | * socketpair connection. */ | ||
577 | shutdown (urh->mhd.socket, SHUT_RDWR); | ||
578 | } | ||
579 | /* Socketpair sockets will remain open as they will be | ||
580 | * used with MHD_UPGRADE_ACTION_CLOSE. They will be | ||
581 | * closed by MHD_cleanup_upgraded_connection_() during | ||
582 | * connection's final cleanup. | ||
583 | */ | ||
584 | } | ||
585 | |||
586 | |||
587 | /** | ||
530 | * A serious error occured, close the | 588 | * A serious error occured, close the |
531 | * connection (and notify the application). | 589 | * connection (and notify the application). |
532 | * | 590 | * |
@@ -3080,8 +3138,9 @@ MHD_connection_handle_idle (struct MHD_Connection *connection) | |||
3080 | cleanup_connection (connection); | 3138 | cleanup_connection (connection); |
3081 | return MHD_NO; | 3139 | return MHD_NO; |
3082 | case MHD_CONNECTION_UPGRADE: | 3140 | case MHD_CONNECTION_UPGRADE: |
3083 | case MHD_CONNECTION_UPGRADE_CLOSED: | ||
3084 | return MHD_YES; /* keep open */ | 3141 | return MHD_YES; /* keep open */ |
3142 | case MHD_CONNECTION_UPGRADE_CLOSED: | ||
3143 | return MHD_YES; /* "Upgraded" connection should be closed in special way. */ | ||
3085 | default: | 3144 | default: |
3086 | EXTRA_CHECK (0); | 3145 | EXTRA_CHECK (0); |
3087 | break; | 3146 | break; |