Backed out changeset 2fd186d1a288 (bug 1164425)

This commit is contained in:
Carsten "Tomcat" Book 2015-05-20 10:31:09 +02:00
parent 70b8a9bab5
commit e62550b3f7
3 changed files with 94 additions and 16 deletions

View File

@ -217,7 +217,7 @@ RilConsumer::RilConsumer(unsigned long aClientId,
mAddress = addr_un.sun_path;
}
Connect(new RilConnector(mAddress, mClientId));
Connect(new RilConnector(mAddress, mClientId), mAddress.get());
}
nsresult
@ -288,10 +288,10 @@ void
RilConsumer::OnDisconnect()
{
CHROMIUM_LOG("RIL[%lu]: %s\n", mClientId, __FUNCTION__);
if (mShutdown) {
return;
if (!mShutdown) {
Connect(new RilConnector(mAddress, mClientId), mAddress.get(),
GetSuggestedConnectDelayMs());
}
Connect(new RilConnector(mAddress, mClientId), GetSuggestedConnectDelayMs());
}
ConnectionOrientedSocketIO*

View File

@ -37,6 +37,8 @@ public:
UnixSocketConnector* aConnector);
~StreamSocketIO();
void GetSocketAddr(nsAString& aAddrStr) const;
StreamSocket* GetStreamSocket();
DataSocket* GetDataSocket();
@ -167,6 +169,26 @@ 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()
{
@ -508,17 +530,47 @@ StreamSocket::~StreamSocket()
MOZ_ASSERT(!mIO);
}
nsresult
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
StreamSocket::Connect(UnixSocketConnector* aConnector,
const char* aAddress,
int aDelayMs)
{
MOZ_ASSERT(aConnector);
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();
mIO = new StreamSocketIO(ioLoop, this, aConnector);
mIO = new StreamSocketIO(ioLoop, this, connector.forget());
SetConnectionStatus(SOCKET_CONNECTING);
if (aDelayMs > 0) {
StreamSocketIO::DelayedConnectTask* connectTask =
new StreamSocketIO::DelayedConnectTask(mIO);
@ -527,7 +579,8 @@ StreamSocket::Connect(UnixSocketConnector* aConnector,
} else {
ioLoop->PostTask(FROM_HERE, new StreamSocketIO::ConnectTask(mIO));
}
return NS_OK;
return true;
}
ConnectionOrientedSocketIO*
@ -567,13 +620,16 @@ void
StreamSocket::Close()
{
MOZ_ASSERT(NS_IsMainThread());
MOZ_ASSERT(mIO);
if (!mIO) {
return;
}
mIO->CancelDelayedConnectTask();
// 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.
// 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.
mIO->ShutdownOnMainThread();
XRE_GetIOMessageLoop()->PostTask(FROM_HERE, new SocketIOShutdownTask(mIO));

View File

@ -28,15 +28,37 @@ 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 aDelayMs Time delay in milliseconds.
* @return NS_OK on success, or an XPCOM error code otherwise.
* @param aAddress Address to connect to.
* @param aDelayMs Time delay in milli-seconds.
*
* @return true on connect task started, false otherwise.
*/
nsresult Connect(UnixSocketConnector* aConnector, int aDelayMs = 0);
bool Connect(UnixSocketConnector* aConnector,
const char* aAddress,
int aDelayMs = 0);
/**
* Get the current sockaddr for the socket
*/
void GetSocketAddr(nsAString& aAddrStr);
// Methods for |DataSocket|
//