Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define _GNU_SOURCE
- #include <stdlib.h>
- #include <dlfcn.h>
- #include <sys/types.h>
- #include <sys/socket.h>
- #include <netinet/tcp.h>
- #include <netinet/in.h>
- static size_t tcp_nodelay_count;
- static size_t tcp_nodelay_errors;
- int (*socket_orig)(int domain, int type, int protocol) = NULL;
- __attribute__((constructor)) static void socket_init(void)
- {
- socket_orig = dlsym(RTLD_NEXT, "socket");
- }
- int socket(int domain, int type, int protocol)
- {
- int fd = socket_orig(domain, type, protocol);
- if (fd < 0) {
- return fd;
- }
- if (type == SOCK_STREAM) {
- int one = 1;
- ++tcp_nodelay_count;
- if (setsockopt(fd, IPPROTO_TCP, TCP_NODELAY, &one, sizeof(one))) {
- ++tcp_nodelay_errors;
- }
- }
- return fd;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement