X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/385ebb5d8109bbdfa60137ccd650d7c78e0747e5..0c09451870888f9c774f86d9a34ac348d41d2da9:/src/unix/gsocket.cpp diff --git a/src/unix/gsocket.cpp b/src/unix/gsocket.cpp index d417f12da8..8bf9517551 100644 --- a/src/unix/gsocket.cpp +++ b/src/unix/gsocket.cpp @@ -36,14 +36,6 @@ #include #include #endif -#ifdef __NETBSD__ -#ifndef _NETBSD_SOURCE -#define _NETBSD_SOURCE -#endif -#ifndef _LIBC -#define _LIBC -#endif -#endif #include #include @@ -307,7 +299,7 @@ struct hostent * wxGethostbyaddr_r(const char *addr_buf, int buf_size, return he; } -#if defined(HAVE_GETHOSTBYNAME) +#if defined(HAVE_GETSERVBYNAME) static struct servent * deepCopyServent(struct servent *s, const struct servent *se, char *buffer, int size) @@ -699,7 +691,12 @@ GSocketError GSocket::SetServer() state after being previously closed. */ if (m_reusable) + { setsockopt(m_fd, SOL_SOCKET, SO_REUSEADDR, (const char*)&arg, sizeof(u_long)); +#ifdef SO_REUSEPORT + setsockopt(m_fd, SOL_SOCKET, SO_REUSEPORT, (const char*)&arg, sizeof(u_long)); +#endif + } /* Bind to the local address, * retrieve the actual address bound, @@ -898,6 +895,21 @@ GSocketError GSocket::Connect(GSocketStream stream) ioctl(m_fd, FIONBIO, &arg); #endif + // If the reuse flag is set, use the applicable socket reuse flags(s) + if (m_reusable) + { + setsockopt(m_fd, SOL_SOCKET, SO_REUSEADDR, (const char*)&arg, sizeof(u_long)); +#ifdef SO_REUSEPORT + setsockopt(m_fd, SOL_SOCKET, SO_REUSEPORT, (const char*)&arg, sizeof(u_long)); +#endif + } + + // If a local address has been set, then we need to bind to it before calling connect + if (m_local && m_local->m_addr) + { + bind(m_fd, m_local->m_addr, m_local->m_len); + } + /* Connect it to the peer address, with a timeout (see below) */ ret = connect(m_fd, m_peer->m_addr, m_peer->m_len);