|
4 | 4 | ** Author Francois Michaut
|
5 | 5 | **
|
6 | 6 | ** Started on Wed Sep 14 21:04:42 2022 Francois Michaut
|
7 |
| -** Last update Wed Aug 20 23:12:24 2025 Francois Michaut |
| 7 | +** Last update Fri Aug 22 21:57:23 2025 Francois Michaut |
8 | 8 | **
|
9 | 9 | ** SecureSocket.cpp : TLS socket wrapper implementation
|
10 | 10 | */
|
@@ -77,36 +77,45 @@ namespace CppSockets {
|
77 | 77 |
|
78 | 78 | TlsSocket::~TlsSocket() noexcept {
|
79 | 79 | if (m_ssl && this->connected()) {
|
80 |
| - int ret = SSL_shutdown(m_ssl.get()); // TODO: log failure |
81 |
| - |
82 |
| - if (ret == 0) { |
83 |
| - try { |
84 |
| - while (this->connected()) { |
85 |
| - this->read(); |
86 |
| - } |
87 |
| - } catch (std::runtime_error &e) { |
88 |
| - // TODO: What ? |
89 |
| - } |
90 |
| - SSL_shutdown(m_ssl.get()); // TODO: log failure |
91 |
| - } |
| 80 | + // TODO: Better shutdown mecanics |
| 81 | + int ret = SSL_shutdown(m_ssl.get()); |
| 82 | + |
| 83 | + // if (ret == 1) { |
| 84 | + // // Peer also closed -> We can leave. |
| 85 | + // } else if (ret == 0) { |
| 86 | + // // Peer didn't send, but we can't wait in the Destructor |
| 87 | + // } else { |
| 88 | + // // TODO: log failure |
| 89 | + // } |
92 | 90 | }
|
93 | 91 | }
|
94 | 92 |
|
95 |
| - TlsSocket::TlsSocket(TlsSocket &&other) noexcept : |
96 |
| - Socket(std::move(other)), m_ctx(std::move(other.m_ctx)), |
97 |
| - m_ssl(std::move(other.m_ssl)), m_peer_cert(std::move(other.m_peer_cert)) |
98 |
| - {} |
| 93 | + TlsSocket::TlsSocket(TlsSocket &&other) noexcept { |
| 94 | + *this = std::move(other); |
| 95 | + } |
99 | 96 |
|
100 | 97 | auto TlsSocket::operator=(TlsSocket &&other) noexcept -> TlsSocket & {
|
101 |
| - std::swap(m_ssl, other.m_ssl); |
102 |
| - |
| 98 | + m_ssl = std::move(other.m_ssl); |
103 | 99 | m_ctx = std::move(other.m_ctx);
|
104 | 100 | m_peer_cert = std::move(other.m_peer_cert);
|
105 | 101 |
|
106 | 102 | Socket::operator=(std::move(other));
|
107 | 103 | return *this;
|
108 | 104 | }
|
109 | 105 |
|
| 106 | + void TlsSocket::close() { |
| 107 | + int ret = SSL_shutdown(m_ssl.get()); |
| 108 | + |
| 109 | + if (ret == 1) { |
| 110 | + return Socket::close(); |
| 111 | + } |
| 112 | + // if (ret == 0) { |
| 113 | + // // TODO: wait for peer |
| 114 | + // } else { |
| 115 | + // // TODO: Log failure |
| 116 | + // } |
| 117 | + } |
| 118 | + |
110 | 119 | void TlsSocket::set_verify(int mode, SSL_verify_cb verify_callback) {
|
111 | 120 | // TODO: While setting it on the CTX makes sense imo (since accepted sockets will inherit this), an application
|
112 | 121 | // might not want that behavior. Need to provide alertnate ways to set verify on CTX vs SSL
|
|
0 commit comments