@@ -1480,6 +1480,8 @@ using SocketOptions = std::function<void(socket_t sock)>;
14801480
14811481void default_socket_options(socket_t sock);
14821482
1483+ bool set_socket_opt(socket_t sock, int level, int optname, int optval);
1484+
14831485const char *status_message(int status);
14841486
14851487std::string to_string(Error error);
@@ -4338,10 +4340,6 @@ inline bool set_socket_opt_impl(socket_t sock, int level, int optname,
43384340 optlen) == 0;
43394341}
43404342
4341- inline bool set_socket_opt(socket_t sock, int level, int optname, int optval) {
4342- return set_socket_opt_impl(sock, level, optname, &optval, sizeof(optval));
4343- }
4344-
43454343inline bool set_socket_opt_time(socket_t sock, int level, int optname,
43464344 time_t sec, time_t usec) {
43474345#ifdef _WIN32
@@ -6089,7 +6087,7 @@ socket_t create_socket(const std::string &host, const std::string &ip, int port,
60896087#ifdef _WIN32
60906088 // Setting SO_REUSEADDR seems not to work well with AF_UNIX on windows, so
60916089 // remove the option.
6092- detail:: set_socket_opt(sock, SOL_SOCKET, SO_REUSEADDR, 0);
6090+ set_socket_opt(sock, SOL_SOCKET, SO_REUSEADDR, 0);
60936091#endif
60946092
60956093 bool dummy;
@@ -9135,13 +9133,18 @@ inline bool setup_client_tls_session(const std::string &host, tls::ctx_t &ctx,
91359133 */
91369134
91379135inline void default_socket_options(socket_t sock) {
9138- detail:: set_socket_opt(sock, SOL_SOCKET,
9136+ set_socket_opt(sock, SOL_SOCKET,
91399137#ifdef SO_REUSEPORT
9140- SO_REUSEPORT,
9138+ SO_REUSEPORT,
91419139#else
9142- SO_REUSEADDR,
9140+ SO_REUSEADDR,
91439141#endif
9144- 1);
9142+ 1);
9143+ }
9144+
9145+ inline bool set_socket_opt(socket_t sock, int level, int optname, int optval) {
9146+ return detail::set_socket_opt_impl(sock, level, optname, &optval,
9147+ sizeof(optval));
91459148}
91469149
91479150inline std::string get_bearer_token_auth(const Request &req) {
@@ -11561,9 +11564,7 @@ inline bool Server::listen_internal() {
1156111564 detail::set_socket_opt_time(sock, SOL_SOCKET, SO_SNDTIMEO,
1156211565 write_timeout_sec_, write_timeout_usec_);
1156311566
11564- if (tcp_nodelay_) {
11565- detail::set_socket_opt(sock, IPPROTO_TCP, TCP_NODELAY, 1);
11566- }
11567+ if (tcp_nodelay_) { set_socket_opt(sock, IPPROTO_TCP, TCP_NODELAY, 1); }
1156711568
1156811569 if (!task_queue->enqueue(
1156911570 [this, sock]() { process_and_close_socket(sock); })) {
0 commit comments