Skip to content

Export set_socket_opt in detail namespace#2411

Closed
angt wants to merge 1 commit intoyhirose:masterfrom
angt:export-set_socket_opt-in-detail-namespace
Closed

Export set_socket_opt in detail namespace#2411
angt wants to merge 1 commit intoyhirose:masterfrom
angt:export-set_socket_opt-in-detail-namespace

Conversation

@angt
Copy link
Copy Markdown
Contributor

@angt angt commented Mar 27, 2026

This allows users to set custom socket options without reimplementing platform specific wrappers

Signed-off-by: Adrien Gallouët <adrien@gallouet.fr>
@yhirose
Copy link
Copy Markdown
Owner

yhirose commented Mar 27, 2026

@angt does the following method meets your needs?

  Server &set_socket_options(SocketOptions socket_options);

@angt
Copy link
Copy Markdown
Contributor Author

angt commented Mar 27, 2026

@angt does the following method meets your needs?

  Server &set_socket_options(SocketOptions socket_options);

I use it to customize the setsockopt function yes, but I need to handle the Windows case myself and replicate the exact same set_socket_opt function that’s already present in the cpp file but not exported.

@yhirose
Copy link
Copy Markdown
Owner

yhirose commented Mar 27, 2026

I intentionally put set_socket_opt in the detailed namespace which is not meant to be part of the public API. However, if it would be useful, I don’t mind moving it to the public interface. Before doing so, though, I’d like to understand the full context of why the existing public method (set_socket_options) didn’t work in the particular situation.

Could you please try to resolve the issue you’re experiencing using the public method set_socket_options? If that doesn’t work, I’ll take a closer look. Thanks!

@angt
Copy link
Copy Markdown
Contributor Author

angt commented Mar 27, 2026

This was just to allow the user to have a simple code like this:

srv->set_socket_options([](socket_t sock) {
    set_socket_opt(sock, SOL_SOCKET, SO_REUSEADDR, 1);
});

instead of

srv->set_socket_options([](socket_t sock) {
    int opt = 1;
#ifdef _WIN32
    const char *optval = (const char *)&opt;
#else
    const void *optval = &opt;
#endif
    setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, optval, sizeof(opt));
});

@yhirose yhirose closed this in 6532464 Mar 28, 2026
@yhirose
Copy link
Copy Markdown
Owner

yhirose commented Mar 28, 2026

@angt I made the function public.

yhirose added a commit that referenced this pull request Mar 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants