#include "reference_drivers/socket_transport.h"
#include <fcntl.h>
#include <poll.h>
#include <stdio.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <algorithm>
#include <cstddef>
#include <cstdint>
#include <cstring>
#include <memory>
#include <optional>
#include <utility>
#include <vector>
#include "reference_drivers/file_descriptor.h"
#include "reference_drivers/handle_eintr.h"
#include "third_party/abseil-cpp/absl/synchronization/mutex.h"
#include "third_party/abseil-cpp/absl/types/span.h"
#include "util/log.h"
#include "util/ref_counted.h"
#include "util/safe_math.h"
namespace ipcz::reference_drivers {
namespace {
constexpr size_t kMaxDescriptorsPerMessage = …;
bool CreateNonBlockingSocketPair(FileDescriptor& first,
FileDescriptor& second) { … }
template <typename T>
absl::Span<T> EnsureCapacity(std::vector<T>& container,
absl::Span<T>& occupied,
size_t capacity) { … }
}
SocketTransport::SocketTransport() = default;
SocketTransport::SocketTransport(FileDescriptor fd) : … { … }
SocketTransport::~SocketTransport() { … }
void SocketTransport::Activate(MessageHandler message_handler,
ErrorHandler error_handler) { … }
void SocketTransport::Deactivate(std::function<void()> shutdown_callback) { … }
bool SocketTransport::Send(Message message) { … }
FileDescriptor SocketTransport::TakeDescriptor() { … }
std::optional<size_t> SocketTransport::TrySend(absl::Span<uint8_t> header,
Message message) { … }
void SocketTransport::RunIOThreadForTransport(Ref<SocketTransport> transport) { … }
void SocketTransport::RunIOThread() { … }
bool SocketTransport::IsOutgoingQueueEmpty() { … }
absl::Span<uint8_t> SocketTransport::EnsureReadCapacity(size_t num_bytes) { … }
void SocketTransport::CommitRead(size_t num_bytes,
std::vector<FileDescriptor> descriptors) { … }
void SocketTransport::NotifyError() { … }
bool SocketTransport::TryDispatchMessages() { … }
void SocketTransport::TryFlushingOutgoingQueue() { … }
void SocketTransport::WakeIOThread() { … }
void SocketTransport::ClearIOThreadSignal() { … }
SocketTransport::DeferredMessage::DeferredMessage() = default;
SocketTransport::DeferredMessage::DeferredMessage(absl::Span<uint8_t> header,
Message message) { … }
SocketTransport::DeferredMessage::DeferredMessage(DeferredMessage&&) = default;
SocketTransport::DeferredMessage& SocketTransport::DeferredMessage::operator=(
DeferredMessage&&) = default;
SocketTransport::DeferredMessage::~DeferredMessage() = default;
SocketTransport::Message SocketTransport::DeferredMessage::AsMessage() { … }
SocketTransport::Pair SocketTransport::CreatePair() { … }
}