feat: add Unix domain socket (UDS) listener support#2494
Open
SBALAVIGNESH123 wants to merge 1 commit intodrogonframework:masterfrom
Open
feat: add Unix domain socket (UDS) listener support#2494SBALAVIGNESH123 wants to merge 1 commit intodrogonframework:masterfrom
SBALAVIGNESH123 wants to merge 1 commit intodrogonframework:masterfrom
Conversation
3ff642c to
df7665c
Compare
Add support for listening on Unix domain sockets, enabling lower-latency
same-host communication for reverse proxy setups (e.g., Nginx -> Drogon).
Server API:
app().addListener(/var/run/drogon.sock);
Config file:
{listeners: [{unix_socket: /var/run/drogon.sock}]}
Changes:
- Add HttpAppFramework::addListener(unixSocketPath) overload (POSIX only)
- Add ListenerManager::addUnixListener() with UDS HttpServer creation
- Add ConfigLoader support for 'unix_socket' field in listener config
- Socket file is automatically cleaned up on server stop
- Includes Trantor changes: InetAddress AF_UNIX support, Socket fixes
Addresses drogonframework#1153
df7665c to
b33408b
Compare
Member
|
@SBALAVIGNESH123 please make PR to trantor first. |
Contributor
Author
|
Thanks @an-tao! I've submitted the Trantor PR here: an-tao/trantor#399 Once that's merged, I'll update the submodule pointer in this PR to reference the official Trantor commit. |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #1153
This PR adds native Unix domain socket support to Drogon. Unix domain sockets provide significantly lower latency than TCP for same-host communication, making them ideal for reverse proxy setups like Nginx → Drogon. This has been a requested feature since issue #1153 was opened back in January 2022.
The implementation spans both Drogon and Trantor. On the Trantor side, I extended
InetAddresswith asockaddr_ununion member and added a new constructor for Unix domain socket paths, along with helper methods likeisUnixDomain()andtoUnixPath(). TheSocketclass was updated to useprotocol = 0instead ofIPPROTO_TCPwhen creating AF_UNIX sockets, and I madebind()UDS-aware — it removes any stale socket file before binding and setschmod 0660permissions afterward. Theaccept()path now usessockaddr_storage(110 bytes) instead ofsockaddr_in6(28 bytes) to accommodate the largersockaddr_unstructure, andTCP_NODELAYis correctly skipped for UDS connections since it only applies to TCP.On the Drogon side, I added a new
addListener(const std::string &unixSocketPath)overload toHttpAppFrameworkthat takes just a socket path. TheListenerManagercreates and manages UDS listeners alongside existing TCP listeners, and automatically cleans up socket files viaunlink()when the server stops. JSON configuration is also supported through a"unix_socket"key in the listeners array.Usage is straightforward — either programmatic: