localsocket: implement SO_RCVTIMEO and SO_SNDTIMEO

This commit is contained in:
Matheus
2026-07-07 02:17:26 -03:00
parent c25807d976
commit c75617a6e2
3 changed files with 66 additions and 5 deletions
+2
View File
@@ -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
+16
View File
@@ -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