2014-12-02 15:00:36 -08: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/. */
|
|
|
|
|
|
|
|
#ifndef mozilla_ipc_unixsocketconnector_h
|
|
|
|
#define mozilla_ipc_unixsocketconnector_h
|
|
|
|
|
|
|
|
#include "mozilla/ipc/UnixSocketWatcher.h"
|
|
|
|
#include "nsString.h"
|
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace ipc {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* |UnixSocketConnector| defines the socket creation and connection/listening
|
|
|
|
* functions for |UnixSocketConsumer|, et al. Due to the fact that socket setup
|
2015-05-18 06:01:27 -07:00
|
|
|
* can vary between protocols (unix sockets, tcp sockets, bluetooth sockets, etc),
|
2014-12-02 15:00:36 -08:00
|
|
|
* this allows the user to create whatever connection mechanism they need while
|
|
|
|
* still depending on libevent for non-blocking communication handling.
|
|
|
|
*/
|
|
|
|
class UnixSocketConnector
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
virtual ~UnixSocketConnector();
|
|
|
|
|
2015-05-18 02:28:30 -07:00
|
|
|
/**
|
2015-05-18 06:01:27 -07:00
|
|
|
* Establishs a file descriptor for a socket.
|
2015-05-18 02:28:30 -07:00
|
|
|
*
|
2015-05-18 06:01:27 -07:00
|
|
|
* @return File descriptor for socket
|
2015-05-18 02:28:30 -07:00
|
|
|
*/
|
2015-05-18 06:01:27 -07:00
|
|
|
virtual int Create() = 0;
|
2015-05-18 02:28:30 -07:00
|
|
|
|
|
|
|
/**
|
2015-05-18 06:01:27 -07:00
|
|
|
* Since most socket specifics are related to address formation into a
|
|
|
|
* sockaddr struct, this function is defined by subclasses and fills in the
|
|
|
|
* structure as needed for whatever connection it is trying to build
|
2015-05-18 02:28:30 -07:00
|
|
|
*
|
2015-05-18 06:01:27 -07:00
|
|
|
* @param aIsServer True is we are acting as a server socket
|
|
|
|
* @param aAddrSize Size of the struct
|
|
|
|
* @param aAddr Struct to fill
|
|
|
|
* @param aAddress If aIsServer is false, Address to connect to. nullptr otherwise.
|
|
|
|
*
|
|
|
|
* @return True if address is filled correctly, false otherwise
|
2015-05-18 02:28:30 -07:00
|
|
|
*/
|
2015-05-18 06:01:27 -07:00
|
|
|
virtual bool CreateAddr(bool aIsServer,
|
|
|
|
socklen_t& aAddrSize,
|
|
|
|
sockaddr_any& aAddr,
|
|
|
|
const char* aAddress) = 0;
|
2015-05-18 02:28:30 -07:00
|
|
|
|
|
|
|
/**
|
2015-05-18 06:01:27 -07:00
|
|
|
* Does any socket type specific setup that may be needed, only for socket
|
|
|
|
* created by ConnectSocket()
|
|
|
|
*
|
|
|
|
* @param aFd File descriptor for opened socket
|
2015-05-18 02:28:30 -07:00
|
|
|
*
|
2015-05-18 06:01:27 -07:00
|
|
|
* @return true is successful, false otherwise
|
2015-05-18 02:28:30 -07:00
|
|
|
*/
|
2015-05-18 06:01:27 -07:00
|
|
|
virtual bool SetUp(int aFd) = 0;
|
2015-05-18 02:28:30 -07:00
|
|
|
|
|
|
|
/**
|
2015-05-18 06:01:27 -07:00
|
|
|
* Perform socket setup for socket created by ListenSocket(), after listen().
|
|
|
|
*
|
|
|
|
* @param aFd File descriptor for opened socket
|
2015-05-18 02:28:30 -07:00
|
|
|
*
|
2015-05-18 06:01:27 -07:00
|
|
|
* @return true is successful, false otherwise
|
2015-05-18 02:28:30 -07:00
|
|
|
*/
|
2015-05-18 06:01:27 -07:00
|
|
|
virtual bool SetUpListenSocket(int aFd) = 0;
|
2015-05-18 02:28:30 -07:00
|
|
|
|
2015-05-18 06:01:27 -07:00
|
|
|
/**
|
|
|
|
* Get address of socket we're currently connected to. Return null string if
|
|
|
|
* not connected.
|
|
|
|
*
|
|
|
|
* @param aAddr Address struct
|
|
|
|
* @param aAddrStr String to store address to
|
|
|
|
*/
|
|
|
|
virtual void GetSocketAddr(const sockaddr_any& aAddr,
|
|
|
|
nsAString& aAddrStr) = 0;
|
2014-12-02 15:00:36 -08:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|