Commit 5333a914 authored by Sean Cannella's avatar Sean Cannella Committed by Noam Lerner

SocketAddress::anyAddress should be a method

Summary:
Calling getaddrinfo from a static constructor is not the most
reliable thing to do. Stop doing it.

Test Plan: existing tests

Reviewed By: davejwatson@fb.com

Subscribers: dancol, mzlee, shikong, kmdent, fma, bmatheny, benyluo, ranjeeth, folly-diffs@, jsedgwick, yfeldblum

FB internal diff: D1924578

Tasks: 6534662

Signature: t1:1924578:1426718586:d73bc2f001095e66fa77fde9c027af050cc26d2a
parent efecbe5f
......@@ -308,7 +308,7 @@ class AsyncSSLSocket : public virtual AsyncSocket {
const folly::SocketAddress& address,
int timeout = 0,
const OptionMap &options = emptyOptionMap,
const folly::SocketAddress& bindAddr = anyAddress)
const folly::SocketAddress& bindAddr = anyAddress())
noexcept override;
using AsyncSocket::connect;
......
......@@ -37,8 +37,6 @@ namespace folly {
// static members initializers
const AsyncSocket::OptionMap AsyncSocket::emptyOptionMap;
const folly::SocketAddress AsyncSocket::anyAddress =
folly::SocketAddress("0.0.0.0", 0);
const AsyncSocketException socketClosedLocallyEx(
AsyncSocketException::END_OF_FILE, "socket closed locally");
......@@ -273,6 +271,12 @@ int AsyncSocket::detachFd() {
return fd;
}
const folly::SocketAddress& AsyncSocket::anyAddress() {
static const folly::SocketAddress anyAddress =
folly::SocketAddress("0.0.0.0", 0);
return anyAddress;
}
void AsyncSocket::setShutdownSocketSet(ShutdownSocketSet* newSS) {
if (shutdownSocketSet_ == newSS) {
return;
......@@ -371,7 +375,7 @@ void AsyncSocket::connect(ConnectCallback* callback,
<< ", fd=" << fd_ << ", host=" << address.describe().c_str();
// bind the socket
if (bindAddr != anyAddress) {
if (bindAddr != anyAddress()) {
int one = 1;
if (::setsockopt(fd_, SOL_SOCKET, SO_REUSEADDR, &one, sizeof(one))) {
doClose();
......
......@@ -238,7 +238,7 @@ class AsyncSocket : virtual public AsyncTransportWrapper {
typedef std::map<OptionKey, int> OptionMap;
static const OptionMap emptyOptionMap;
static const folly::SocketAddress anyAddress;
static const folly::SocketAddress& anyAddress();
/**
* Initiate a connection.
......@@ -254,7 +254,7 @@ class AsyncSocket : virtual public AsyncTransportWrapper {
const folly::SocketAddress& address,
int timeout = 0,
const OptionMap &options = emptyOptionMap,
const folly::SocketAddress& bindAddr = anyAddress
const folly::SocketAddress& bindAddr = anyAddress()
) noexcept;
void connect(ConnectCallback* callback, const std::string& ip, uint16_t port,
int timeout = 00,
......
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