| 61 | } |
| 62 | |
| 63 | size_t TcpSocket::receive(char* data, size_t size) { |
| 64 | ReadLocker locker(m_mutex); |
| 65 | checkOpen("TcpSocket::receive"); |
| 66 | |
| 67 | if (m_socketMode == SocketMode::Closed) |
| 68 | throw SocketClosedException("TcpSocket not open in TcpSocket::receive"); |
| 69 | |
| 70 | int flags = 0; |
| 71 | #ifdef STAR_SYSTEM_LINUX |
| 72 | // Don't generate sigpipe |
| 73 | flags |= MSG_NOSIGNAL; |
| 74 | #endif |
| 75 | |
| 76 | auto r = ::recv(m_impl->socketDesc, data, size, flags); |
| 77 | if (r < 0) { |
| 78 | if (m_socketMode == SocketMode::Shutdown) { |
| 79 | throw SocketClosedException("Connection closed"); |
| 80 | } else if (netErrorConnectionReset()) { |
| 81 | doShutdown(); |
| 82 | throw SocketClosedException("Connection reset"); |
| 83 | } else if (netErrorInterrupt()) { |
| 84 | r = 0; |
| 85 | } else { |
| 86 | throw NetworkException(strf("tcp recv error: {}", netErrorString())); |
| 87 | } |
| 88 | } |
| 89 | |
| 90 | return r; |
| 91 | } |
| 92 | |
| 93 | size_t TcpSocket::send(char const* data, size_t size) { |
| 94 | ReadLocker locker(m_mutex); |
nothing calls this directly
no test coverage detected