| 127 | } |
| 128 | |
| 129 | void WriteBufferFromPocoSocket::nextImpl() |
| 130 | { |
| 131 | if (!offset()) |
| 132 | return; |
| 133 | |
| 134 | Stopwatch watch; |
| 135 | size_t bytes_written = 0; |
| 136 | |
| 137 | SCOPE_EXIT({ |
| 138 | ProfileEvents::increment(ProfileEvents::NetworkSendElapsedMicroseconds, watch.elapsedMicroseconds()); |
| 139 | ProfileEvents::increment(ProfileEvents::NetworkSendBytes, bytes_written); |
| 140 | if (write_event != ProfileEvents::end()) |
| 141 | ProfileEvents::increment(write_event, bytes_written); |
| 142 | }); |
| 143 | |
| 144 | while (bytes_written < offset()) |
| 145 | { |
| 146 | ssize_t res = 0; |
| 147 | |
| 148 | /// Add more details to exceptions. |
| 149 | try |
| 150 | { |
| 151 | CurrentMetrics::Increment metric_increment(CurrentMetrics::NetworkSend); |
| 152 | char * pos = working_buffer.begin() + bytes_written; |
| 153 | size_t size = offset() - bytes_written; |
| 154 | if (size > INT_MAX) |
| 155 | throw Exception(ErrorCodes::LOGICAL_ERROR, "Buffer overflow"); |
| 156 | |
| 157 | res = socketSendBytesImpl(pos, size); |
| 158 | } |
| 159 | catch (const Poco::Net::NetException & e) |
| 160 | { |
| 161 | throw NetException(ErrorCodes::NETWORK_ERROR, "{}, while writing to socket ({} -> {})", e.displayText(), |
| 162 | our_address.toString(), peer_address.toString()); |
| 163 | } |
| 164 | catch (const Poco::TimeoutException &) |
| 165 | { |
| 166 | throw NetException(ErrorCodes::SOCKET_TIMEOUT, "Timeout exceeded while writing to socket ({}, {} ms)", |
| 167 | peer_address.toString(), |
| 168 | socket.impl()->getSendTimeout().totalMilliseconds()); |
| 169 | } |
| 170 | catch (const Poco::IOException & e) |
| 171 | { |
| 172 | throw NetException(ErrorCodes::NETWORK_ERROR, "{}, while writing to socket ({} -> {})", e.displayText(), |
| 173 | our_address.toString(), peer_address.toString()); |
| 174 | } |
| 175 | |
| 176 | if (res < 0) |
| 177 | throw NetException(ErrorCodes::CANNOT_WRITE_TO_SOCKET, "Cannot write to socket ({} -> {})", |
| 178 | our_address.toString(), peer_address.toString()); |
| 179 | |
| 180 | bytes_written += res; |
| 181 | } |
| 182 | } |
| 183 | |
| 184 | WriteBufferFromPocoSocket::WriteBufferFromPocoSocket(Poco::Net::Socket & socket_, size_t buf_size) |
| 185 | : WriteBufferFromPocoSocket(socket_, buf_size, nullptr) |
nothing calls this directly
no test coverage detected