mirror of
https://github.com/Mathewnd/Astral.git
synced 2026-10-27 12:48:22 +00:00
localsocket: implement SO_RCVTIMEO and SO_SNDTIMEO
This commit is contained in:
@@ -120,6 +120,8 @@ typedef struct {
|
||||
#define SO_PEERCRED 17
|
||||
#define SO_RCVLOWAT 18
|
||||
#define SO_SNDLOWAT 19
|
||||
#define SO_RCVTIMEO 20
|
||||
#define SO_SNDTIMEO 21
|
||||
#define SO_BINDTODEVICE 25
|
||||
#define SO_ACCEPTCONN 30
|
||||
#define SO_PROTOCOL 38
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
|
||||
#include <util.h>
|
||||
#include <stdbool.h>
|
||||
#include <errno.h>
|
||||
|
||||
typedef long time_t;
|
||||
typedef long suseconds_t;
|
||||
@@ -65,4 +66,19 @@ static inline timeval_t timespec_to_timeval(timespec_t ts) {
|
||||
return tv;
|
||||
}
|
||||
|
||||
static inline int timeval_to_us(timeval_t *tv, time_t *timeout_us) {
|
||||
if (tv->s < 0 || tv->us < 0 || tv->us >= 1000000)
|
||||
return EINVAL;
|
||||
|
||||
*timeout_us = tv->s * 1000000 + tv->us;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static inline timeval_t timeval_from_us(time_t timeout_us) {
|
||||
return (timeval_t) {
|
||||
.s = timeout_us / 1000000,
|
||||
.us = timeout_us % 1000000
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user