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

Method nextImpl

src/IO/WriteBufferFromPocoSocket.cpp:129–182  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

127}
128
129void 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
184WriteBufferFromPocoSocket::WriteBufferFromPocoSocket(Poco::Net::Socket & socket_, size_t buf_size)
185 : WriteBufferFromPocoSocket(socket_, buf_size, nullptr)

Callers

nothing calls this directly

Calls 11

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

Tested by

no test coverage detected