Commit e30cbe78 by eqy Committed by Tianqi Chen

check in (#2484)

parent 65548f99
...@@ -175,7 +175,8 @@ class Socket { ...@@ -175,7 +175,8 @@ class Socket {
*/ */
void Bind(const SockAddr &addr) { void Bind(const SockAddr &addr) {
if (bind(sockfd, reinterpret_cast<const sockaddr*>(&addr.addr), if (bind(sockfd, reinterpret_cast<const sockaddr*>(&addr.addr),
sizeof(addr.addr)) == -1) { (addr.addr.ss_family == AF_INET6 ? sizeof(sockaddr_in6) :
sizeof(sockaddr_in))) == -1) {
Socket::Error("Bind"); Socket::Error("Bind");
} }
} }
...@@ -189,7 +190,8 @@ class Socket { ...@@ -189,7 +190,8 @@ class Socket {
for (int port = start_port; port < end_port; ++port) { for (int port = start_port; port < end_port; ++port) {
SockAddr addr("0.0.0.0", port); SockAddr addr("0.0.0.0", port);
if (bind(sockfd, reinterpret_cast<sockaddr*>(&addr.addr), if (bind(sockfd, reinterpret_cast<sockaddr*>(&addr.addr),
sizeof(addr.addr)) == 0) { (addr.addr.ss_family == AF_INET6 ? sizeof(sockaddr_in6) :
sizeof(sockaddr_in))) == 0) {
return port; return port;
} }
#if defined(_WIN32) #if defined(_WIN32)
...@@ -371,7 +373,8 @@ class TCPSocket : public Socket { ...@@ -371,7 +373,8 @@ class TCPSocket : public Socket {
*/ */
bool Connect(const SockAddr &addr) { bool Connect(const SockAddr &addr) {
return connect(sockfd, reinterpret_cast<const sockaddr*>(&addr.addr), return connect(sockfd, reinterpret_cast<const sockaddr*>(&addr.addr),
sizeof(addr.addr)) == 0; (addr.addr.ss_family == AF_INET6 ? sizeof(sockaddr_in6) :
sizeof(sockaddr_in))) == 0;
} }
/*! /*!
* \brief send data using the socket * \brief send data using the socket
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment