… | |
… | |
1052 | defined wantarray && guard { %state = () } |
1052 | defined wantarray && guard { %state = () } |
1053 | } |
1053 | } |
1054 | |
1054 | |
1055 | =item $guard = tcp_server $host, $service, $accept_cb[, $prepare_cb] |
1055 | =item $guard = tcp_server $host, $service, $accept_cb[, $prepare_cb] |
1056 | |
1056 | |
1057 | Create and bind a stream socket to the given host, and port, set the |
1057 | Create and bind a stream socket to the given host address and port, set |
1058 | SO_REUSEADDR flag (if applicable) and call C<listen>. Unlike the name |
1058 | the SO_REUSEADDR flag (if applicable) and call C<listen>. Unlike the name |
1059 | implies, this function can also bind on UNIX domain sockets. |
1059 | implies, this function can also bind on UNIX domain sockets. |
1060 | |
1060 | |
1061 | For internet sockets, C<$host> must be an IPv4 or IPv6 address (or |
1061 | For internet sockets, C<$host> must be an IPv4 or IPv6 address (or |
1062 | C<undef>, in which case it binds either to C<0> or to C<::>, depending |
1062 | C<undef>, in which case it binds either to C<0> or to C<::>, depending |
1063 | on whether IPv4 or IPv6 is the preferred protocol, and maybe to both in |
1063 | on whether IPv4 or IPv6 is the preferred protocol, and maybe to both in |
1064 | future versions, as applicable). |
1064 | future versions, as applicable). |
1065 | |
1065 | |
1066 | To bind to the IPv4 wildcard address, use C<0>, to bind to the IPv6 |
1066 | To bind to the IPv4 wildcard address, use C<0>, to bind to the IPv6 |
1067 | wildcard address, use C<::>. |
1067 | wildcard address, use C<::>. |
1068 | |
1068 | |
1069 | The port is specified by C<$service>, which must be either a service name or |
1069 | The port is specified by C<$service>, which must be either a service name |
1070 | a numeric port number (or C<0> or C<undef>, in which case an ephemeral |
1070 | or a numeric port number (or C<0> or C<undef>, in which case an ephemeral |
1071 | port will be used). |
1071 | port will be used). |
1072 | |
1072 | |
1073 | For UNIX domain sockets, C<$host> must be C<unix/> and C<$service> must be |
1073 | For UNIX domain sockets, C<$host> must be C<unix/> and C<$service> must be |
1074 | the absolute pathname of the socket. This function will try to C<unlink> |
1074 | the absolute pathname of the socket. This function will try to C<unlink> |
1075 | the socket before it tries to bind to it, and will try to unlink it after |
1075 | the socket before it tries to bind to it, and will try to unlink it after |