Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 6 additions & 32 deletions base/cvd/cuttlefish/common/libs/fs/fd.cc
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ Result<Fd> Fd::SocketLocalServer(int port, int type) {
"Bind failed: {}", rval.StrError());

if (type == SOCK_STREAM || type == SOCK_SEQPACKET) {
CF_EXPECTF(rval.Listen(4) >= 0, "Listen failed: {}", rval.StrError());
CF_EXPECT(rval.Listen(4));
}
return rval;
}
Expand Down Expand Up @@ -383,7 +383,7 @@ Result<Fd> Fd::SocketLocalServer(std::string_view name, bool abstract,
// Connection oriented sockets: start listening.
if (socket_type == SOCK_STREAM || socket_type == SOCK_SEQPACKET) {
// Follows the default from socket_local_server
CF_EXPECTF(rval.Listen(4) >= 0, "Listen failed: {}", rval.StrError());
CF_EXPECT(rval.Listen(4));
}

if (!abstract) {
Expand Down Expand Up @@ -416,8 +416,7 @@ Result<Fd> Fd::VsockServer(unsigned int port, int type,
"Bind failed port {}: {}", port, vsock.StrError());

if (type == SOCK_STREAM || type == SOCK_SEQPACKET) {
CF_EXPECTF(vsock.Listen(4) >= 0, "Listen on port {} failed: {}", port,
vsock.StrError());
CF_EXPECTF(vsock.Listen(4), "Listen on port {} failed", port);
}
return vsock;
}
Expand Down Expand Up @@ -729,10 +728,10 @@ int Fd::LinkAtCwd(const std::string& path) {
AT_SYMLINK_FOLLOW);
}

int Fd::Listen(int backlog) {
Result<void> Fd::Listen(int backlog) {
LocalErrno record_errno(errno_);

return listen(fd_, backlog);
CF_EXPECT_GE(listen(fd_, backlog), 0, ::cuttlefish::StrError(errno));
return {};
}

off_t Fd::LSeek(off_t offset, int whence) {
Expand Down Expand Up @@ -828,31 +827,6 @@ int Fd::GetSockOpt(int level, int optname, void* optval, socklen_t* optlen) {
return getsockopt(fd_, level, optname, optval, optlen);
}

int Fd::SetTerminalRaw() {
LocalErrno record_errno(errno_);

termios terminal_settings;
if (int rval = tcgetattr(fd_, &terminal_settings); rval < 0) {
return rval;
}
cfmakeraw(&terminal_settings);
if (int rval = tcsetattr(fd_, TCSANOW, &terminal_settings); rval < 0) {
return rval;
}

// tcsetattr() succeeds if any of the requested change success.
// So double check whether everything is applied.
termios raw_settings;
if (int rval = tcgetattr(fd_, &raw_settings); rval < 0) {
return rval;
}
if (memcmp(&terminal_settings, &raw_settings, sizeof(terminal_settings))) {
errno = EPROTO;
return -1;
}
return 0;
}

std::string Fd::StrError() const {
errno = 0;
return std::string(::cuttlefish::StrError(errno_));
Expand Down
4 changes: 2 additions & 2 deletions base/cvd/cuttlefish/common/libs/fs/fd.h
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,6 @@ class Fd : public ReaderWriterSeeker {
*/
// Used with O_TMPFILE files to attach them to the filesystem.
int LinkAtCwd(const std::string& path);
int Listen(int backlog);
static void Log(const char* message);
off_t LSeek(off_t offset, int whence);
ssize_t Recv(void* buf, size_t len, int flags);
Expand Down Expand Up @@ -241,7 +240,6 @@ class Fd : public ReaderWriterSeeker {
void Set(fd_set* dest, int* max_index) const;
int SetSockOpt(int level, int optname, const void* optval, socklen_t optlen);
int GetSockOpt(int level, int optname, void* optval, socklen_t* optlen);
int SetTerminalRaw();
std::string StrError() const;
ScopedMMap MMap(void* addr, size_t length, int prot, int flags, off_t offset);
Result<void> Truncate(uint64_t length) override;
Expand Down Expand Up @@ -270,6 +268,8 @@ class Fd : public ReaderWriterSeeker {
private:
Fd(int fd, int in_errno);

Result<void> Listen(int backlog);

static Fd ErrorFD(int error);

int fd_;
Expand Down
Loading