eidheim / Simple-Web-Server

A very simple, fast, multithreaded, platform independent HTTP and HTTPS server and client library implemented using C++11 and Boost.Asio. Created to be an easy way to make REST resources available from C++ applications.
MIT License
2.61k stars 751 forks source link

glaceful close ssl socket #207

Open lxlenovostar opened 6 years ago

lxlenovostar commented 6 years ago

Hi: @eidheim

    void close() noexcept {
        error_code ec;
        std::unique_lock<std::mutex> lock(socket_close_mutex); // The following operations seems to be needed to run sequentially
        socket->lowest_layer().shutdown(asio::ip::tcp::socket::shutdown_both, ec);
        socket->lowest_layer().close(ec);
      }

In this way, we directly close tcp socket, why we not close SSL socket first in HTTPS server?

Thank you.

eidheim commented 6 years ago

Last time I studied this I came to the conclusion that calling ssl::stream::shutdown was not needed. Though I might be wrong! By the way, ssl::stream does not have a close-member function.

eidheim commented 6 years ago

Although, thank you for bringing this up. I'll add a couple of labels to this issue.

lxlenovostar commented 6 years ago

@eidheim In a rare case, If I don't add mutex before shutdown/close, SIGSEGV happen. Why you choose use mutex before shutdown/close?