2012-09-05 20:06:06 -07:00
|
|
|
/* -*- Mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 40 -*- */
|
|
|
|
/* vim: set ts=2 et sw=2 tw=80: */
|
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
2014-12-02 15:00:36 -08:00
|
|
|
#ifndef mozilla_ipc_unixsocket_h
|
|
|
|
#define mozilla_ipc_unixsocket_h
|
2012-09-25 13:13:15 -07:00
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include "nsAutoPtr.h"
|
2014-03-09 19:11:27 -07:00
|
|
|
#include "nsString.h"
|
2013-12-09 05:21:18 -08:00
|
|
|
#include "nsThreadUtils.h"
|
2014-07-31 04:55:27 -07:00
|
|
|
#include "mozilla/ipc/SocketBase.h"
|
2014-12-02 15:00:36 -08:00
|
|
|
#include "mozilla/ipc/UnixSocketWatcher.h"
|
2014-03-09 19:11:27 -07:00
|
|
|
#include "mozilla/RefPtr.h"
|
2014-12-02 15:00:36 -08:00
|
|
|
#include "UnixSocketConnector.h"
|
2012-09-05 20:06:06 -07:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace ipc {
|
|
|
|
|
2014-07-31 04:55:30 -07:00
|
|
|
class UnixSocketConsumerIO;
|
2012-09-25 13:13:15 -07:00
|
|
|
|
2014-07-31 04:55:27 -07:00
|
|
|
class UnixSocketConsumer : public SocketConsumerBase
|
2012-09-25 13:13:15 -07:00
|
|
|
{
|
2014-04-14 12:04:25 -07:00
|
|
|
protected:
|
|
|
|
virtual ~UnixSocketConsumer();
|
|
|
|
|
2012-09-25 13:13:15 -07:00
|
|
|
public:
|
2014-04-14 12:04:25 -07:00
|
|
|
UnixSocketConsumer();
|
2014-04-14 13:16:18 -07:00
|
|
|
|
2012-10-01 00:03:16 -07:00
|
|
|
/**
|
2012-09-25 13:13:15 -07:00
|
|
|
* Queue data to be sent to the socket on the IO thread. Can only be called on
|
|
|
|
* originating thread.
|
|
|
|
*
|
|
|
|
* @param aMessage Data to be sent to socket
|
|
|
|
*
|
|
|
|
* @return true if data is queued, false otherwise (i.e. not connected)
|
|
|
|
*/
|
|
|
|
bool SendSocketData(UnixSocketRawData* aMessage);
|
|
|
|
|
2012-10-01 00:03:16 -07:00
|
|
|
/**
|
2012-09-25 13:13:15 -07:00
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* @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);
|
|
|
|
|
2012-10-01 00:03:16 -07:00
|
|
|
/**
|
|
|
|
* Starts a task on the socket that will try to connect to a socket in a
|
|
|
|
* non-blocking manner.
|
2012-09-25 13:13:15 -07:00
|
|
|
*
|
|
|
|
* @param aConnector Connector object for socket type specific functions
|
|
|
|
* @param aAddress Address to connect to.
|
2013-02-01 04:28:18 -08:00
|
|
|
* @param aDelayMs Time delay in milli-seconds.
|
2012-09-25 13:13:15 -07:00
|
|
|
*
|
2012-10-01 00:03:16 -07:00
|
|
|
* @return true on connect task started, false otherwise.
|
2012-09-25 13:13:15 -07:00
|
|
|
*/
|
2013-02-01 04:28:18 -08:00
|
|
|
bool ConnectSocket(UnixSocketConnector* aConnector,
|
|
|
|
const char* aAddress,
|
|
|
|
int aDelayMs = 0);
|
2012-09-25 13:13:15 -07:00
|
|
|
|
2013-09-06 01:17:55 -07:00
|
|
|
/**
|
2012-10-01 00:03:16 -07:00
|
|
|
* Starts a task on the socket that will try to accept a new connection in a
|
|
|
|
* non-blocking manner.
|
|
|
|
*
|
|
|
|
* @param aConnector Connector object for socket type specific functions
|
|
|
|
*
|
|
|
|
* @return true on listen started, false otherwise
|
|
|
|
*/
|
|
|
|
bool ListenSocket(UnixSocketConnector* aConnector);
|
|
|
|
|
|
|
|
/**
|
2012-09-25 13:13:15 -07:00
|
|
|
* Queues the internal representation of socket for deletion. Can be called
|
|
|
|
* from main thread.
|
|
|
|
*/
|
|
|
|
void CloseSocket();
|
2012-09-05 20:06:06 -07:00
|
|
|
|
2012-10-17 17:10:27 -07:00
|
|
|
/**
|
|
|
|
* Get the current sockaddr for the socket
|
|
|
|
*/
|
2012-10-17 17:11:05 -07:00
|
|
|
void GetSocketAddr(nsAString& aAddrStr);
|
|
|
|
|
2012-09-25 13:13:15 -07:00
|
|
|
private:
|
2014-07-31 04:55:30 -07:00
|
|
|
UnixSocketConsumerIO* mIO;
|
2012-09-25 13:13:15 -07:00
|
|
|
};
|
2012-09-05 20:06:06 -07:00
|
|
|
|
|
|
|
} // namespace ipc
|
|
|
|
} // namepsace mozilla
|
|
|
|
|
2014-12-02 15:00:36 -08:00
|
|
|
#endif // mozilla_ipc_unixsocket_h
|