-
Notifications
You must be signed in to change notification settings - Fork 1
/
message.h
63 lines (46 loc) · 1.39 KB
/
message.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#ifndef PROTO_H
#define PROTO_H
#include <stdlib.h>
#include <stdint.h>
#include "types.h"
#include "proto.h"
#define PROT_VERSION 0
struct message {
struct msgbody body;
/*
* Whether this message's body was filled in by XDR and thus should be
* passed to xdr_free() for freeing instead passing individual members
* to xfree().
*/
int from_xdr;
/* For linking into a list (doesn't exist on the wire) */
struct message* next;
};
/* Shorthand macro for accessing message body members */
#define MB(m, t) ((m)->body.msgbody_u.t)
/*
* How many bytes we will always unconditionally read at the start of a
* message (the initial fixed-size part).
*/
#define MSGHDR_SIZE (sizeof(uint32_t))
/* Buffer used for storing an incoming (possibly incomplete) message */
struct partrecv {
char hdrbuf[MSGHDR_SIZE];
void* plbuf;
size_t bytes_recvd;
};
/* Buffer for storing an outgoing (possibly only partially-sent) message */
struct partsend {
void* buf;
size_t len;
size_t bytes_sent;
};
struct message* new_message(msgtype_t type);
void free_message(struct message* msg);
void free_msgbody(struct message* msg);
const char* msgtype_name(msgtype_t type);
int fill_msgbuf(int fd, struct partrecv* pr);
int parse_message(struct partrecv* pr, struct message* msg);
void unparse_message(const struct message* msg, struct partsend* ps);
int drain_msgbuf(int fd, struct partsend* ps);
#endif /* PROTO_H */