Electroneum
tube.h
Go to the documentation of this file.
1 /*
2  * util/tube.h - pipe service
3  *
4  * Copyright (c) 2008, NLnet Labs. All rights reserved.
5  *
6  * This software is open source.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  *
12  * Redistributions of source code must retain the above copyright notice,
13  * this list of conditions and the following disclaimer.
14  *
15  * Redistributions in binary form must reproduce the above copyright notice,
16  * this list of conditions and the following disclaimer in the documentation
17  * and/or other materials provided with the distribution.
18  *
19  * Neither the name of the NLNET LABS nor the names of its contributors may
20  * be used to endorse or promote products derived from this software without
21  * specific prior written permission.
22  *
23  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
26  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
27  * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
28  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
29  * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
30  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
31  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
32  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
33  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34  */
35 
42 #ifndef UTIL_TUBE_H
43 #define UTIL_TUBE_H
44 struct comm_reply;
45 struct comm_point;
46 struct comm_base;
47 struct tube;
48 struct tube_res_list;
49 #ifdef USE_WINSOCK
50 #include "util/locks.h"
51 #endif
52 
58 typedef void tube_callback_type(struct tube*, uint8_t*, size_t, int, void*);
59 
63 struct tube {
64 #ifndef USE_WINSOCK
65 
66  int sr;
68  int sw;
69 
75  void* listen_arg;
77  size_t cmd_read;
82 
87  size_t res_write;
92 
93 #else /* USE_WINSOCK */
94 
97  void* listen_arg;
99  WSAEVENT event;
101  struct ub_event* ev_listen;
102 
104  lock_basic_type res_lock;
106  struct tube_res_list* res_list;
108  struct tube_res_list* res_last;
109 #endif /* USE_WINSOCK */
110 };
111 
122 };
123 
128 struct tube* tube_create(void);
129 
134 void tube_delete(struct tube* tube);
135 
153 int tube_write_msg(struct tube* tube, uint8_t* buf, uint32_t len,
154  int nonblock);
155 
173 int tube_read_msg(struct tube* tube, uint8_t** buf, uint32_t* len,
174  int nonblock);
175 
181 void tube_close_read(struct tube* tube);
182 
188 void tube_close_write(struct tube* tube);
189 
196 int tube_poll(struct tube* tube);
197 
205 int tube_wait(struct tube* tube);
206 
212 int tube_read_fd(struct tube* tube);
213 
224 int tube_setup_bg_listen(struct tube* tube, struct comm_base* base,
225  tube_callback_type* cb, void* arg);
226 
231 void tube_remove_bg_listen(struct tube* tube);
232 
240 int tube_setup_bg_write(struct tube* tube, struct comm_base* base);
241 
246 void tube_remove_bg_write(struct tube* tube);
247 
248 
259 int tube_queue_item(struct tube* tube, uint8_t* msg, size_t len);
260 
262 int tube_handle_listen(struct comm_point* c, void* arg, int error,
263  struct comm_reply* reply_info);
264 
266 int tube_handle_write(struct comm_point* c, void* arg, int error,
267  struct comm_reply* reply_info);
268 
270 void tube_handle_signal(int fd, short events, void* arg);
271 
272 #endif /* UTIL_TUBE_H */
void tube_close_write(struct tube *tube)
void tube_callback_type(struct tube *, uint8_t *, size_t, int, void *)
Definition: tube.h:58
struct tube_res_list * next
Definition: tube.h:117
uint32_t cmd_len
Definition: tube.h:79
void tube_remove_bg_listen(struct tube *tube)
unsigned char uint8_t
Definition: stdint.h:124
int tube_handle_listen(struct comm_point *c, void *arg, int error, struct comm_reply *reply_info)
int tube_setup_bg_write(struct tube *tube, struct comm_base *base)
void * listen_arg
Definition: tube.h:75
uint32_t len
Definition: tube.h:121
size_t cmd_read
Definition: tube.h:77
int sr
Definition: tube.h:66
unsigned int uint32_t
Definition: stdint.h:126
int tube_write_msg(struct tube *tube, uint8_t *buf, uint32_t len, int nonblock)
int lock_basic_type
Definition: locks.h:269
int tube_read_fd(struct tube *tube)
int tube_read_msg(struct tube *tube, uint8_t **buf, uint32_t *len, int nonblock)
uint8_t * cmd_msg
Definition: tube.h:81
int tube_queue_item(struct tube *tube, uint8_t *msg, size_t len)
void tube_handle_signal(int fd, short events, void *arg)
struct comm_point * res_com
Definition: tube.h:84
const char * buf
Definition: slow_memmem.cpp:74
int tube_handle_write(struct comm_point *c, void *arg, int error, struct comm_reply *reply_info)
int sw
Definition: tube.h:68
size_t res_write
Definition: tube.h:87
struct tube_res_list * res_last
Definition: tube.h:91
struct tube_res_list * res_list
Definition: tube.h:89
void tube_delete(struct tube *tube)
int tube_poll(struct tube *tube)
uint8_t * buf
Definition: tube.h:119
int tube_wait(struct tube *tube)
Definition: tube.h:63
tube_callback_type * listen_cb
Definition: tube.h:73
void tube_close_read(struct tube *tube)
struct comm_point * listen_com
Definition: tube.h:71
error
Tracks LMDB error codes.
Definition: error.h:44
struct tube * tube_create(void)
void tube_remove_bg_write(struct tube *tube)
int tube_setup_bg_listen(struct tube *tube, struct comm_base *base, tube_callback_type *cb, void *arg)