#pragma once
#include <optional>
#include <folly/ExceptionWrapper.h>
#include <folly/Expected.h>
#include <folly/SocketAddress.h>
#include <folly/io/async/AsyncServerSocket.h>
#include <folly/io/coro/Transport.h>
#if FOLLY_HAS_COROUTINES
namespace folly {
namespace coro {
class ServerSocket {
public:
ServerSocket(
std::shared_ptr<AsyncServerSocket> socket,
std::optional<SocketAddress> bindAddr,
uint32_t listenQueueDepth);
ServerSocket(ServerSocket&&) = default;
ServerSocket& operator=(ServerSocket&&) = default;
Task<std::unique_ptr<Transport>> accept();
void close() noexcept {
if (socket_) {
socket_->stopAccepting();
}
}
const AsyncServerSocket* getAsyncServerSocket() const {
return socket_.get();
}
private:
ServerSocket(const ServerSocket&) = delete;
ServerSocket& operator=(const ServerSocket&) = delete;
std::shared_ptr<AsyncServerSocket> socket_;
};
}
}
#endif