Bug 1093025: Initialize listen socket only once in |UnixSocketWatcher::Listen|, r=kyle

Sockets in listen mode may only be created and bound once. This patch fixes
|unixSocketWatcher::Listen| to respect these contraints. Listening more than
once will reuse the settings from the first listen operation.
This commit is contained in:
Thomas Zimmermann 2014-12-02 15:00:35 -08:00
parent a4c3938959
commit 602c829f2e

View File

@ -53,13 +53,16 @@ UnixSocketWatcher::Listen(const struct sockaddr* aAddr, socklen_t aAddrLen)
MOZ_ASSERT(IsOpen());
MOZ_ASSERT(aAddr || !aAddrLen);
if (bind(GetFd(), aAddr, aAddrLen) < 0) {
OnError("bind", errno);
return NS_ERROR_FAILURE;
}
if (listen(GetFd(), 1) < 0) {
OnError("listen", errno);
return NS_ERROR_FAILURE;
if (mConnectionStatus == SOCKET_IS_DISCONNECTED) {
// We init the socket descriptor when we listen for the first time.
if (bind(GetFd(), aAddr, aAddrLen) < 0) {
OnError("bind", errno);
return NS_ERROR_FAILURE;
}
if (listen(GetFd(), 1) < 0) {
OnError("listen", errno);
return NS_ERROR_FAILURE;
}
}
mConnectionStatus = SOCKET_IS_LISTENING;
OnListening();