Files

63 lines
1.4 KiB
C

#pragma once
#include <stdatomic.h>
#include <stdint.h>
#include <sys/types.h>
// global definition for size if input and
// output data fields across protocols
// mq limit is 8192 bytes default..
#define READ_BUFFER_SIZE 4096
#define WRITE_BUFFER_SIZE 4096
#define MQ_PAYLOAD_SIZE_IN READ_BUFFER_SIZE
#define MQ_PAYLOAD_SIZE_OUT WRITE_BUFFER_SIZE
// paths
#define MQ_REL_PATH "/stored"
#define MQ_ABS_PATH "/dev/mqueue" MQ_REL_PATH
#define UDS_SOCK_PATH "/tmp/stored.sock"
#define TCP_PORT 6767
#define SHM_PATH "/storebus"
// message for shared incoming queue
typedef struct MQMessage {
pid_t client_pid;
unsigned int request_id;
uint8_t payload[MQ_PAYLOAD_SIZE_IN];
} mq_message_t;
// message for outgoing queues to clients
typedef struct MQResponse {
unsigned int request_id;
uint8_t payload[MQ_PAYLOAD_SIZE_OUT];
} mq_response_t;
// shared memory
/*
* 0 = availible for new connections
* 1 = connection reserved
* 2 = client wrote request
* 3 = server wrote response
* 4 = client finished
*/
typedef enum SHMStatus {
SHM_STAT_AVAIL = 0,
SHM_STAT_NEW_CONNECT = 1,
SHM_STAT_REQ_WRITTEN = 2,
SHM_STAT_RES_WRITTEN = 3,
SHM_STAT_DONE = 4,
} shm_status_t;
typedef struct SharedMemoryBuf {
_Atomic shm_status_t shared_status;
mq_message_t message;
mq_response_t response;
} shared_memory_buf_t ;