folly/folly/io/async/SimpleAsyncIO.cpp

/*
 * Copyright (c) Meta Platforms, Inc. and affiliates.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include <folly/io/async/SimpleAsyncIO.h>

#include <folly/String.h>
#include <folly/experimental/coro/Baton.h>
#include <folly/experimental/io/AsyncIO.h>
#include <folly/experimental/io/IoUring.h>
#include <folly/experimental/io/Liburing.h>
#include <folly/portability/Sockets.h>

namespace folly {

#if __has_include(<libaio.h>)
static constexpr bool has_aio = true;
using aio_type = AsyncIO;
#else
static constexpr bool has_aio =;
aio_type;
#endif

#if FOLLY_HAS_LIBURING
static constexpr auto has_io_uring_rt = &IoUring::isAvailable;
using io_uring_type = IoUring;
#else
static constexpr auto has_io_uring_rt =;
io_uring_type;
#endif

template <typename AsyncIOType>
void SimpleAsyncIO::init() {}

template <>
void SimpleAsyncIO::init<void>() {}

SimpleAsyncIO::SimpleAsyncIO(Config cfg)
    :{}

SimpleAsyncIO::~SimpleAsyncIO() {}

void SimpleAsyncIO::handlerReady(uint16_t events) noexcept {}

std::unique_ptr<AsyncBaseOp> SimpleAsyncIO::getOp() {}

void SimpleAsyncIO::putOp(std::unique_ptr<AsyncBaseOp>&& op) {}

void SimpleAsyncIO::submitOp(
    Function<void(AsyncBaseOp*)> preparer, SimpleAsyncIOCompletor completor) {}

void SimpleAsyncIO::pread(
    int fd,
    void* buf,
    size_t size,
    off_t start,
    SimpleAsyncIOCompletor completor) {}

void SimpleAsyncIO::pwrite(
    int fd,
    const void* buf,
    size_t size,
    off_t start,
    SimpleAsyncIOCompletor completor) {}

#if FOLLY_HAS_COROUTINES
folly::coro::Task<int> SimpleAsyncIO::co_pwrite(
    int fd, const void* buf, size_t size, off_t start) {
  folly::coro::Baton done;
  int result;
  pwrite(fd, buf, size, start, [&done, &result](int rc) {
    result = rc;
    done.post();
  });
  co_await done;
  co_return result;
}

folly::coro::Task<int> SimpleAsyncIO::co_pread(
    int fd, void* buf, size_t size, off_t start) {
  folly::coro::Baton done;
  int result;
  pread(fd, buf, size, start, [&done, &result](int rc) {
    result = rc;
    done.post();
  });
  co_await done;
  co_return result;
}
#endif // FOLLY_HAS_COROUTINES

} // namespace folly