| 74 | } |
| 75 | |
| 76 | void WriteBufferFromPocoSocket::socketSendBytes(const char * ptr, size_t size) |
| 77 | { |
| 78 | if (!size) |
| 79 | return; |
| 80 | |
| 81 | Stopwatch watch; |
| 82 | size_t bytes_written = 0; |
| 83 | |
| 84 | SCOPE_EXIT({ |
| 85 | ProfileEvents::increment(ProfileEvents::NetworkSendElapsedMicroseconds, watch.elapsedMicroseconds()); |
| 86 | ProfileEvents::increment(ProfileEvents::NetworkSendBytes, bytes_written); |
| 87 | if (write_event != ProfileEvents::end()) |
| 88 | ProfileEvents::increment(write_event, bytes_written); |
| 89 | }); |
| 90 | |
| 91 | while (bytes_written < size) |
| 92 | { |
| 93 | ssize_t res = 0; |
| 94 | |
| 95 | /// Add more details to exceptions. |
| 96 | try |
| 97 | { |
| 98 | CurrentMetrics::Increment metric_increment(CurrentMetrics::NetworkSend); |
| 99 | if (size > INT_MAX) |
| 100 | throw Exception(ErrorCodes::LOGICAL_ERROR, "Buffer overflow"); |
| 101 | |
| 102 | res = socketSendBytesImpl(ptr + bytes_written, size - bytes_written); |
| 103 | } |
| 104 | catch (const Poco::Net::NetException & e) |
| 105 | { |
| 106 | throw NetException(ErrorCodes::NETWORK_ERROR, "{}, while writing to socket ({} -> {})", e.displayText(), |
| 107 | our_address.toString(), peer_address.toString()); |
| 108 | } |
| 109 | catch (const Poco::TimeoutException &) |
| 110 | { |
| 111 | throw NetException(ErrorCodes::SOCKET_TIMEOUT, "Timeout exceeded while writing to socket ({}, {} ms)", |
| 112 | peer_address.toString(), |
| 113 | socket.impl()->getSendTimeout().totalMilliseconds()); |
| 114 | } |
| 115 | catch (const Poco::IOException & e) |
| 116 | { |
| 117 | throw NetException(ErrorCodes::NETWORK_ERROR, "{}, while writing to socket ({} -> {})", e.displayText(), |
| 118 | our_address.toString(), peer_address.toString()); |
| 119 | } |
| 120 | |
| 121 | if (res < 0) |
| 122 | throw NetException(ErrorCodes::CANNOT_WRITE_TO_SOCKET, "Cannot write to socket ({} -> {})", |
| 123 | our_address.toString(), peer_address.toString()); |
| 124 | |
| 125 | bytes_written += res; |
| 126 | } |
| 127 | } |
| 128 | |
| 129 | void WriteBufferFromPocoSocket::nextImpl() |
| 130 | { |
nothing calls this directly
no test coverage detected