summaryrefslogtreecommitdiff
path: root/libhw/host_net.c
diff options
context:
space:
mode:
Diffstat (limited to 'libhw/host_net.c')
-rw-r--r--libhw/host_net.c24
1 files changed, 14 insertions, 10 deletions
diff --git a/libhw/host_net.c b/libhw/host_net.c
index 20b72f1..27df2e2 100644
--- a/libhw/host_net.c
+++ b/libhw/host_net.c
@@ -75,14 +75,18 @@ static inline bool RUN_PTHREAD(void *(*fn)(void *), void *args) {
return false;
}
-static inline ssize_t hostnet_map_errno(ssize_t v) {
+static inline ssize_t hostnet_map_negerrno(ssize_t v) {
if (v >= 0)
return v;
switch (v) {
- case ETIMEDOUT:
- return NET_ETIMEDOUT;
+ case -ETIMEDOUT:
+ return -NET_ETIMEDOUT;
+ case -EBADF:
+ return -NET_ECLOSED;
+ case -EMSGSIZE:
+ return -NET_EMSGSIZE;
default:
- return NET_EOTHER;
+ return -NET_EOTHER;
}
}
@@ -208,7 +212,7 @@ static void *hostnet_pthread_read(void *_args) {
end:
if (*(args->ret) < 0)
- *(args->ret) = hostnet_map_errno(-errno);
+ *(args->ret) = hostnet_map_negerrno(-errno);
WAKE_COROUTINE(args);
return NULL;
}
@@ -262,7 +266,7 @@ static void *hostnet_pthread_write(void *_args) {
while (done < args->count) {
ssize_t r = write(args->connfd, args->buf, args->count);
if (r < 0) {
- hostnet_map_errno(-errno);
+ hostnet_map_negerrno(-errno);
break;
}
done += r;
@@ -310,7 +314,7 @@ static int hostnet_tcp_close(implements_net_stream_conn *_conn, bool rd, bool wr
how = SHUT_WR;
else
assert(false);
- return hostnet_map_errno(shutdown(conn->fd, how) ? -errno : 0);
+ return hostnet_map_negerrno(shutdown(conn->fd, how) ? -errno : 0);
}
/* UDP init() *****************************************************************/
@@ -384,7 +388,7 @@ static void *hostnet_pthread_sendto(void *_args) {
addr.in.sin_port = htons(args->port);
*(args->ret) = sendto(args->connfd, args->buf, args->count, 0, &addr.gen, sizeof(addr));
if (*(args->ret) < 0)
- *(args->ret) = hostnet_map_errno(-errno);
+ *(args->ret) = hostnet_map_negerrno(-errno);
WAKE_COROUTINE(args);
return NULL;
}
@@ -470,7 +474,7 @@ static void *hostnet_pthread_recvfrom(void *_args) {
end:
if (*(args->ret_size) < 0)
- *(args->ret_size) = hostnet_map_errno(-errno);
+ *(args->ret_size) = hostnet_map_negerrno(-errno);
WAKE_COROUTINE(args);
return NULL;
}
@@ -515,5 +519,5 @@ static int hostnet_udp_close(implements_net_packet_conn *_conn) {
VCALL_SELF(struct hostnet_udp_conn, implements_net_packet_conn, _conn);
assert(conn);
- return hostnet_map_errno(close(conn->fd) ? -errno : 0);
+ return hostnet_map_negerrno(close(conn->fd) ? -errno : 0);
}