From 15f69910646cf3643ec24c05019971950b7738ae Mon Sep 17 00:00:00 2001 From: sanikoyes Date: Tue, 13 Oct 2015 13:11:33 +0800 Subject: [PATCH] REUSE_ADDR under windows platform --- platform/windows/tcp_server_winsock.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/platform/windows/tcp_server_winsock.cpp b/platform/windows/tcp_server_winsock.cpp index bf7e85aebbb..cc689d9dcfa 100644 --- a/platform/windows/tcp_server_winsock.cpp +++ b/platform/windows/tcp_server_winsock.cpp @@ -79,6 +79,13 @@ Error TCPServerWinsock::listen(uint16_t p_port,const List *p_accepted_ho my_addr.sin_addr.s_addr = INADDR_ANY; // automatically fill with my IP TODO: use p_accepted_hosts memset(my_addr.sin_zero, '\0', sizeof my_addr.sin_zero); + int reuse=1; + if(setsockopt(sockfd, SOL_SOCKET, SO_REUSEADDR, (char *)&reuse, sizeof(reuse)) < 0) { + + printf("REUSEADDR failed!"); + } + + if (bind(sockfd, (struct sockaddr *)&my_addr, sizeof my_addr) != SOCKET_ERROR) { if (::listen(sockfd, SOMAXCONN) == SOCKET_ERROR) {