-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgrestart.h
138 lines (121 loc) · 3.74 KB
/
grestart.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
/*
Graceful restart library
Copyright (C) 2013 idostyle
This file is part of libgrestart.
libgrestart is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, version 3 of the License.
libgrestart is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with libgrestart. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef _LIB_GRESTART_
#define _LIB_GRESTART_
/**
* Graceful Restart Library
*/
#include <stddef.h>
typedef enum error_codes_
{
GR_NO_IDENTIFIER = -1,
GR_IDENTIFIER_TOO_LONG = -2,
GR_SOCKET_CREATION_FAILED = -3,
GR_CONNECT_FAILED = -4,
GR_SETSOCKOPT_FAILED = -5,
GR_BIND_FAILED = -6,
GR_LISTEN_FAILED = -7,
GR_NOT_A_GR_CLIENT = -8,
GR_RECVMSG_FAILED = -9,
GR_SENDMSG_FAILED = -10,
GR_INVALID_MSG_RECVD = -11,
GR_DOESNT_LOOK_LIKE_A_FD = -12,
GR_GETSOCKNAME_FAILED = -13,
GR_UNLINK_FAILED = -14,
GR_CLOSE_FAILED = -15,
GR_POLL_FAILED = -16,
} error_codes_t;
/**
* Connect to an running instance if there is one.
*
* - identifier:
* - a writable path string (ex. "/tmp/example.sock")
* - an abstract uds string (ex. "\0e11ab38fa")
*
* - identifier_len: length of identifier (ex. "/tmp/example.sock" => 17)
*
* Returns a fd >= 0 or an error code < 0
* -
*/
int gr_init(const char * identifier, const size_t identifier_len);
/**
* Setup a waiting instance.
*
* - identifier:
* - a writable path string (ex. "/tmp/example.sock")
* - an abstract uds string (ex. "\0e11ab38fa")
*
* - identifier_len: length of identifier (ex. "/tmp/example.sock" => 17)
*
* Returns a fd >= 0 or an error code < 0
*/
int gr_setup(const char * identifier, const size_t identifier_len);
/**
* Recieve a fd from a running instance.
*
* - gr: is expected to be an accepted client socket;
* not the main socket from gr_init/gr_setup;
*
* - fd_identifier: is expected to be an allocated memory area of fd_identifier_len
* size or a 0-pointer; can be used to identify the fd send over;
* is send over unmodified; may or may not be null-terminated;
*
* - fd_identifier_len: size of memory area passed to fd_identifier;
* can be 0 if fd_identifier is a 0-pointer;
*
* Returns an fd >= 0 or an error code < 0
*/
int gr_recv(const int gr, void * fd_identifier, const size_t fd_identifier_len);
/**
* Send a fd to the new instance.
*
* - gr: is expected to be an accepted client socket
*
* - fd: file descriptor to be send over
*
* - fd_identifier: is expected to be an allocated memory area of fd_identifier_len
* size or a 0-pointer; can be used to identify the fd send over;
*
* - fd_identifier_len: size of memory area passed to fd_identifier;
* can be 0 if fd_identifier is a 0-pointer;
*
* Returns count of byte sent >= 0 or an error code < 0
*/
int gr_send(const int gr, const int fd, void * fd_identifier, const size_t fd_identifier_len);
/**
*
*/
int gr_close(const int gr);
/**
* Poll if the fd is readable.
* It may be advisable to use you own implementation.
*
* - fd: file descriptor to check
*
* - timeout: timeout in milisecs (passed over to poll)
*
* Returns poll events >= 0 or an error code < 0
*/
#ifdef GR_WANT_POLL
int gr_poll(const int fd, const int timeout);
#endif
/**
* Raw interface to gr_recv/gr_send.
*/
#ifdef GR_WANT_IOV
int gr_recv_iov(const int gr, struct iovec * iov);
int gr_send_iov(const int gr, const int fd, struct iovec * iov);
#endif
#endif