38 lines
1023 B
C
38 lines
1023 B
C
#ifndef __MSG_H__
|
|
#define __MSG_H__
|
|
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
|
|
#define MSG_TYPE_CLOSE 0
|
|
#define MSG_TYPE_CON 1
|
|
#define MSG_TYPE_ERR 2
|
|
#define MSG_TYPE_ACK 3
|
|
#define MSG_TYPE_DATA 4
|
|
|
|
struct msg {
|
|
char type;
|
|
unsigned short valsize;
|
|
char *val;
|
|
};
|
|
|
|
// used to create msg structure from buffer
|
|
int msg_format_read (struct msg *m, const char *buf, size_t msize);
|
|
// used to create buffer from msg structure
|
|
int msg_format_write (const struct msg *m, char **buf, size_t *msize);
|
|
|
|
// read a structure msg from fd
|
|
int msg_read (int fd, struct msg *m);
|
|
// write a structure msg to fd
|
|
int msg_write (int fd, const struct msg *m);
|
|
|
|
int msg_format_con (struct msg *m, const char *val, size_t valsize);
|
|
int msg_format_data (struct msg *m, const char *val, size_t valsize);
|
|
int msg_format_ack (struct msg *m, const char *val, size_t valsize);
|
|
|
|
int msg_free (struct msg *m);
|
|
void print_msg (const struct msg *m);
|
|
|
|
#endif
|