Skip to content

Commit

Permalink
Resolve remote peer prior to opening server socket
Browse files Browse the repository at this point in the history
This is important to prevent leaking server socket descriptor in case createIPClientSocket throws
  • Loading branch information
g-arjones committed Sep 8, 2016
1 parent e27bf48 commit bda3042
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions src/Driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -353,13 +353,12 @@ void Driver::openUDPBidirectional(std::string const& hostname, int out_port, int
out_hints.ai_family = AF_UNSPEC; /* Allow IPv4 or IPv6 */
out_hints.ai_socktype = SOCK_DGRAM; /* Datagram socket */

int sfd = createIPServerSocket(in_port, in_hints);

struct sockaddr peer;
size_t peer_len;
int peerfd = createIPClientSocket(hostname.c_str(), boost::lexical_cast<string>(out_port).c_str(), out_hints, &peer, &peer_len);

::close(peerfd);

int sfd = createIPServerSocket(in_port, in_hints);
setMainStream(new UDPServerStream(sfd, true, &peer, &peer_len));
}

Expand Down

0 comments on commit bda3042

Please sign in to comment.