diff --git a/dom/bluetooth/bluedroid/BluetoothSocket.cpp b/dom/bluetooth/bluedroid/BluetoothSocket.cpp index 9ef9b904082..1122885010f 100644 --- a/dom/bluetooth/bluedroid/BluetoothSocket.cpp +++ b/dom/bluetooth/bluedroid/BluetoothSocket.cpp @@ -337,7 +337,7 @@ DroidSocketImpl::OnSocketCanReceiveWithoutBlocking(int aFd) MOZ_ASSERT(!NS_IsMainThread()); MOZ_ASSERT(!mShuttingDownOnIOThread); - ssize_t res = ReceiveData(aFd, this); + ssize_t res = ReceiveData(aFd); if (res < 0) { /* I/O error */ RemoveWatchers(READ_WATCHER|WRITE_WATCHER); @@ -475,7 +475,7 @@ DroidSocketImpl::OnSocketCanSendWithoutBlocking(int aFd) MOZ_ASSERT(!mShuttingDownOnIOThread); MOZ_ASSERT(aFd >= 0); - nsresult rv = SendPendingData(aFd, this); + nsresult rv = SendPendingData(aFd); if (NS_FAILED(rv)) { return; } diff --git a/dom/bluetooth/bluez/BluetoothSocket.cpp b/dom/bluetooth/bluez/BluetoothSocket.cpp index c10fbf45840..9bdd905ffa0 100644 --- a/dom/bluetooth/bluez/BluetoothSocket.cpp +++ b/dom/bluetooth/bluez/BluetoothSocket.cpp @@ -418,7 +418,7 @@ BluetoothSocket::BluetoothSocketIO::OnSocketCanReceiveWithoutBlocking() MOZ_ASSERT(MessageLoopForIO::current() == GetIOLoop()); MOZ_ASSERT(GetConnectionStatus() == SOCKET_IS_CONNECTED); // see bug 990984 - ssize_t res = ReceiveData(GetFd(), this); + ssize_t res = ReceiveData(GetFd()); if (res < 0) { /* I/O error */ RemoveWatchers(READ_WATCHER|WRITE_WATCHER); @@ -434,7 +434,7 @@ BluetoothSocket::BluetoothSocketIO::OnSocketCanSendWithoutBlocking() MOZ_ASSERT(MessageLoopForIO::current() == GetIOLoop()); MOZ_ASSERT(GetConnectionStatus() == SOCKET_IS_CONNECTED); // see bug 990984 - nsresult rv = SendPendingData(GetFd(), this); + nsresult rv = SendPendingData(GetFd()); if (NS_FAILED(rv)) { return; } diff --git a/ipc/unixsocket/DataSocket.cpp b/ipc/unixsocket/DataSocket.cpp index f153f8419c2..c9a4d95d2f6 100644 --- a/ipc/unixsocket/DataSocket.cpp +++ b/ipc/unixsocket/DataSocket.cpp @@ -7,6 +7,13 @@ */ #include "mozilla/ipc/DataSocket.h" +#ifdef MOZ_TASK_TRACER +#include "GeckoTaskTracer.h" +#endif + +#ifdef MOZ_TASK_TRACER +using namespace mozilla::tasktracer; +#endif namespace mozilla { namespace ipc { @@ -34,6 +41,70 @@ DataSocketIO::HasPendingData() const return !mOutgoingQ.IsEmpty(); } +ssize_t +DataSocketIO::ReceiveData(int aFd) +{ + MOZ_ASSERT(aFd >= 0); + + UnixSocketIOBuffer* incoming; + nsresult rv = QueryReceiveBuffer(&incoming); + if (NS_FAILED(rv)) { + /* an error occured */ + NS_DispatchToMainThread(new SocketIORequestClosingRunnable(this)); + return -1; + } + + ssize_t res = incoming->Receive(aFd); + if (res < 0) { + /* an I/O error occured */ + DiscardBuffer(); + NS_DispatchToMainThread(new SocketIORequestClosingRunnable(this)); + return -1; + } else if (!res) { + /* EOF or peer shut down sending */ + DiscardBuffer(); + NS_DispatchToMainThread(new SocketIORequestClosingRunnable(this)); + return 0; + } + +#ifdef MOZ_TASK_TRACER + /* Make unix socket creation events to be the source events of TaskTracer, + * and originate the rest correlation tasks from here. + */ + AutoSourceEvent taskTracerEvent(SourceEventType::Unixsocket); +#endif + + ConsumeBuffer(); + + return res; +} + +nsresult +DataSocketIO::SendPendingData(int aFd) +{ + MOZ_ASSERT(aFd >= 0); + + while (HasPendingData()) { + UnixSocketIOBuffer* outgoing = mOutgoingQ.ElementAt(0); + + ssize_t res = outgoing->Send(aFd); + if (res < 0) { + /* an I/O error occured */ + NS_DispatchToMainThread(new SocketIORequestClosingRunnable(this)); + return NS_ERROR_FAILURE; + } else if (!res && outgoing->GetSize()) { + /* I/O is currently blocked; try again later */ + return NS_OK; + } + if (!outgoing->GetSize()) { + mOutgoingQ.RemoveElementAt(0); + delete outgoing; + } + } + + return NS_OK; +} + DataSocketIO::DataSocketIO() { } diff --git a/ipc/unixsocket/DataSocket.h b/ipc/unixsocket/DataSocket.h index 47fd34f8896..db9ac506f5d 100644 --- a/ipc/unixsocket/DataSocket.h +++ b/ipc/unixsocket/DataSocket.h @@ -85,70 +85,9 @@ public: void EnqueueData(UnixSocketIOBuffer* aBuffer); bool HasPendingData() const; - template - ssize_t ReceiveData(int aFd, T* aIO) - { - MOZ_ASSERT(aFd >= 0); - MOZ_ASSERT(aIO); + ssize_t ReceiveData(int aFd); - UnixSocketIOBuffer* incoming; - nsresult rv = QueryReceiveBuffer(&incoming); - if (NS_FAILED(rv)) { - /* an error occured */ - NS_DispatchToMainThread(new SocketIORequestClosingRunnable(aIO)); - return -1; - } - - ssize_t res = incoming->Receive(aFd); - if (res < 0) { - /* an I/O error occured */ - DiscardBuffer(); - NS_DispatchToMainThread(new SocketIORequestClosingRunnable(aIO)); - return -1; - } else if (!res) { - /* EOF or peer shut down sending */ - DiscardBuffer(); - NS_DispatchToMainThread(new SocketIORequestClosingRunnable(aIO)); - return 0; - } - -#ifdef MOZ_TASK_TRACER - // Make unix socket creation events to be the source events of TaskTracer, - // and originate the rest correlation tasks from here. - AutoSourceEvent taskTracerEvent(SourceEventType::Unixsocket); -#endif - - ConsumeBuffer(); - - return res; - } - - template - nsresult SendPendingData(int aFd, T* aIO) - { - MOZ_ASSERT(aFd >= 0); - MOZ_ASSERT(aIO); - - while (HasPendingData()) { - UnixSocketIOBuffer* outgoing = mOutgoingQ.ElementAt(0); - - ssize_t res = outgoing->Send(aFd); - if (res < 0) { - /* an I/O error occured */ - NS_DispatchToMainThread(new SocketIORequestClosingRunnable(aIO)); - return NS_ERROR_FAILURE; - } else if (!res && outgoing->GetSize()) { - /* I/O is currently blocked; try again later */ - return NS_OK; - } - if (!outgoing->GetSize()) { - mOutgoingQ.RemoveElementAt(0); - delete outgoing; - } - } - - return NS_OK; - } + nsresult SendPendingData(int aFd); protected: DataSocketIO(); diff --git a/ipc/unixsocket/SocketBase.h b/ipc/unixsocket/SocketBase.h index 8f6967acbeb..9d8793b2dcf 100644 --- a/ipc/unixsocket/SocketBase.h +++ b/ipc/unixsocket/SocketBase.h @@ -14,11 +14,6 @@ #include "nsTArray.h" #include "nsThreadUtils.h" -#ifdef MOZ_TASK_TRACER -#include "GeckoTaskTracer.h" -using namespace mozilla::tasktracer; -#endif - namespace mozilla { namespace ipc { diff --git a/ipc/unixsocket/StreamSocket.cpp b/ipc/unixsocket/StreamSocket.cpp index 241014747cc..8cd6b975543 100644 --- a/ipc/unixsocket/StreamSocket.cpp +++ b/ipc/unixsocket/StreamSocket.cpp @@ -433,7 +433,7 @@ StreamSocketIO::OnSocketCanReceiveWithoutBlocking() MOZ_ASSERT(MessageLoopForIO::current() == GetIOLoop()); MOZ_ASSERT(GetConnectionStatus() == SOCKET_IS_CONNECTED); // see bug 990984 - ssize_t res = ReceiveData(GetFd(), this); + ssize_t res = ReceiveData(GetFd()); if (res < 0) { /* I/O error */ RemoveWatchers(READ_WATCHER|WRITE_WATCHER); @@ -449,7 +449,7 @@ StreamSocketIO::OnSocketCanSendWithoutBlocking() MOZ_ASSERT(MessageLoopForIO::current() == GetIOLoop()); MOZ_ASSERT(GetConnectionStatus() == SOCKET_IS_CONNECTED); // see bug 990984 - nsresult rv = SendPendingData(GetFd(), this); + nsresult rv = SendPendingData(GetFd()); if (NS_FAILED(rv)) { return; }