MCPcopy Create free account
hub / github.com/3rdparty/libprocess / sendfile

Method sendfile

src/posix/poll_socket.cpp:238–283  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

236
237
238Future<size_t> PollSocketImpl::sendfile(int_fd fd, off_t offset, size_t size)
239{
240 CHECK(size > 0); // TODO(benh): Just return 0 if `size` is 0?
241
242 // Need to hold a copy of `this` so that the underlying socket
243 // doesn't end up getting reused before we return.
244 auto self = shared(this);
245
246 return loop(
247 None(),
248 [self, fd, offset, size]() -> Future<Option<size_t>> {
249 while (true) {
250 Try<ssize_t, SocketError> length = os::sendfile(
251 self->get(),
252 fd,
253 offset,
254 size);
255
256 if (length.isSome()) {
257 CHECK(length.get() >= 0);
258 return length.get();
259 }
260
261 if (net::is_restartable_error(length.error().code)) {
262 // Interrupted, try again now.
263 continue;
264 } else if (!net::is_retryable_error(length.error().code)) {
265 VLOG(1) << length.error().message;
266 return Failure(length.error());
267 }
268
269 return None();
270 }
271 },
272 [self](const Option<size_t>& length) -> Future<ControlFlow<size_t>> {
273 // Retry after we've polled if we don't yet have a result.
274 if (length.isNone()) {
275 return io::poll(self->get(), io::WRITE)
276 .then([](short event) -> ControlFlow<size_t> {
277 CHECK_EQ(io::WRITE, event);
278 return Continue();
279 });
280 }
281 return Break(length.get());
282 });
283}
284
285} // namespace internal {
286} // namespace network {

Callers 2

sendFunction · 0.45
_sendFunction · 0.45

Calls 8

loopFunction · 0.85
FailureClass · 0.85
sendfileFunction · 0.50
pollFunction · 0.50
ContinueClass · 0.50
BreakFunction · 0.50
getMethod · 0.45
thenMethod · 0.45

Tested by

no test coverage detected