diff options
author | Glenn Strauss <gstrauss@gluelogic.com> | 2017-12-11 01:20:43 -0500 |
---|---|---|
committer | Glenn Strauss <gstrauss@gluelogic.com> | 2017-12-11 21:35:31 -0500 |
commit | 84b5064dc4ca6a9e670f4566923ee8c8b4706c55 (patch) | |
tree | 30ffda08fd74b436226e41e3fcd2ae1a06f863b0 /src/fdevent.c | |
parent | e4ed2ed4aeb3a0afe9f5bc51559c0c0c2ac11a72 (diff) | |
download | lighttpd-git-84b5064dc4ca6a9e670f4566923ee8c8b4706c55.tar.gz |
[core] discard from socket using recv MSG_TRUNC
discard from socket using recv MSG_TRUNC on Linux TCP SOCK_STREAM socket
Currently, lighttpd supports only TCP SOCK_STREAM. If UDP SOCK_DGRAM
were to be supported in the future, then socket type will need to be
stored so that MSG_TRUNC is used appropriately for the desired effect.
To find out socket type on arbitrary socket fd:
getsockopt(..., SOL_SOCKET, SO_TYPE, ...)
but better to store it with each listening socket.
Diffstat (limited to 'src/fdevent.c')
-rw-r--r-- | src/fdevent.c | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/src/fdevent.c b/src/fdevent.c index 441744a7..e8b94dfa 100644 --- a/src/fdevent.c +++ b/src/fdevent.c @@ -889,6 +889,28 @@ int fdevent_cycle_logger(const char *logger, int *curfd) { } +#ifndef MSG_DONTWAIT +#define MSG_DONTWAIT 0 +#endif +#ifndef MSG_NOSIGNAL +#define MSG_NOSIGNAL 0 +#endif + + +ssize_t fdevent_socket_read_discard (int fd, char *buf, size_t sz, int family, int so_type) { + #if defined(MSG_TRUNC) && defined(__linux__) + if ((family == AF_INET || family == AF_INET6) && so_type == SOCK_STREAM) { + ssize_t len = recv(fd, buf, sz, MSG_TRUNC|MSG_DONTWAIT|MSG_NOSIGNAL); + if (len >= 0 || errno != EINVAL) return len; + } + #else + UNUSED(family); + UNUSED(so_type); + #endif + return read(fd, buf, sz); +} + + #include <sys/ioctl.h> #ifdef HAVE_SYS_FILIO_H #include <sys/filio.h> /* FIONREAD (for illumos (OpenIndiana)) */ |