Created
March 15, 2019 12:51
-
-
Save azat/aba9e905605b2d77aa5afc4a89cbc8c0 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment