Back to index

lightning-sunbird  0.9+nobinonly
Defines | Typedefs | Functions
ipcConnection.h File Reference
#include "nscore.h"
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Defines

#define IPC_METHOD_PRIVATE_(type)   NS_HIDDEN_(type)
#define IPC_METHOD_PRIVATE   IPC_METHOD_PRIVATE_(nsresult)

Typedefs

typedef void(* ipcCallbackFunc )(void *)

Functions

IPC_METHOD_PRIVATE IPC_Connect (const char *daemonPath)
 IPC_Connect.
IPC_METHOD_PRIVATE IPC_Disconnect ()
 IPC_Disconnect.
IPC_METHOD_PRIVATE IPC_SendMsg (ipcMessage *msg)
 IPC_SendMsg.
IPC_METHOD_PRIVATE IPC_DoCallback (ipcCallbackFunc func, void *arg)
 IPC_DoCallback.
IPC_METHOD_PRIVATE IPC_SpawnDaemon (const char *daemonPath)
 IPC_SpawnDaemon.
 IPC_METHOD_PRIVATE_ (void) IPC_OnConnectionEnd(nsresult error)
 IPC_OnConnectionEnd.

Define Documentation

Definition at line 46 of file ipcConnection.h.

Definition at line 45 of file ipcConnection.h.


Typedef Documentation

typedef void(* ipcCallbackFunc)(void *)

Definition at line 52 of file ipcConnection.h.


Function Documentation

IPC_METHOD_PRIVATE IPC_Connect ( const char *  daemonPath)

IPC_Connect.

This function causes a connection to the IPC daemon to be established. If a connection already exists, then this function will be ignored.

Parameters:
daemonPathSpecifies the path to the IPC daemon executable.

NOTE: This function must be called on the main thread.

Definition at line 49 of file ipcConnectionStub.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

IPC_Disconnect.

This function causes a connection to the IPC daemon to be closed. Any unsent messages (IPC_SendMsg puts messages on a queue) will be sent to the IPC daemon before the connection is closed.

NOTE: This function must be called on the main thread.

Definition at line 55 of file ipcConnectionStub.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

IPC_DoCallback.

This function executes a callback function on the same background thread that calls IPC_OnConnectionEnd and IPC_OnMessageAvailable.

If this function succeeds, then the caller is guaranteed that |func| will be called. This guarantee is important because it allows the caller to free any memory associated with |arg| once |func| has been called.

NOTE: This function may be called on any thread.

Definition at line 67 of file ipcConnectionStub.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

IPC_OnConnectionEnd.

IPC_OnMessageAvailable.

This function is called whenever the connection to the IPC daemon has been terminated. If terminated due to an abnormal error, then the error will be described by the |error| parameter. If |error| is NS_OK, then it means the connection was closed in response to a call to IPC_Disconnect.

This function is called whenever an incoming message is read from the IPC daemon. The ipcMessage object, |msg|, must be deleted by the implementation of IPC_OnMessageAvailable when the object is no longer needed.

IPC_SendMsg.

This function sends a message to the IPC daemon. Typically, the message is put on a queue, to be delivered asynchronously to the IPC daemon. The ipcMessage object will be deleted when IPC_SendMsg is done with it. The caller must not touch |msg| after passing it to IPC_SendMsg.

IPC_SendMsg cannot be called before IPC_Connect or after IPC_Disconnect.

NOTE: This function may be called on any thread.

Definition at line 61 of file ipcConnectionStub.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

IPC_METHOD_PRIVATE IPC_SpawnDaemon ( const char *  daemonPath)

IPC_SpawnDaemon.

This function launches the IPC daemon process. It is called by the platform specific IPC_Connect implementation. It should not return until the daemon process is ready to receive a client connection or an error occurs.

Parameters:
daemonPathSpecifies the path to the IPC daemon executable.

Definition at line 977 of file ipcdclient.cpp.

{
  PRFileDesc *readable = nsnull, *writable = nsnull;
  PRProcessAttr *attr = nsnull;
  nsresult rv = NS_ERROR_FAILURE;
  char *const argv[] = { (char *const) path, nsnull };
  char c;

  // setup an anonymous pipe that we can use to determine when the daemon
  // process has started up.  the daemon will write a char to the pipe, and
  // when we read it, we'll know to proceed with trying to connect to the
  // daemon.

  if (PR_CreatePipe(&readable, &writable) != PR_SUCCESS)
    goto end;
  PR_SetFDInheritable(writable, PR_TRUE);

  attr = PR_NewProcessAttr();
  if (!attr)
    goto end;

  if (PR_ProcessAttrSetInheritableFD(attr, writable, IPC_STARTUP_PIPE_NAME) != PR_SUCCESS)
    goto end;

  if (PR_CreateProcessDetached(path, argv, nsnull, attr) != PR_SUCCESS)
    goto end;

  if ((PR_Read(readable, &c, 1) != 1) && (c != IPC_STARTUP_PIPE_MAGIC))
    goto end;

  rv = NS_OK;
end:
  if (readable)
    PR_Close(readable);
  if (writable)
    PR_Close(writable);
  if (attr)
    PR_DestroyProcessAttr(attr);
  return rv;
}

Here is the call graph for this function:

Here is the caller graph for this function: