Overview
| Artifact ID: | 0cbc126208fadd9c1b2435d706282bdee7e65ea0 |
|---|---|
| Ticket: | 0b9d3ba2ba3e1e3fc33c97d5a9fa7ef85d11a696
Support for reuseport for UNIX sockets |
| User & Date: | cklein on 2016-11-17 17:13:28 |
Changes
- assignee changed to: "nobody"
- closer changed to: "nobody"
- cmimetype changed to: "text/plain"
- comment changed to:
Support for reuseport for UNIX sockets. The new socket option allows multiple sockets on the same host to bind to the same port, and is intended to improve the performance of multithreaded network server applications running on top of multicore systems. Without reuseport, you get the error: "couldn't open socket: address already in use" Patch: Index: unix/tclUnixSock.c ================================================================== --- unix/tclUnixSock.c +++ unix/tclUnixSock.c @@ -1428,10 +1428,13 @@ /* Callback for accepting connections from new * clients. */ ClientData acceptProcData) /* Data for the callback. */ { int status = 0, sock = -1, reuseaddr = 1, chosenport; +#ifdef SO_REUSEPORT + int reuseport = 1; +#endif struct addrinfo *addrlist = NULL, *addrPtr; /* socket address */ TcpState *statePtr = NULL; char channelName[SOCK_CHAN_LENGTH]; const char *errorMsg = NULL; TcpFdList *fds = NULL, *newfds; @@ -1510,17 +1513,26 @@ */ (void) setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, (char *) &reuseaddr, sizeof(reuseaddr)); +#ifdef SO_REUSEPORT + /* + * Set up to allows multiple sockets on the same host to bind to the same port. + */ + + (void) setsockopt(sock, SOL_SOCKET, SO_REUSEPORT, + (char *) &reuseport, sizeof(reuseport)); + /* * Make sure we use the same port number when opening two server * sockets for IPv4 and IPv6 on a random port. * * As sockaddr_in6 uses the same offset and size for the port member * as sockaddr_in, we can handle both through the IPv4 API. */ +#endif if (port == 0 && chosenport != 0) { ((struct sockaddr_in *) addrPtr->ai_addr)->sin_port = htons(chosenport); } - is_private changed to: "0"
- login: "cklein"
- priority changed to: "5 Medium"
- private_contact changed to: "a15d90ba80f978cae526596013adf440a5f1f255"
- resolution changed to: "None"
- severity changed to: "Minor"
- status changed to: "Open"
- submitter changed to: "cklein"
- subsystem changed to: "None"
- title changed to: "Support for reuseport for UNIX sockets"
- type changed to: "Patch"