diff --git a/include/frnetlib/SSLSocket.h b/include/frnetlib/SSLSocket.h index 27e6f2a..1c3f469 100644 --- a/include/frnetlib/SSLSocket.h +++ b/include/frnetlib/SSLSocket.h @@ -115,9 +115,6 @@ namespace fr std::unique_ptr ssl; mbedtls_ssl_config conf; uint32_t flags; - - std::mutex outbound_mutex; - std::mutex inbound_mutex; }; } diff --git a/include/frnetlib/Socket.h b/include/frnetlib/Socket.h index c825f3b..35c030a 100644 --- a/include/frnetlib/Socket.h +++ b/include/frnetlib/Socket.h @@ -6,6 +6,7 @@ #define FRNETLIB_SOCKET_H +#include #include "NetworkEncoding.h" #include "Packet.h" @@ -165,6 +166,9 @@ namespace fr bool is_blocking; bool is_connected; + std::mutex outbound_mutex; + std::mutex inbound_mutex; + #ifdef _WIN32 static WSADATA wsaData; static uint32_t instance_count; diff --git a/include/frnetlib/TcpSocket.h b/include/frnetlib/TcpSocket.h index 8797bb3..b5b9458 100644 --- a/include/frnetlib/TcpSocket.h +++ b/include/frnetlib/TcpSocket.h @@ -107,8 +107,6 @@ protected: std::string unprocessed_buffer; std::unique_ptr recv_buffer; int32_t socket_descriptor; - std::mutex outbound_mutex; - std::mutex inbound_mutex; }; } diff --git a/src/SSLSocket.cpp b/src/SSLSocket.cpp index 486eaf0..4d04322 100644 --- a/src/SSLSocket.cpp +++ b/src/SSLSocket.cpp @@ -40,7 +40,6 @@ namespace fr Socket::Status SSLSocket::send_raw(const char *data, size_t size) { - std::lock_guard guard(outbound_mutex); int error = 0; while((error = mbedtls_ssl_write(ssl.get(), (const unsigned char *)data, size)) <= 0) { @@ -55,8 +54,6 @@ namespace fr Socket::Status SSLSocket::receive_raw(void *data, size_t data_size, size_t &received) { - std::lock_guard guard(inbound_mutex); - int read = MBEDTLS_ERR_SSL_WANT_READ; received = 0; if(unprocessed_buffer.size() < data_size) diff --git a/src/Socket.cpp b/src/Socket.cpp index d92416e..04f6457 100644 --- a/src/Socket.cpp +++ b/src/Socket.cpp @@ -80,6 +80,7 @@ namespace fr ssize_t bytes_remaining = buffer_size; size_t bytes_read = 0; + std::lock_guard guard(inbound_mutex); while(bytes_remaining > 0) { size_t received = 0; diff --git a/src/TcpSocket.cpp b/src/TcpSocket.cpp index bf75320..e756e97 100644 --- a/src/TcpSocket.cpp +++ b/src/TcpSocket.cpp @@ -22,7 +22,6 @@ namespace fr Socket::Status TcpSocket::send_raw(const char *data, size_t size) { std::lock_guard guard(outbound_mutex); - size_t sent = 0; while(sent < size) { @@ -56,7 +55,6 @@ namespace fr Socket::Status TcpSocket::receive_raw(void *data, size_t buffer_size, size_t &received) { - std::lock_guard guard(inbound_mutex); received = 0; if(unprocessed_buffer.size() < buffer_size) {