Bug 1164425: Cleanup interfaces of |StreamSocket|, r=kmachulis
This patch cleans up the interface of |StreamSocket|. All arguments that contain protocol parameters are removed from |Connect|. They are stored in the connector class. |Connect| now returns error codes. The method |GetSocketAddr| is unused and not thread-safe and therefore removed. The method |SendSocketData| for strings is unused and removed.
This commit is contained in:
@@ -37,8 +37,6 @@ public:
|
||||
UnixSocketConnector* aConnector);
|
||||
~StreamSocketIO();
|
||||
|
||||
void GetSocketAddr(nsAString& aAddrStr) const;
|
||||
|
||||
StreamSocket* GetStreamSocket();
|
||||
DataSocket* GetDataSocket();
|
||||
|
||||
@@ -169,26 +167,6 @@ StreamSocketIO::~StreamSocketIO()
|
||||
MOZ_ASSERT(IsShutdownOnMainThread());
|
||||
}
|
||||
|
||||
void
|
||||
StreamSocketIO::GetSocketAddr(nsAString& aAddrStr) const
|
||||
{
|
||||
if (!mConnector) {
|
||||
NS_WARNING("No connector to get socket address from!");
|
||||
aAddrStr.Truncate();
|
||||
return;
|
||||
}
|
||||
|
||||
nsCString addressString;
|
||||
nsresult rv = mConnector->ConvertAddressToString(
|
||||
*reinterpret_cast<const struct sockaddr*>(&mAddress), mAddressLength,
|
||||
addressString);
|
||||
if (NS_FAILED(rv)) {
|
||||
return;
|
||||
}
|
||||
|
||||
aAddrStr.Assign(NS_ConvertUTF8toUTF16(addressString));
|
||||
}
|
||||
|
||||
StreamSocket*
|
||||
StreamSocketIO::GetStreamSocket()
|
||||
{
|
||||
@@ -530,47 +508,17 @@ StreamSocket::~StreamSocket()
|
||||
MOZ_ASSERT(!mIO);
|
||||
}
|
||||
|
||||
bool
|
||||
StreamSocket::SendSocketData(const nsACString& aStr)
|
||||
{
|
||||
if (aStr.Length() > MAX_READ_SIZE) {
|
||||
return false;
|
||||
}
|
||||
|
||||
SendSocketData(new UnixSocketRawData(aStr.BeginReading(), aStr.Length()));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void
|
||||
StreamSocket::GetSocketAddr(nsAString& aAddrStr)
|
||||
{
|
||||
aAddrStr.Truncate();
|
||||
if (!mIO || GetConnectionStatus() != SOCKET_CONNECTED) {
|
||||
NS_WARNING("No socket currently open!");
|
||||
return;
|
||||
}
|
||||
mIO->GetSocketAddr(aAddrStr);
|
||||
}
|
||||
|
||||
bool
|
||||
nsresult
|
||||
StreamSocket::Connect(UnixSocketConnector* aConnector,
|
||||
const char* aAddress,
|
||||
int aDelayMs)
|
||||
{
|
||||
MOZ_ASSERT(aConnector);
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
|
||||
nsAutoPtr<UnixSocketConnector> connector(aConnector);
|
||||
|
||||
if (mIO) {
|
||||
NS_WARNING("Socket already connecting/connected!");
|
||||
return false;
|
||||
}
|
||||
MOZ_ASSERT(!mIO);
|
||||
|
||||
MessageLoop* ioLoop = XRE_GetIOMessageLoop();
|
||||
mIO = new StreamSocketIO(ioLoop, this, connector.forget());
|
||||
mIO = new StreamSocketIO(ioLoop, this, aConnector);
|
||||
SetConnectionStatus(SOCKET_CONNECTING);
|
||||
|
||||
if (aDelayMs > 0) {
|
||||
StreamSocketIO::DelayedConnectTask* connectTask =
|
||||
new StreamSocketIO::DelayedConnectTask(mIO);
|
||||
@@ -579,8 +527,7 @@ StreamSocket::Connect(UnixSocketConnector* aConnector,
|
||||
} else {
|
||||
ioLoop->PostTask(FROM_HERE, new StreamSocketIO::ConnectTask(mIO));
|
||||
}
|
||||
|
||||
return true;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
ConnectionOrientedSocketIO*
|
||||
@@ -620,16 +567,13 @@ void
|
||||
StreamSocket::Close()
|
||||
{
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
|
||||
if (!mIO) {
|
||||
return;
|
||||
}
|
||||
MOZ_ASSERT(mIO);
|
||||
|
||||
mIO->CancelDelayedConnectTask();
|
||||
|
||||
// From this point on, we consider mIO as being deleted.
|
||||
// We sever the relationship here so any future calls to listen or connect
|
||||
// will create a new implementation.
|
||||
// From this point on, we consider |mIO| as being deleted. We sever
|
||||
// the relationship here so any future calls to |Connect| will create
|
||||
// a new I/O object.
|
||||
mIO->ShutdownOnMainThread();
|
||||
|
||||
XRE_GetIOMessageLoop()->PostTask(FROM_HERE, new SocketIOShutdownTask(mIO));
|
||||
|
||||
Reference in New Issue
Block a user