mirror of
https://github.com/roytam1/palemoon27.git
synced 2026-05-26 23:06:52 +00:00
193db9294d
- Bug 1224810 - "TraceLogger: Add the script information for the event created by BytecodeCompiler". r=hv1989 (12b6891fa7)
- Bug 1227677 - Simplify emitting of comprehension variables. r=shu (4e9ea2fee7)
- bug 1223529 - remove ipc/chromium/Makefile.in. r=gps (8d71334ca0)
- Bug 1225682 - Don't use nsAuto{,C}String as class member variables in widget/. r=roc (4355625107)
- Bug 1225188. Implement window.onstorage. r=smaug (50168cdffb)
- Bug 1286158 - Add Android 64bit support for libevent. r=billm (b33cb1fccf)
- Bug 1162524: Fix error handling |UnixSocketWatcher::Connect|, r=kmachulis (04e67535b4)
- Bug 1178514 - Mark one-argument constructors in IPDL tests as 'explicit'. r=bent (cc6fde1e1c)
- some warnings stuff (68ecef6622)
- Bug 1170231: Part 1 - Remove condition that may cause deadlock in IPC when mediating interrupt races; r=dvander (79dd6902a2)
- Bug 1170231: Part 2 - Regression test for IPC race mediation deadlock; r=dvander (eabe33218f)
- Bug 1167396 - Make ProtocolCloneContext::mContentParent a smart pointer. r=bent (519ad9f47e)
- Bug 1213567: Prevent neutering from occurring during CreateWindow(Ex) calls; r=jimm (6550685051)
- Bug 1177013 - Bug fixes for CPOW cancelation (r=dvander) (b50da43c07)
- Bug 1217640 - MessageChannel::Call() should delete aMsg when the channel is not connected. r=jld (899b0e6349)
- Bug 1159037: Ensure correct parent and child message are passed to MessageListener::MediateInterruptRace; r=dvander (96c1f42029)
- Bug 1177013 - Telemetry for CPOW cancelation (r=dvander) (ec704af72c)
- Bug 1050122 - Part 2: Disable preallocate when proc loader is not initialized. r=khuey (2d35b8e25e)
137 lines
3.5 KiB
C++
137 lines
3.5 KiB
C++
/* -*- Mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 40 -*- */
|
|
/* vim: set ts=2 et sw=2 tw=80: */
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
#include <fcntl.h>
|
|
#include "UnixSocketWatcher.h"
|
|
|
|
namespace mozilla {
|
|
namespace ipc {
|
|
|
|
UnixSocketWatcher::~UnixSocketWatcher()
|
|
{
|
|
}
|
|
|
|
void UnixSocketWatcher::Close()
|
|
{
|
|
MOZ_ASSERT(MessageLoopForIO::current() == GetIOLoop());
|
|
|
|
mConnectionStatus = SOCKET_IS_DISCONNECTED;
|
|
UnixFdWatcher::Close();
|
|
}
|
|
|
|
nsresult
|
|
UnixSocketWatcher::Connect(const struct sockaddr* aAddr, socklen_t aAddrLen)
|
|
{
|
|
MOZ_ASSERT(MessageLoopForIO::current() == GetIOLoop());
|
|
MOZ_ASSERT(IsOpen());
|
|
MOZ_ASSERT(aAddr || !aAddrLen);
|
|
|
|
if (TEMP_FAILURE_RETRY(connect(GetFd(), aAddr, aAddrLen) < 0)) {
|
|
if (errno == EINPROGRESS) {
|
|
mConnectionStatus = SOCKET_IS_CONNECTING;
|
|
// Set up a write watch to receive the connect signal
|
|
AddWatchers(WRITE_WATCHER, false);
|
|
return NS_OK;
|
|
}
|
|
OnError("connect", errno);
|
|
return NS_ERROR_FAILURE;
|
|
}
|
|
|
|
mConnectionStatus = SOCKET_IS_CONNECTED;
|
|
OnConnected();
|
|
|
|
return NS_OK;
|
|
}
|
|
|
|
nsresult
|
|
UnixSocketWatcher::Listen(const struct sockaddr* aAddr, socklen_t aAddrLen)
|
|
{
|
|
MOZ_ASSERT(MessageLoopForIO::current() == GetIOLoop());
|
|
MOZ_ASSERT(IsOpen());
|
|
MOZ_ASSERT(aAddr || !aAddrLen);
|
|
|
|
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();
|
|
|
|
return NS_OK;
|
|
}
|
|
|
|
UnixSocketWatcher::UnixSocketWatcher(MessageLoop* aIOLoop)
|
|
: UnixFdWatcher(aIOLoop)
|
|
, mConnectionStatus(SOCKET_IS_DISCONNECTED)
|
|
{
|
|
}
|
|
|
|
UnixSocketWatcher::UnixSocketWatcher(MessageLoop* aIOLoop, int aFd,
|
|
ConnectionStatus aConnectionStatus)
|
|
: UnixFdWatcher(aIOLoop, aFd)
|
|
, mConnectionStatus(aConnectionStatus)
|
|
{
|
|
}
|
|
|
|
void
|
|
UnixSocketWatcher::SetSocket(int aFd, ConnectionStatus aConnectionStatus)
|
|
{
|
|
MOZ_ASSERT(MessageLoopForIO::current() == GetIOLoop());
|
|
|
|
SetFd(aFd);
|
|
mConnectionStatus = aConnectionStatus;
|
|
}
|
|
|
|
void
|
|
UnixSocketWatcher::OnFileCanReadWithoutBlocking(int aFd)
|
|
{
|
|
MOZ_ASSERT(MessageLoopForIO::current() == GetIOLoop());
|
|
MOZ_ASSERT(aFd == GetFd());
|
|
|
|
if (mConnectionStatus == SOCKET_IS_CONNECTED) {
|
|
OnSocketCanReceiveWithoutBlocking();
|
|
} else if (mConnectionStatus == SOCKET_IS_LISTENING) {
|
|
OnSocketCanAcceptWithoutBlocking();
|
|
} else {
|
|
NS_NOTREACHED("invalid connection state for reading");
|
|
}
|
|
}
|
|
|
|
void
|
|
UnixSocketWatcher::OnFileCanWriteWithoutBlocking(int aFd)
|
|
{
|
|
MOZ_ASSERT(MessageLoopForIO::current() == GetIOLoop());
|
|
MOZ_ASSERT(aFd == GetFd());
|
|
|
|
if (mConnectionStatus == SOCKET_IS_CONNECTED) {
|
|
OnSocketCanSendWithoutBlocking();
|
|
} else if (mConnectionStatus == SOCKET_IS_CONNECTING) {
|
|
RemoveWatchers(WRITE_WATCHER);
|
|
int error = 0;
|
|
socklen_t len = sizeof(error);
|
|
if (getsockopt(GetFd(), SOL_SOCKET, SO_ERROR, &error, &len) < 0) {
|
|
OnError("getsockopt", errno);
|
|
} else if (error) {
|
|
OnError("connect", error);
|
|
} else {
|
|
mConnectionStatus = SOCKET_IS_CONNECTED;
|
|
OnConnected();
|
|
}
|
|
} else {
|
|
NS_NOTREACHED("invalid connection state for writing");
|
|
}
|
|
}
|
|
|
|
}
|
|
}
|