Skip to content

Commit

Permalink
check in (#2484)
Browse files Browse the repository at this point in the history
  • Loading branch information
eqy authored and tqchen committed Jan 24, 2019
1 parent 65548f9 commit e30cbe7
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/common/socket.h
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,8 @@ class Socket {
*/
void Bind(const SockAddr &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");
}
}
Expand All @@ -189,7 +190,8 @@ class Socket {
for (int port = start_port; port < end_port; ++port) {
SockAddr addr("0.0.0.0", port);
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;
}
#if defined(_WIN32)
Expand Down Expand Up @@ -371,7 +373,8 @@ class TCPSocket : public Socket {
*/
bool Connect(const SockAddr &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
Expand Down

0 comments on commit e30cbe7

Please sign in to comment.