- Read data using one thread while writing data usingwith another thread.
- Allow only one client to be connected at a time.
- Automatically close the connection with the client and re-establish it if the connection is lost.
- Read data using one thread while writing data using another.
- Allow only one client to be connected at a time.
- Automatically close the connection with the client and re-establish it if the connection is lost.
- Read data using one thread while writing data with another thread.
- Allow only one client to be connected at a time.
- Automatically close the connection with the client and re-establish it if the connection is lost.
@Guntram Blohm said it's perfectly ok to read and write a socket from two threads at the same time.
However, m_socket_fd
is used by threads which both read and write it(i.e. TcpServer::send()
may be still called while the value of m_socket_fd
is modified after accept() sucessfully returns and TcpServer::close
may be called at the same time by either of the two threads without the mutex).
@Guntram Blohm said it's perfectly ok to read and write a socket from two threads at the same time.
However, m_socket_fd
is used by threads which both read and write it(i.e. TcpServer::send()
may be still called while the value of m_socket_fd
is modified after accept() sucessfully returns and TcpServer::close
may be called at the same time by either of the two threads without the mutex).
std::mutex
is used to protected the socket fd which is read/written by two threads. Is it a better way to achieve this goal without ASIO or other third party libraries?std::mutex
is used to protected the socket fd which is read/written by two threads. Is it a better way to achieve this goal without ASIO or other third party libraries?
std::mutex
is used to protected the socket fd which is read/written by two threads. Is it a better way to achieve this goal without ASIO or other third party libraries?
std::mutex
is used to protected the socket fd which is read/written by two threads. Is it a better way to achieve this goal without ASIO or other third party libraries?