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:
@@ -217,7 +217,7 @@ RilConsumer::RilConsumer(unsigned long aClientId,
|
|||||||
mAddress = addr_un.sun_path;
|
mAddress = addr_un.sun_path;
|
||||||
}
|
}
|
||||||
|
|
||||||
Connect(new RilConnector(mAddress, mClientId), mAddress.get());
|
Connect(new RilConnector(mAddress, mClientId));
|
||||||
}
|
}
|
||||||
|
|
||||||
nsresult
|
nsresult
|
||||||
@@ -288,10 +288,10 @@ void
|
|||||||
RilConsumer::OnDisconnect()
|
RilConsumer::OnDisconnect()
|
||||||
{
|
{
|
||||||
CHROMIUM_LOG("RIL[%lu]: %s\n", mClientId, __FUNCTION__);
|
CHROMIUM_LOG("RIL[%lu]: %s\n", mClientId, __FUNCTION__);
|
||||||
if (!mShutdown) {
|
if (mShutdown) {
|
||||||
Connect(new RilConnector(mAddress, mClientId), mAddress.get(),
|
return;
|
||||||
GetSuggestedConnectDelayMs());
|
|
||||||
}
|
}
|
||||||
|
Connect(new RilConnector(mAddress, mClientId), GetSuggestedConnectDelayMs());
|
||||||
}
|
}
|
||||||
|
|
||||||
ConnectionOrientedSocketIO*
|
ConnectionOrientedSocketIO*
|
||||||
|
|||||||
@@ -37,8 +37,6 @@ public:
|
|||||||
UnixSocketConnector* aConnector);
|
UnixSocketConnector* aConnector);
|
||||||
~StreamSocketIO();
|
~StreamSocketIO();
|
||||||
|
|
||||||
void GetSocketAddr(nsAString& aAddrStr) const;
|
|
||||||
|
|
||||||
StreamSocket* GetStreamSocket();
|
StreamSocket* GetStreamSocket();
|
||||||
DataSocket* GetDataSocket();
|
DataSocket* GetDataSocket();
|
||||||
|
|
||||||
@@ -169,26 +167,6 @@ StreamSocketIO::~StreamSocketIO()
|
|||||||
MOZ_ASSERT(IsShutdownOnMainThread());
|
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*
|
StreamSocket*
|
||||||
StreamSocketIO::GetStreamSocket()
|
StreamSocketIO::GetStreamSocket()
|
||||||
{
|
{
|
||||||
@@ -530,47 +508,17 @@ StreamSocket::~StreamSocket()
|
|||||||
MOZ_ASSERT(!mIO);
|
MOZ_ASSERT(!mIO);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
nsresult
|
||||||
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
|
|
||||||
StreamSocket::Connect(UnixSocketConnector* aConnector,
|
StreamSocket::Connect(UnixSocketConnector* aConnector,
|
||||||
const char* aAddress,
|
|
||||||
int aDelayMs)
|
int aDelayMs)
|
||||||
{
|
{
|
||||||
MOZ_ASSERT(aConnector);
|
|
||||||
MOZ_ASSERT(NS_IsMainThread());
|
MOZ_ASSERT(NS_IsMainThread());
|
||||||
|
MOZ_ASSERT(!mIO);
|
||||||
nsAutoPtr<UnixSocketConnector> connector(aConnector);
|
|
||||||
|
|
||||||
if (mIO) {
|
|
||||||
NS_WARNING("Socket already connecting/connected!");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
MessageLoop* ioLoop = XRE_GetIOMessageLoop();
|
MessageLoop* ioLoop = XRE_GetIOMessageLoop();
|
||||||
mIO = new StreamSocketIO(ioLoop, this, connector.forget());
|
mIO = new StreamSocketIO(ioLoop, this, aConnector);
|
||||||
SetConnectionStatus(SOCKET_CONNECTING);
|
SetConnectionStatus(SOCKET_CONNECTING);
|
||||||
|
|
||||||
if (aDelayMs > 0) {
|
if (aDelayMs > 0) {
|
||||||
StreamSocketIO::DelayedConnectTask* connectTask =
|
StreamSocketIO::DelayedConnectTask* connectTask =
|
||||||
new StreamSocketIO::DelayedConnectTask(mIO);
|
new StreamSocketIO::DelayedConnectTask(mIO);
|
||||||
@@ -579,8 +527,7 @@ StreamSocket::Connect(UnixSocketConnector* aConnector,
|
|||||||
} else {
|
} else {
|
||||||
ioLoop->PostTask(FROM_HERE, new StreamSocketIO::ConnectTask(mIO));
|
ioLoop->PostTask(FROM_HERE, new StreamSocketIO::ConnectTask(mIO));
|
||||||
}
|
}
|
||||||
|
return NS_OK;
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ConnectionOrientedSocketIO*
|
ConnectionOrientedSocketIO*
|
||||||
@@ -620,16 +567,13 @@ void
|
|||||||
StreamSocket::Close()
|
StreamSocket::Close()
|
||||||
{
|
{
|
||||||
MOZ_ASSERT(NS_IsMainThread());
|
MOZ_ASSERT(NS_IsMainThread());
|
||||||
|
MOZ_ASSERT(mIO);
|
||||||
if (!mIO) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
mIO->CancelDelayedConnectTask();
|
mIO->CancelDelayedConnectTask();
|
||||||
|
|
||||||
// From this point on, we consider mIO as being deleted.
|
// From this point on, we consider |mIO| as being deleted. We sever
|
||||||
// We sever the relationship here so any future calls to listen or connect
|
// the relationship here so any future calls to |Connect| will create
|
||||||
// will create a new implementation.
|
// a new I/O object.
|
||||||
mIO->ShutdownOnMainThread();
|
mIO->ShutdownOnMainThread();
|
||||||
|
|
||||||
XRE_GetIOMessageLoop()->PostTask(FROM_HERE, new SocketIOShutdownTask(mIO));
|
XRE_GetIOMessageLoop()->PostTask(FROM_HERE, new SocketIOShutdownTask(mIO));
|
||||||
|
|||||||
@@ -28,37 +28,15 @@ public:
|
|||||||
*/
|
*/
|
||||||
virtual void ReceiveSocketData(nsAutoPtr<UnixSocketBuffer>& aBuffer) = 0;
|
virtual void ReceiveSocketData(nsAutoPtr<UnixSocketBuffer>& aBuffer) = 0;
|
||||||
|
|
||||||
/**
|
|
||||||
* Convenience function for sending strings to the socket (common in bluetooth
|
|
||||||
* profile usage). Converts to a UnixSocketRawData struct. Can only be called
|
|
||||||
* on originating thread.
|
|
||||||
*
|
|
||||||
* TODO: Move this method into Bluetooth module.
|
|
||||||
*
|
|
||||||
* @param aMessage String to be sent to socket
|
|
||||||
*
|
|
||||||
* @return true if data is queued, false otherwise (i.e. not connected)
|
|
||||||
*/
|
|
||||||
bool SendSocketData(const nsACString& aMessage);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Starts a task on the socket that will try to connect to a socket in a
|
* Starts a task on the socket that will try to connect to a socket in a
|
||||||
* non-blocking manner.
|
* non-blocking manner.
|
||||||
*
|
*
|
||||||
* @param aConnector Connector object for socket type specific functions
|
* @param aConnector Connector object for socket type specific functions
|
||||||
* @param aAddress Address to connect to.
|
* @param aDelayMs Time delay in milliseconds.
|
||||||
* @param aDelayMs Time delay in milli-seconds.
|
* @return NS_OK on success, or an XPCOM error code otherwise.
|
||||||
*
|
|
||||||
* @return true on connect task started, false otherwise.
|
|
||||||
*/
|
*/
|
||||||
bool Connect(UnixSocketConnector* aConnector,
|
nsresult Connect(UnixSocketConnector* aConnector, int aDelayMs = 0);
|
||||||
const char* aAddress,
|
|
||||||
int aDelayMs = 0);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the current sockaddr for the socket
|
|
||||||
*/
|
|
||||||
void GetSocketAddr(nsAString& aAddrStr);
|
|
||||||
|
|
||||||
// Methods for |DataSocket|
|
// Methods for |DataSocket|
|
||||||
//
|
//
|
||||||
|
|||||||
Reference in New Issue
Block a user