static bool set_reuse_addr(sockfd_t sockfd) { int flag = 1; int ret = setsockopt(sockfd, SOL_SOCKET, SO_REUSEADDR, (char *)&flag, sizeof(int)); return ret == 0; } static std::shared_ptr<socket_t> socket_connect(const char * host, int port) { @@ -181,7 +187,10 @@ sta...
rpc-serveron the same port if it crashes. This can be verified like this: startrpc-server -p 50052 in some other consolenc localhost 50052 killall -9 rpc-server If you try to startrpc-serveragain (withoutSO_REUSEADDR), it will fail. With this patch, it will start successfully....
Re: Failure to set address to reuse attribute SO_REUSEADDR Quote Postby1163167506»Wed Aug 29, 2018 9:36 am my complete code: int g_sock_fd_client_model; void tcp_reconnect() { struct sockaddr_in mine,dest; int n = 0; int ret = 0; ...
* via setsockopt() without reporting an error, SO_REUSEADDR is actually * not supported for sockets of AF_UNIX. * Instead of confusing the callers by allowing this option to be set and * failing the subsequent bind() on the same socket, it's better to fail here. ...
Package greuse provides Listen and Dial functions that set socket options in order to be able to reuse ports. You should only use this package if you know what SO_REUSEADDR and SO_REUSEPORT are. Installation go get -u -v github.com/gogf/greuse ...