Skip to content

Commit

Permalink
fixup: compiler
Browse files Browse the repository at this point in the history
  • Loading branch information
eugeneo committed Dec 10, 2024
1 parent e281f5a commit 8651fc0
Show file tree
Hide file tree
Showing 2 changed files with 92 additions and 79 deletions.
79 changes: 43 additions & 36 deletions src/core/lib/event_engine/posix_engine/posix_system_api.cc
Original file line number Diff line number Diff line change
Expand Up @@ -780,58 +780,58 @@ absl::StatusOr<int> SystemApi::EventFdWrite(FileDescriptor fd,
namespace grpc_event_engine {
namespace experimental {

FileDescriptor SystemApi::AdoptExternalFd(int fd) const {
grpc_core::Crash("unimplemented");
}

FileDescriptor SystemApi::Socket(int domain, int type, int protocol) const {
FileDescriptor SystemApi::AdoptExternalFd(int fd) {
grpc_core::Crash("unimplemented");
}

int SystemApi::Bind(FileDescriptor fd, const struct sockaddr* addr,
socklen_t addrlen) const {
FileDescriptor SystemApi::Socket(int domain, int type, int protocol) {
grpc_core::Crash("unimplemented");
}

void SystemApi::Close(FileDescriptor fd) const {
absl::StatusOr<int> SystemApi::Bind(FileDescriptor fd,
const struct sockaddr* addr,
socklen_t addrlen) const {
grpc_core::Crash("unimplemented");
}

int SystemApi::Fcntl(FileDescriptor fd, int op, int args) const {
grpc_core::Crash("unimplemented");
}
void SystemApi::Close(FileDescriptor fd) { grpc_core::Crash("unimplemented"); }

int SystemApi::GetSockOpt(FileDescriptor fd, int level, int optname,
void* optval, socklen_t* optlen) const {
absl::StatusOr<int> SystemApi::GetSockOpt(FileDescriptor fd, int level,
int optname, void* optval,
socklen_t* optlen) const {
grpc_core::Crash("unimplemented");
}

int SystemApi::GetSockName(FileDescriptor fd, struct sockaddr* addr,
socklen_t* addrlen) const {
absl::StatusOr<int> SystemApi::GetSockName(FileDescriptor fd,
struct sockaddr* addr,
socklen_t* addrlen) const {
grpc_core::Crash("unimplemented");
}

int SystemApi::GetPeerName(FileDescriptor fd, struct sockaddr* addr,
socklen_t* addrlen) const {
absl::StatusOr<int> SystemApi::GetPeerName(FileDescriptor fd,
struct sockaddr* addr,
socklen_t* addrlen) const {
grpc_core::Crash("unimplemented");
}

int SystemApi::Listen(FileDescriptor fd, int backlog) const {
absl::StatusOr<int> SystemApi::Listen(FileDescriptor fd, int backlog) const {
grpc_core::Crash("unimplemented");
}

long SystemApi::RecvMsg(FileDescriptor fd, struct msghdr* msg,
int flags) const {
absl::StatusOr<long> SystemApi::RecvMsg(FileDescriptor fd, struct msghdr* msg,
int flags) const {
grpc_core::Crash("unimplemented");
}

long SystemApi::SendMsg(FileDescriptor fd, const struct msghdr* message,
int flags) const {
absl::StatusOr<long> SystemApi::SendMsg(FileDescriptor fd,
const struct msghdr* message,
int flags) const {
grpc_core::Crash("unimplemented");
}

int SystemApi::SetSockOpt(FileDescriptor fd, int level, int optname,
const void* optval, socklen_t optlen) const {
absl::Status SystemApi::SetSockOpt(FileDescriptor fd, int level, int optname,
const void* optval, socklen_t optlen,
absl::string_view label) const {
grpc_core::Crash("unimplemented");
}

Expand All @@ -844,7 +844,7 @@ absl::Status SystemApi::SetSocketZeroCopy(FileDescriptor fd) const {
}

absl::Status SystemApi::SetSocketNonBlocking(FileDescriptor fd,
int non_blocking) const {
bool non_blocking) const {
grpc_core::Crash("unimplemented");
}

Expand Down Expand Up @@ -897,42 +897,49 @@ bool SystemApi::IsSocketReusePortSupported() const {
grpc_core::Crash("unimplemented");
}

int SystemApi::Shutdown(FileDescriptor sockfd, int how) const {
absl::StatusOr<int> SystemApi::Shutdown(FileDescriptor sockfd, int how) const {
grpc_core::Crash("unimplemented");
}

int SystemApi::Connect(FileDescriptor sockfd, const struct sockaddr* addr,
socklen_t addrlen) const {
absl::StatusOr<int> SystemApi::Connect(FileDescriptor sockfd,
const struct sockaddr* addr,
socklen_t addrlen) const {
grpc_core::Crash("unimplemented");
}

int SystemApi::Ioctl(FileDescriptor fd, int request, void* extras) const {
absl::StatusOr<int> SystemApi::Ioctl(FileDescriptor fd, int request,
void* extras) const {
grpc_core::Crash("unimplemented");
}

long SystemApi::Read(FileDescriptor fd, void* buf, size_t count) const {
absl::StatusOr<long> SystemApi::Read(FileDescriptor fd, void* buf,
size_t count) const {
grpc_core::Crash("unimplemented");
}

long SystemApi::Write(FileDescriptor fd, const void* buf, size_t count) const {
absl::StatusOr<long> SystemApi::Write(FileDescriptor fd, const void* buf,
size_t count) const {
grpc_core::Crash("unimplemented");
}

std::pair<int, std::array<FileDescriptor, 2>> SystemApi::SocketPair(
int domain, int type, int protocol) const {
int domain, int type, int protocol) {
grpc_core::Crash("unimplemented");
}

long SystemApi::EventFdRead(FileDescriptor fd, uint64_t* value) const {
absl::StatusOr<long> SystemApi::EventFdRead(FileDescriptor fd,
uint64_t* value) const {
grpc_core::Crash("unimplemented");
}

long SystemApi::EventFdWrite(FileDescriptor fd, uint64_t value) const {
absl::StatusOr<int> SystemApi::EventFdWrite(FileDescriptor fd,
uint64_t value) const {
grpc_core::Crash("unimplemented");
}

int SystemApi::EpollCtl(FileDescriptor epfd, int op, FileDescriptor fd,
struct epoll_event* event) const {
absl::StatusOr<int> SystemApi::EpollCtl(FileDescriptor epfd, int op,
FileDescriptor fd,
struct epoll_event* event) const {
grpc_core::Crash("unimplemented");
}

Expand Down
92 changes: 49 additions & 43 deletions src/core/lib/event_engine/posix_engine/posix_system_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,53 @@
namespace grpc_event_engine {
namespace experimental {

// Will need to be moved to implementation file, here to save time wrestling
// compilers.
namespace internal {

template <typename R>
struct WithFdReturn {
using type = absl::StatusOr<R>;

template <typename Fn>
static type invoke(const Fn fn, int fd) {
return fn(fd);
}
};

template <>
struct WithFdReturn<absl::Status> {
using type = absl::Status;

template <typename Fn>
static type invoke(const Fn fn, int fd) {
return fn(fd);
}
};

template <typename R>
struct WithFdReturn<absl::StatusOr<R>> {
using type = absl::StatusOr<R>;

template <typename Fn>
static type invoke(const Fn fn, int fd) {
return fn(fd);
}
};

template <>
struct WithFdReturn<void> {
using type = absl::Status;

template <typename Fn>
static type invoke(const Fn fn, int fd) {
fn(fd);
return absl::OkStatus();
}
};

} // namespace internal

class LockedFd;

ABSL_ATTRIBUTE_TRIVIAL_ABI class FileDescriptor {
Expand Down Expand Up @@ -219,55 +266,14 @@ class SystemApi {
FileDescriptor RegisterFileDescriptor(int fd);
void Unlock(int fd) const;

template <typename R>
struct WithFdReturn {
using type = absl::StatusOr<R>;

template <typename Fn>
static type invoke(const Fn fn, int fd) {
return fn(fd);
}
};

template <>
struct WithFdReturn<absl::Status> {
using type = absl::Status;

template <typename Fn>
static type invoke(const Fn fn, int fd) {
return fn(fd);
}
};

template <typename R>
struct WithFdReturn<absl::StatusOr<R>> {
using type = absl::StatusOr<R>;

template <typename Fn>
static type invoke(const Fn fn, int fd) {
return fn(fd);
}
};

template <>
struct WithFdReturn<void> {
using type = absl::Status;

template <typename Fn>
static type invoke(const Fn fn, int fd) {
fn(fd);
return absl::OkStatus();
}
};

template <typename Fn>
auto WithFd(const FileDescriptor& fd, const Fn& fn) const ->
typename WithFdReturn<decltype(fn(0))>::type {
typename internal::WithFdReturn<decltype(fn(0))>::type {
auto locked_fd = Lock(fd);
if (!locked_fd.ok()) {
return std::move(locked_fd).status();
}
return WithFdReturn<decltype(fn(0))>::invoke(fn, locked_fd->fd());
return internal::WithFdReturn<decltype(fn(0))>::invoke(fn, locked_fd->fd());
}

// Whether the socket supports TCP_USER_TIMEOUT option.
Expand Down

0 comments on commit 8651fc0

Please sign in to comment.