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)
| 1159 | // Writes as many bytes as possible from the given SendBuffer chain into the write buffer and returns the number of |
| 1160 | // bytes written (might be 0) |
| 1161 | int write(SendBuffer const* data, int limit) override { |
| 1162 | #ifdef __APPLE__ |
| 1163 | // For some reason, writing ssl_sock with more than 2016 bytes when socket is writeable sometimes results in a |
| 1164 | // broken pipe error. |
| 1165 | limit = std::min(limit, 2016); |
| 1166 | #endif |
| 1167 | boost::system::error_code err; |
| 1168 | ++g_net2->countWrites; |
| 1169 | |
| 1170 | size_t sent = ssl_sock.write_some( |
| 1171 | boost::iterator_range<SendBufferIterator>(SendBufferIterator(data, limit), SendBufferIterator()), err); |
| 1172 | |
| 1173 | if (err) { |
| 1174 | // Since there was an error, sent's value can't be used to infer that the buffer has data and the limit is |
| 1175 | // positive so check explicitly. |
| 1176 | ASSERT(limit > 0); |
| 1177 | bool notEmpty = false; |
| 1178 | for (auto p = data; p; p = p->next) |
| 1179 | if (p->bytes_written - p->bytes_sent > 0) { |
| 1180 | notEmpty = true; |
| 1181 | break; |
| 1182 | } |
| 1183 | ASSERT(notEmpty); |
| 1184 | |
| 1185 | if (err == boost::asio::error::would_block) { |
| 1186 | ++g_net2->countWouldBlock; |
| 1187 | return 0; |
| 1188 | } |
| 1189 | onWriteError(err); |
| 1190 | throw connection_failed(); |
| 1191 | } |
| 1192 | |
| 1193 | ASSERT(sent); // Make sure data was sent, and also this check will fail if the buffer chain was empty or the |
| 1194 | // limit was not > 0. |
| 1195 | return sent; |
| 1196 | } |
| 1197 | |
| 1198 | NetworkAddress getPeerAddress() const override { return peer_address; } |
| 1199 |
no test coverage detected