diff options
Diffstat (limited to 'libhw/host_net.c')
-rw-r--r-- | libhw/host_net.c | 32 |
1 files changed, 11 insertions, 21 deletions
diff --git a/libhw/host_net.c b/libhw/host_net.c index 904019a..97e7726 100644 --- a/libhw/host_net.c +++ b/libhw/host_net.c @@ -17,16 +17,18 @@ #include <sys/socket.h> /* for struct sockaddr{,_storage}, SOCK_*, SOL_*, SO_*, socket(), setsockopt(), bind(), listen(), accept() */ /* async */ #include <pthread.h> /* for pthread_* */ -#include <signal.h> /* for siginfo_t, struct sigaction, enum sigval, sigaction(), SIGRTMIN, SIGRTMAX, SA_SIGINFO */ +#include <signal.h> /* for siginfo_t, struct sigaction, enum sigval, sigaction(), SA_SIGINFO */ #include <libcr/coroutine.h> #include <libmisc/vcall.h> -#include <libhw/generic/bootclock.h> +#include <libhw/generic/alarmclock.h> #define IMPLEMENTATION_FOR_LIBHW_HOST_NET_H YES #include <libhw/host_net.h> +#include "host_sigrt.h" /* for host_sigrt_alloc(), ns_to_host_us_time() */ + /* common *********************************************************************/ #define UNUSED(name) /* name __attribute__ ((unused)) */ @@ -43,9 +45,7 @@ static void hostnet_init(void) { if (hostnet_sig_io) return; - hostnet_sig_io = SIGRTMIN; - if (hostnet_sig_io > SIGRTMAX) - error(1, 0, "SIGRTMAX exceeded"); + hostnet_sig_io = host_sigrt_alloc(); action.sa_flags = SA_SIGINFO; action.sa_sigaction = hostnet_handle_sig_io; @@ -230,17 +230,12 @@ static ssize_t hostnet_tcp_read(implements_net_stream_conn *_conn, void *buf, si .ret = &ret, }; if (conn->read_deadline_ns) { - uint64_t now_ns = bootclock_get_ns(); + uint64_t now_ns = VCALL(bootclock, get_time_ns); if (conn->read_deadline_ns < now_ns) return -NET_ETIMEDOUT; - uint64_t timeout_ns = conn->read_deadline_ns-now_ns; - args.timeout.tv_sec = timeout_ns - /NS_PER_S; - args.timeout.tv_usec = (timeout_ns - ((uint64_t)args.timeout.tv_sec)*NS_PER_S) - /(NS_PER_S/US_PER_S); + args.timeout = ns_to_host_us_time(conn->read_deadline_ns-now_ns); } else { - args.timeout.tv_sec = 0; - args.timeout.tv_usec = 0; + args.timeout = ns_to_host_us_time(0); } if (RUN_PTHREAD(hostnet_pthread_read, &args)) @@ -500,17 +495,12 @@ static ssize_t hostnet_udp_recvfrom(implements_net_packet_conn *_conn, void *buf .ret_port = ret_port, }; if (conn->read_deadline_ns) { - uint64_t now_ns = bootclock_get_ns(); + uint64_t now_ns = VCALL(bootclock, get_time_ns); if (conn->read_deadline_ns < now_ns) return -NET_ETIMEDOUT; - uint64_t timeout_ns = conn->read_deadline_ns-now_ns; - args.timeout.tv_sec = timeout_ns - /NS_PER_S; - args.timeout.tv_usec = (timeout_ns - ((uint64_t)args.timeout.tv_sec)*NS_PER_S) - /(NS_PER_S/US_PER_S); + args.timeout = ns_to_host_us_time(conn->read_deadline_ns-now_ns); } else { - args.timeout.tv_sec = 0; - args.timeout.tv_usec = 0; + args.timeout = ns_to_host_us_time(0); } if (RUN_PTHREAD(hostnet_pthread_recvfrom, &args)) |