Skip to main content
Code Review

Return to Question

Notice removed Canonical answer required by Community Bot
Bounty Ended with no winning answer by Community Bot
added 6 characters in body
Source Link
John
  • 469
  • 2
  • 18
  1. Read data using one thread while writing data usingwith another thread.
  2. Allow only one client to be connected at a time.
  3. Automatically close the connection with the client and re-establish it if the connection is lost.
  1. Read data using one thread while writing data using another.
  2. Allow only one client to be connected at a time.
  3. Automatically close the connection with the client and re-establish it if the connection is lost.
  1. Read data using one thread while writing data with another thread.
  2. Allow only one client to be connected at a time.
  3. Automatically close the connection with the client and re-establish it if the connection is lost.
Notice added Canonical answer required by John
Bounty Started worth 50 reputation by John
added 406 characters in body
Source Link
John
  • 469
  • 2
  • 18

@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).

Became Hot Network Question
added 6 characters in body
Source Link
John
  • 469
  • 2
  • 18

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?

added 142 characters in body
Source Link
John
  • 469
  • 2
  • 18
Loading
added 2 characters in body
Source Link
Madagascar
  • 10.1k
  • 1
  • 15
  • 51
Loading
Source Link
John
  • 469
  • 2
  • 18
Loading
lang-cpp

AltStyle によって変換されたページ (->オリジナル) /