MCPcopy Create free account
hub / github.com/ClickHouse/ClickHouse / socketSendBytes

Method socketSendBytes

src/IO/WriteBufferFromPocoSocket.cpp:76–127  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

74}
75
76void 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
129void WriteBufferFromPocoSocket::nextImpl()
130{

Callers

nothing calls this directly

Calls 10

NetExceptionClass · 0.85
displayTextMethod · 0.80
ExceptionClass · 0.70
incrementFunction · 0.50
endFunction · 0.50
elapsedMicrosecondsMethod · 0.45
toStringMethod · 0.45
totalMillisecondsMethod · 0.45
getSendTimeoutMethod · 0.45
implMethod · 0.45

Tested by

no test coverage detected