Bug 1159209: Remove template parameters from |DataSocketIO|, r=kmachulis

This patch removes the template parameters from |DataSocketIO| and
moves its methods into the C++ source file. All users have been
adapted.
This commit is contained in:
Thomas Zimmermann 2015-04-29 11:19:28 +02:00
parent 97a6e261a2
commit 9d654e96e7
6 changed files with 79 additions and 74 deletions

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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()
{ }

View File

@ -85,70 +85,9 @@ public:
void EnqueueData(UnixSocketIOBuffer* aBuffer);
bool HasPendingData() const;
template <typename T>
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 <typename T>
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();

View File

@ -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 {

View File

@ -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;
}