Crinit -- Configurable Rootfs Init
sockcom.c File Reference

(2023-08-02, commit: 9434b31)

Implementation of socket communication functions for the crinit-client library. More...

#include "sockcom.h"
#include <stdlib.h>
#include <sys/socket.h>
#include <sys/un.h>
#include <unistd.h>
#include "logio.h"
Include dependency graph for sockcom.c:

Functions

static int crinitConnect (int *sockFd, const char *sockFile)
 
static int crinitSend (int sockFd, const crinitRtimCmd_t *cmd)
 
static int crinitRecv (int sockFd, crinitRtimCmd_t *res)
 
static int crinitWaitForRtr (int sockFd)
 
int crinitXfer (const char *sockFile, crinitRtimCmd_t *res, const crinitRtimCmd_t *cmd)
 

Detailed Description

Implementation of socket communication functions for the crinit-client library.

Function Documentation

◆ crinitConnect()

static int crinitConnect ( int *  sockFd,
const char *  sockFile 
)
static

Connect to Crinit and wait for a ready-to-receive message.

Parameters
sockFdReturn pointer for the connected socket.
sockFilePath to the AF_UNIX socket file to connect to.
Returns
0 on success, -1 otherwise

◆ crinitRecv()

static int crinitRecv ( int  sockFd,
crinitRtimCmd_t res 
)
static

Receive a response from Crinit.

Receives a string using the same protocol as sendStr()/recvStr() in notiserv.c and then uses crinitParseRtimCmd() to generate an equivalent crinitRtimCmd_t.

First, a binary size_t with the string size is received, memory allocation made accordingly, and then the string itself in a second message/packet is received.

The following diagram illustrates the low-level protocol:

Parameters
sockFdThe connected socket from which to receive.
resReturn pointer for the response/result.
Returns
0 on success, -1 otherwise

◆ crinitSend()

static int crinitSend ( int  sockFd,
const crinitRtimCmd_t cmd 
)
static

Send a command/request to Crinit.

Uses crinitRtimCmdToMsgStr() to generate a string and sends it using the same protocol as sendStr()/recvStr() in notiserv.c. First, a binary size_t with the string size is sent, then the string itself in a second message/packet.

The following diagram illustrates the low-level protocol:

Parameters
sockFdThe connected socket over which to send.
cmdThe command/request to send.
Returns
0 on success, -1 otherwise

◆ crinitWaitForRtr()

static int crinitWaitForRtr ( int  sockFd)
static

Wait for a ready-to-receive message from Crinit.

Parameters
sockFdThe socket file descriptor connected to Crinit.
Returns
0 on success, -1 otherwise

◆ crinitXfer()

int crinitXfer ( const char *  sockFile,
crinitRtimCmd_t res,
const crinitRtimCmd_t cmd 
)

Perform a request/response transfer with Crinit

Will connect to Crinit and send a request/command, then receive the result/response. The server side equivalent is crinitConnThread() in notiserv.c.

The following image shows the high level communication sequence. For the lower level, refer to the internal functions crinitSend() and crinitRecv().

Parameters
sockFilePath to the AF_UNIX socket file to connect to.
resReturn pointer for response/result.
cmdThe command/request to send.
Returns
0 on success, -1 otherwise