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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
|
/*
* Buxton
*
* Copyright (C) 2015 Samsung Electronics Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the License);
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#pragma once
#include <stdint.h>
#include "common.h"
#define MSG_FIRST 0x4
#define MSG_MIDDLE 0x2
#define MSG_LAST 0x1
#define MSG_SINGLE (MSG_FIRST | MSG_MIDDLE | MSG_LAST)
#define MSG_MTU 4096
/*
* Single type message
* = key (<4KB) + value (<4KB) + privileges (<2KB) + etc (<6KB)
*/
#define MSG_SINGLE_MAX (1 << 14) /* 16KB */
/*
* The length of MSG_LIST is the length of key name * number of keys.
* Usually, an average length of key name is about 35B.
* A 32MB message can send about 0.9M names of keys.
*/
#define MSG_TOTAL_MAX (1 << 25) /* 32 MB */
/*
* Message header (12 bytes) :
*
* +-----------+-----------+-----------+-----------+
* | type (1) | mtype (1) | Sequence number (2) |
* +-----------+-----------+-----------+-----------+
* | Total length (4) |
* +-----------+-----------+-----------+-----------+
* | Current data length (4) |
* +-----------+-----------+-----------+-----------+
* | Data ... (n) |
* +-----------+-----------+-----------+-----------+
*
*/
struct header {
uint8_t type; /* one of MSG_XXX */
uint8_t mtype; /* enum message_type */
uint16_t seq; /* sequence number */
uint32_t total; /* total length of message */
uint32_t len; /* length of current data */
uint8_t data[0];
} __attribute__((packed));
int proto_send(int fd, enum message_type type, uint8_t *data, int32_t len);
int proto_recv(int fd, enum message_type *type, uint8_t **data, int32_t *len);
typedef void (*recv_callback)(void *user_data,
enum message_type type, uint8_t *data, int32_t len);
int proto_recv_async(int fd, recv_callback callback, void *user_data);
int proto_send_block(int fd, enum message_type type, uint8_t *data,
int32_t len);
|