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

Function write_internal

src/windows/libwinio.cpp:492–525  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

490
491
492static Future<size_t> write_internal(
493 const int_fd& fd, const void* buf, size_t size, IOType type)
494{
495 process::initialize();
496
497 Promise<size_t>* promise = new Promise<size_t>();
498 Future<size_t> future = promise->future();
499
500 // We use a `std::shared_ptr`, so we can safely support canceling.
501 auto overlapped = std::make_shared<IOOverlappedReadWrite>(
502 IOOverlappedBase{OVERLAPPED{}, fd, type}, promise);
503
504 enable_cancellation(fd, future, overlapped);
505
506 // Start the asynchronous operation.
507 const Result<size_t> result =
508 os::write_async(fd, buf, size, &overlapped->base.overlapped);
509
510 // If the request is pending, then we return immediately and have the
511 // callback free the promise and overlapped.
512 if (result.isNone()) {
513 return future;
514 }
515
516 // In an error or immediate success, we have to manually set the promise
517 // and free it.
518 if (result.isError()) {
519 promise->fail("os::write_async failed: " + result.error());
520 } else if (result.isSome()) {
521 promise->set(result.get());
522 }
523 delete promise;
524 return future;
525}
526
527
528Future<size_t> read(const int_fd& fd, void* buf, size_t size)

Callers 2

writeFunction · 0.85
sendFunction · 0.85

Calls 6

enable_cancellationFunction · 0.85
futureMethod · 0.80
initializeFunction · 0.50
failMethod · 0.45
setMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected