IPC

mm_ipc_srv_create

#include <mmsysio.h>
struct mm_ipc_srv* mm_ipc_srv_create(const char* addr)

Create a IPC server

Parameters:
  • addr (const char*) – path to which the server must listen

Description

This creates a server instance that will listen to the path specified by argument path. This path does not have necessarily a connection with the filesystem pathnames. However it obey to the same syntax.

Only one IPC server instance can listen to same address. If there is already another server, this function will fail.

Return

pointer to IPC server in case of success. NULL otherwise with error state set accordingly

mm_ipc_srv_destroy

#include <mmsysio.h>
void mm_ipc_srv_destroy(struct mm_ipc_srv* srv)

Destroy IPC server

Parameters:
  • srv (struct mm_ipc_srv*) – server to destroy

Description

This function destroy the server referenced to by srv. The path to which server was listening become available for new call to mm_ipc_srv_create(). However, if there were accepted connection still opened, it is unspecified whether the name will be available before all connection are closed or not. If there were client connection pending that had not been accepted by the server yet, those will be dropped.

Destroying a server does not affect accepted connections which will survive until they are specifically closed with mm_close().

mm_ipc_srv_accept

#include <mmsysio.h>
int mm_ipc_srv_accept(struct mm_ipc_srv* srv)

accept a incoming connection

Parameters:
  • srv (struct mm_ipc_srv*) – IPC server

Description

This function extracts the first connection on the queue of pending connections, and allocate a new file descriptor for that connection (the lowest number available). If there are no connection pending, the function will block until one arrives.

Return

a non-negative integer representing the file descriptor in case of success. Otherwise -1 is returned with error state set accordingly.

mm_ipc_connect

#include <mmsysio.h>
int mm_ipc_connect(const char* addr)

connect a client to an IPC server

Parameters:
  • addr (const char*) – path to which the client must connect

Description

Client-side counterpart of mm_ipc_srv_accept(), this functions attempts to connect to a server listening to addr if there are any. If one is found, it allocates a new file descriptor for that connection (the lowest number available). If there are no server listening to addr, the function will block until one server does.

Return

a non-negative integer representing the file descriptor in case of success. Otherwise -1 is returned with error state set accordingly.

mm_ipc_sendmsg

#include <mmsysio.h>
ssize_t mm_ipc_sendmsg(int fd, const struct mm_ipc_msg* msg)

send message to ICP endpoint

Parameters:
  • fd (int) – file descriptor of an IPC connection endpoint
  • msg (const struct mm_ipc_msg*) – IPC message

Description

If space is not available at the sending endpoint to hold the message to be transmitted, the function will block until space is available. The message sent in msg is a datagram: either all could have been transmitted, either none and the function would fail.

File descriptors can also be transmitted to the receiving endpoint along a message with the msg->fds and msg->num_fds fields. The file descriptors listed here are duplicated for the process holding the other endpoint.

Return

the number of bytes sent in case of success, -1 otherwise with error state set accordingly.

mm_ipc_recvmsg

#include <mmsysio.h>
ssize_t mm_ipc_recvmsg(int fd, struct mm_ipc_msg* msg)

recv message from IPC endpoint

Parameters:
  • fd (int) – file descriptor of an IPC connection endpoint
  • msg (struct mm_ipc_msg*) – IPC message

Description

This function receives a message. The message received is a datagram: if the data received is smaller that requested, the function will return a smaller message and its size will be reported by the return value. Controversy if a message is too long to fit in the supplied buffers in msg->iov, the excess bytes will be discarded and the flag MSG_TRUNC will be set in msg->flags.

You can receive file descriptors along with the message in msg->fds and msg->num_fds fields. Similarly to the data message, if the buffer holding the file descriptor is too small, the files descriptor in excess will be discarded (implicitly closing them, ensuring no descriptor leak to occur) and the flag MSG_CTRUNC will be set in msg->flags.

Return

the number of bytes received in case of success, -1 otherwise with error state set accordingly.

mm_ipc_connected_pair

#include <mmsysio.h>
int mm_ipc_connected_pair(int fds)

create a pair of connected IPC endpoints

Parameters:
  • fds (int) – array receiving the file descriptor of the 2 endpoints

Return

0 in case of success, -1 otherwise with error state set accordingly.