Writes as many bytes as possible from the given SendBuffer chain into the write buffer and returns the number of bytes written (might be 0)
| 1085 | // Writes as many bytes as possible from the given SendBuffer chain into the write buffer and returns the number of |
| 1086 | // bytes written (might be 0) |
| 1087 | int write(SendBuffer const* data, int limit) override { |
| 1088 | #ifdef __APPLE__ |
| 1089 | // For some reason, writing ssl_sock with more than 2016 bytes when socket is writeable sometimes results in a |
| 1090 | // broken pipe error. |
| 1091 | limit = std::min(limit, 2016); |
| 1092 | #endif |
| 1093 | boost::system::error_code err; |
| 1094 | ++g_net2->countWrites; |
| 1095 | |
| 1096 | size_t sent = ssl_sock.write_some( |
| 1097 | boost::iterator_range<SendBufferIterator>(SendBufferIterator(data, limit), SendBufferIterator()), err); |
| 1098 | |
| 1099 | if (err) { |
| 1100 | // Since there was an error, sent's value can't be used to infer that the buffer has data and the limit is |
| 1101 | // positive so check explicitly. |
| 1102 | ASSERT(limit > 0); |
| 1103 | bool notEmpty = false; |
| 1104 | for (auto p = data; p; p = p->next) |
| 1105 | if (p->bytes_written - p->bytes_sent > 0) { |
| 1106 | notEmpty = true; |
| 1107 | break; |
| 1108 | } |
| 1109 | ASSERT(notEmpty); |
| 1110 | |
| 1111 | if (err == boost::asio::error::would_block) { |
| 1112 | ++g_net2->countWouldBlock; |
| 1113 | return 0; |
| 1114 | } |
| 1115 | onWriteError(err); |
| 1116 | throw connection_failed(); |
| 1117 | } |
| 1118 | |
| 1119 | ASSERT(sent); // Make sure data was sent, and also this check will fail if the buffer chain was empty or the |
| 1120 | // limit was not > 0. |
| 1121 | return sent; |
| 1122 | } |
| 1123 | |
| 1124 | NetworkAddress getPeerAddress() const override { return peer_address; } |
| 1125 |
no test coverage detected