Index: net/socket/tcp_server_socket_libevent.cc |
diff --git a/net/socket/tcp_server_socket_libevent.cc b/net/socket/tcp_server_socket_libevent.cc |
index ef8d1b1bcbef21f851decf142c01181d9c5e1c30..3249889869f8ce2f263ddc59c9c995b3a683bfc9 100644 |
--- a/net/socket/tcp_server_socket_libevent.cc |
+++ b/net/socket/tcp_server_socket_libevent.cc |
@@ -35,6 +35,7 @@ TCPServerSocketLibevent::TCPServerSocketLibevent( |
const net::NetLog::Source& source) |
: socket_(kInvalidSocket), |
accept_socket_(NULL), |
+ reuse_address_(false), |
net_log_(BoundNetLog::Make(net_log, NetLog::SOURCE_SOCKET)) { |
net_log_.BeginEvent(NetLog::TYPE_SOCKET_ALIVE, |
source.ToEventParametersCallback()); |
@@ -63,11 +64,16 @@ int TCPServerSocketLibevent::Listen(const IPEndPoint& address, int backlog) { |
return result; |
} |
+ int result = SetSocketOptions(); |
+ if (result < 0) { |
wtc
2012/09/13 18:31:55
result < 0 => result != OK
Note: although SetSock
justinlin
2012/09/14 03:54:40
Done. Nice catch.
|
+ return result; |
+ } |
+ |
SockaddrStorage storage; |
if (!address.ToSockAddr(storage.addr, &storage.addr_len)) |
return ERR_INVALID_ARGUMENT; |
- int result = bind(socket_, storage.addr, storage.addr_len); |
+ result = bind(socket_, storage.addr, storage.addr_len); |
if (result < 0) { |
PLOG(ERROR) << "bind() returned an error"; |
result = MapSystemError(errno); |
@@ -125,6 +131,24 @@ int TCPServerSocketLibevent::Accept( |
return result; |
} |
+void TCPServerSocketLibevent::AllowAddressReuse() { |
+ DCHECK(CalledOnValidThread()); |
+ DCHECK_EQ(socket_, kInvalidSocket); |
+ |
+ reuse_address_ = true; |
+} |
+ |
+int TCPServerSocketLibevent::SetSocketOptions() { |
+ int true_value = 1; |
+ if (reuse_address_) { |
+ int rv = setsockopt(socket_, SOL_SOCKET, SO_REUSEADDR, &true_value, |
+ sizeof(true_value)); |
+ if (rv < 0) |
+ return MapSystemError(errno); |
wtc
2012/09/13 18:31:55
Why didn't you copy the following code from tcp_cl
Sergey Ulanov
2012/09/13 22:08:45
I actually don't think we really need this. Yuri a
wtc
2012/09/14 02:36:12
Thank you. Then we should not copy the SO_REUSEPOR
|
+ } |
+ return OK; |
+} |
+ |
int TCPServerSocketLibevent::AcceptInternal( |
scoped_ptr<StreamSocket>* socket) { |
SockaddrStorage storage; |