summaryrefslogtreecommitdiffhomepage
path: root/test/packetimpact/dut/posix_server.cc
diff options
context:
space:
mode:
Diffstat (limited to 'test/packetimpact/dut/posix_server.cc')
-rw-r--r--test/packetimpact/dut/posix_server.cc56
1 files changed, 42 insertions, 14 deletions
diff --git a/test/packetimpact/dut/posix_server.cc b/test/packetimpact/dut/posix_server.cc
index 0f8e279f8..de5b4be93 100644
--- a/test/packetimpact/dut/posix_server.cc
+++ b/test/packetimpact/dut/posix_server.cc
@@ -116,7 +116,9 @@ class PosixImpl final : public posix_server::Posix::Service {
socklen_t addrlen = sizeof(addr);
response->set_fd(accept(request->sockfd(),
reinterpret_cast<sockaddr *>(&addr), &addrlen));
- response->set_errno_(errno);
+ if (response->fd() < 0) {
+ response->set_errno_(errno);
+ }
return sockaddr_to_proto(addr, addrlen, response->mutable_addr());
}
@@ -137,7 +139,9 @@ class PosixImpl final : public posix_server::Posix::Service {
response->set_ret(
bind(request->sockfd(), reinterpret_cast<sockaddr *>(&addr), addr_len));
- response->set_errno_(errno);
+ if (response->ret() < 0) {
+ response->set_errno_(errno);
+ }
return ::grpc::Status::OK;
}
@@ -145,7 +149,9 @@ class PosixImpl final : public posix_server::Posix::Service {
const ::posix_server::CloseRequest *request,
::posix_server::CloseResponse *response) override {
response->set_ret(close(request->fd()));
- response->set_errno_(errno);
+ if (response->ret() < 0) {
+ response->set_errno_(errno);
+ }
return ::grpc::Status::OK;
}
@@ -165,7 +171,9 @@ class PosixImpl final : public posix_server::Posix::Service {
response->set_ret(connect(request->sockfd(),
reinterpret_cast<sockaddr *>(&addr), addr_len));
- response->set_errno_(errno);
+ if (response->ret() < 0) {
+ response->set_errno_(errno);
+ }
return ::grpc::Status::OK;
}
@@ -173,7 +181,9 @@ class PosixImpl final : public posix_server::Posix::Service {
const ::posix_server::FcntlRequest *request,
::posix_server::FcntlResponse *response) override {
response->set_ret(::fcntl(request->fd(), request->cmd(), request->arg()));
- response->set_errno_(errno);
+ if (response->ret() < 0) {
+ response->set_errno_(errno);
+ }
return ::grpc::Status::OK;
}
@@ -185,7 +195,9 @@ class PosixImpl final : public posix_server::Posix::Service {
socklen_t addrlen = sizeof(addr);
response->set_ret(getsockname(
request->sockfd(), reinterpret_cast<sockaddr *>(&addr), &addrlen));
- response->set_errno_(errno);
+ if (response->ret() < 0) {
+ response->set_errno_(errno);
+ }
return sockaddr_to_proto(addr, addrlen, response->mutable_addr());
}
@@ -227,7 +239,9 @@ class PosixImpl final : public posix_server::Posix::Service {
return ::grpc::Status(grpc::StatusCode::INVALID_ARGUMENT,
"Unknown SockOpt Type");
}
- response->set_errno_(errno);
+ if (response->ret() < 0) {
+ response->set_errno_(errno);
+ }
return ::grpc::Status::OK;
}
@@ -235,7 +249,9 @@ class PosixImpl final : public posix_server::Posix::Service {
const ::posix_server::ListenRequest *request,
::posix_server::ListenResponse *response) override {
response->set_ret(listen(request->sockfd(), request->backlog()));
- response->set_errno_(errno);
+ if (response->ret() < 0) {
+ response->set_errno_(errno);
+ }
return ::grpc::Status::OK;
}
@@ -244,7 +260,9 @@ class PosixImpl final : public posix_server::Posix::Service {
::posix_server::SendResponse *response) override {
response->set_ret(::send(request->sockfd(), request->buf().data(),
request->buf().size(), request->flags()));
- response->set_errno_(errno);
+ if (response->ret() < 0) {
+ response->set_errno_(errno);
+ }
return ::grpc::Status::OK;
}
@@ -265,7 +283,9 @@ class PosixImpl final : public posix_server::Posix::Service {
response->set_ret(::sendto(request->sockfd(), request->buf().data(),
request->buf().size(), request->flags(),
reinterpret_cast<sockaddr *>(&addr), addr_len));
- response->set_errno_(errno);
+ if (response->ret() < 0) {
+ response->set_errno_(errno);
+ }
return ::grpc::Status::OK;
}
@@ -299,7 +319,9 @@ class PosixImpl final : public posix_server::Posix::Service {
return ::grpc::Status(grpc::StatusCode::INVALID_ARGUMENT,
"Unknown SockOpt Type");
}
- response->set_errno_(errno);
+ if (response->ret() < 0) {
+ response->set_errno_(errno);
+ }
return ::grpc::Status::OK;
}
@@ -308,14 +330,18 @@ class PosixImpl final : public posix_server::Posix::Service {
::posix_server::SocketResponse *response) override {
response->set_fd(
socket(request->domain(), request->type(), request->protocol()));
- response->set_errno_(errno);
+ if (response->fd() < 0) {
+ response->set_errno_(errno);
+ }
return ::grpc::Status::OK;
}
::grpc::Status Shutdown(grpc_impl::ServerContext *context,
const ::posix_server::ShutdownRequest *request,
::posix_server::ShutdownResponse *response) override {
- response->set_errno_(shutdown(request->fd(), request->how()));
+ if (shutdown(request->fd(), request->how()) < 0) {
+ response->set_errno_(errno);
+ }
return ::grpc::Status::OK;
}
@@ -328,7 +354,9 @@ class PosixImpl final : public posix_server::Posix::Service {
if (response->ret() >= 0) {
response->set_buf(buf.data(), response->ret());
}
- response->set_errno_(errno);
+ if (response->ret() < 0) {
+ response->set_errno_(errno);
+ }
return ::grpc::Status::OK;
}
};