mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-28 07:13:20 +00:00
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:
parent
533d048a4b
commit
a3afbdf88b
@ -217,7 +217,7 @@ RilConsumer::RilConsumer(unsigned long aClientId,
|
||||
mAddress = addr_un.sun_path;
|
||||
}
|
||||
|
||||
Connect(new RilConnector(mAddress, mClientId), mAddress.get());
|
||||
Connect(new RilConnector(mAddress, mClientId));
|
||||
}
|
||||
|
||||
nsresult
|
||||
@ -288,10 +288,10 @@ void
|
||||
RilConsumer::OnDisconnect()
|
||||
{
|
||||
CHROMIUM_LOG("RIL[%lu]: %s\n", mClientId, __FUNCTION__);
|
||||
if (!mShutdown) {
|
||||
Connect(new RilConnector(mAddress, mClientId), mAddress.get(),
|
||||
GetSuggestedConnectDelayMs());
|
||||
if (mShutdown) {
|
||||
return;
|
||||
}
|
||||
Connect(new RilConnector(mAddress, mClientId), GetSuggestedConnectDelayMs());
|
||||
}
|
||||
|
||||
ConnectionOrientedSocketIO*
|
||||
|
@ -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));
|
||||
|
@ -28,37 +28,15 @@ public:
|
||||
*/
|
||||
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
|
||||
* non-blocking manner.
|
||||
*
|
||||
* @param aConnector Connector object for socket type specific functions
|
||||
* @param aAddress Address to connect to.
|
||||
* @param aDelayMs Time delay in milli-seconds.
|
||||
*
|
||||
* @return true on connect task started, false otherwise.
|
||||
* @param aDelayMs Time delay in milliseconds.
|
||||
* @return NS_OK on success, or an XPCOM error code otherwise.
|
||||
*/
|
||||
bool Connect(UnixSocketConnector* aConnector,
|
||||
const char* aAddress,
|
||||
int aDelayMs = 0);
|
||||
|
||||
/**
|
||||
* Get the current sockaddr for the socket
|
||||
*/
|
||||
void GetSocketAddr(nsAString& aAddrStr);
|
||||
nsresult Connect(UnixSocketConnector* aConnector, int aDelayMs = 0);
|
||||
|
||||
// Methods for |DataSocket|
|
||||
//
|
||||
|
Loading…
Reference in New Issue
Block a user