mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-02-19 15:51:33 +00:00
Bug 1164425: Cleanup interfaces of |ListenSocket|, r=kmachulis
This patch removes |ListenSocket::GetSocketAddr|, which is unused and not thread-safe. The |Listen| methods now return error codes.
This commit is contained in:
parent
d21bc736cb
commit
840f154d6b
@ -1913,7 +1913,7 @@ BluetoothDaemonInterface::OnConnectSuccess(enum Channel aChannel)
|
||||
/* Notification channel should not be open; let's close it. */
|
||||
mNtfChannel->Close();
|
||||
}
|
||||
if (!mListenSocket->Listen(mNtfChannel)) {
|
||||
if (NS_FAILED(mListenSocket->Listen(mNtfChannel))) {
|
||||
OnConnectError(NTF_CHANNEL);
|
||||
}
|
||||
break;
|
||||
@ -2136,9 +2136,9 @@ BluetoothDaemonInterface::Init(
|
||||
mListenSocketName.AssignLiteral(BASE_SOCKET_NAME);
|
||||
}
|
||||
|
||||
bool success = mListenSocket->Listen(
|
||||
new BluetoothDaemonConnector(mListenSocketName), mCmdChannel);
|
||||
if (!success) {
|
||||
rv = mListenSocket->Listen(new BluetoothDaemonConnector(mListenSocketName),
|
||||
mCmdChannel);
|
||||
if (NS_FAILED(rv)) {
|
||||
OnConnectError(CMD_CHANNEL);
|
||||
return;
|
||||
}
|
||||
|
@ -312,15 +312,14 @@ NfcService::Start(nsINfcGonkEventListener* aListener)
|
||||
mListenSocketName = BASE_SOCKET_NAME;
|
||||
|
||||
mListenSocket = new NfcListenSocket(this);
|
||||
|
||||
bool success = mListenSocket->Listen(new NfcConnector(mListenSocketName),
|
||||
mConsumer);
|
||||
if (!success) {
|
||||
nsresult rv = mListenSocket->Listen(new NfcConnector(mListenSocketName),
|
||||
mConsumer);
|
||||
if (NS_FAILED(rv)) {
|
||||
mConsumer = nullptr;
|
||||
return NS_ERROR_FAILURE;
|
||||
return rv;
|
||||
}
|
||||
|
||||
nsresult rv = NS_NewNamedThread("NfcThread", getter_AddRefs(mThread));
|
||||
rv = NS_NewNamedThread("NfcThread", getter_AddRefs(mThread));
|
||||
if (NS_FAILED(rv)) {
|
||||
NS_WARNING("Can't create Nfc worker thread.");
|
||||
mListenSocket->Close();
|
||||
|
@ -31,8 +31,6 @@ public:
|
||||
UnixSocketConnector* aConnector);
|
||||
~ListenSocketIO();
|
||||
|
||||
void GetSocketAddr(nsAString& aAddrStr) const;
|
||||
|
||||
// Task callback methods
|
||||
//
|
||||
|
||||
@ -114,26 +112,6 @@ ListenSocketIO::~ListenSocketIO()
|
||||
MOZ_ASSERT(IsShutdownOnMainThread());
|
||||
}
|
||||
|
||||
void
|
||||
ListenSocketIO::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));
|
||||
}
|
||||
|
||||
void
|
||||
ListenSocketIO::Listen(ConnectionOrientedSocketIO* aCOSocketIO)
|
||||
{
|
||||
@ -314,51 +292,32 @@ ListenSocket::~ListenSocket()
|
||||
MOZ_ASSERT(!mIO);
|
||||
}
|
||||
|
||||
bool
|
||||
nsresult
|
||||
ListenSocket::Listen(UnixSocketConnector* aConnector,
|
||||
ConnectionOrientedSocket* aCOSocket)
|
||||
{
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
MOZ_ASSERT(aConnector);
|
||||
MOZ_ASSERT(aCOSocket);
|
||||
MOZ_ASSERT(!mIO);
|
||||
|
||||
nsAutoPtr<UnixSocketConnector> connector(aConnector);
|
||||
|
||||
if (mIO) {
|
||||
NS_WARNING("Socket already connecting/connected!");
|
||||
return false;
|
||||
}
|
||||
|
||||
mIO = new ListenSocketIO(XRE_GetIOMessageLoop(), this, connector.forget());
|
||||
mIO = new ListenSocketIO(XRE_GetIOMessageLoop(), this, aConnector);
|
||||
|
||||
// Prepared I/O object, now start listening.
|
||||
return Listen(aCOSocket);
|
||||
}
|
||||
|
||||
bool
|
||||
nsresult
|
||||
ListenSocket::Listen(ConnectionOrientedSocket* aCOSocket)
|
||||
{
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
MOZ_ASSERT(mIO);
|
||||
MOZ_ASSERT(aCOSocket);
|
||||
MOZ_ASSERT(mIO);
|
||||
|
||||
SetConnectionStatus(SOCKET_LISTENING);
|
||||
|
||||
XRE_GetIOMessageLoop()->PostTask(
|
||||
FROM_HERE, new ListenSocketIO::ListenTask(mIO, aCOSocket->GetIO()));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void
|
||||
ListenSocket::GetSocketAddr(nsAString& aAddrStr)
|
||||
{
|
||||
aAddrStr.Truncate();
|
||||
if (!mIO || GetConnectionStatus() != SOCKET_CONNECTED) {
|
||||
NS_WARNING("No socket currently open!");
|
||||
return;
|
||||
}
|
||||
mIO->GetSocketAddr(aAddrStr);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
// |SocketBase|
|
||||
|
@ -32,11 +32,10 @@ public:
|
||||
* @param aConnector Connector object for socket-type-specific functions
|
||||
* @param aCOSocket The connection-oriented socket for handling the
|
||||
* accepted connection.
|
||||
*
|
||||
* @return true on listen started, false otherwise
|
||||
* @return NS_OK on success, or an XPCOM error code otherwise.
|
||||
*/
|
||||
bool Listen(UnixSocketConnector* aConnector,
|
||||
ConnectionOrientedSocket* aCOSocket);
|
||||
nsresult Listen(UnixSocketConnector* aConnector,
|
||||
ConnectionOrientedSocket* aCOSocket);
|
||||
|
||||
/**
|
||||
* Starts a task on the socket that will try to accept a new connection
|
||||
@ -45,15 +44,9 @@ public:
|
||||
*
|
||||
* @param aCOSocket The connection-oriented socket for handling the
|
||||
* accepted connection.
|
||||
*
|
||||
* @return true on listen started, false otherwise
|
||||
* @return NS_OK on success, or an XPCOM error code otherwise.
|
||||
*/
|
||||
bool Listen(ConnectionOrientedSocket* aCOSocket);
|
||||
|
||||
/**
|
||||
* Get the current sockaddr for the socket
|
||||
*/
|
||||
void GetSocketAddr(nsAString& aAddrStr);
|
||||
nsresult Listen(ConnectionOrientedSocket* aCOSocket);
|
||||
|
||||
// Methods for |SocketBase|
|
||||
//
|
||||
|
Loading…
x
Reference in New Issue
Block a user