kinetic-c  v0.12.0
Seagate Kinetic Protocol Client Library for C
listener_internal_types.h
Go to the documentation of this file.
1 /*
2 * kinetic-c
3 * Copyright (C) 2015 Seagate Technology.
4 *
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 *
19 */
20 #ifndef LISTENER_INTERNAL_TYPES_H
21 #define LISTENER_INTERNAL_TYPES_H
22 
23 #include "bus_types.h"
24 #include "bus_internal_types.h"
25 
26 #include <poll.h>
27 
29 #define DEFAULT_READ_BUF_SIZE (1024L * 1024L)
30 
35 #define INCOMING_MSG_PIPE_ID 0
36 
39 #define INCOMING_MSG_PIPE 1
40 
41 typedef enum {
48 } MSG_TYPE;
49 
51 typedef struct listener_msg {
52  const uint8_t id;
54  struct listener_msg *next;
55  int pipes[2];
56 
57  union { /* keyed by .type */
58  struct {
60  int notify_fd;
61  } add_socket;
62  struct {
63  int fd;
64  int notify_fd;
65  } remove_socket;
66  struct {
67  int fd;
68  int64_t seq_id;
69  int16_t timeout_sec;
70  int notify_fd;
71  } hold;
72  struct {
74  } expect;
75  struct {
76  int notify_fd;
77  } shutdown;
78  } u;
79 } listener_msg;
80 
83 #define LISTENER_TASK_TIMEOUT_DELAY 100
84 
85 typedef enum {
86  RIS_HOLD = 1,
90 
92 typedef struct rx_info_t {
93  const uint16_t id;
94  struct rx_info_t *next;
95 
97  time_t timeout_sec;
98 
99  union {
100  struct {
101  int fd;
102  int64_t seq_id;
106  } hold;
107  struct {
110  bool has_result;
112  } expect;
113  } u;
114 } rx_info_t;
115 
118 #define MAX_FDS 1000
119 
120 /* Max number of partially processed messages.
121  * TODO: Capacity planning. */
122 #define MAX_PENDING_MESSAGES (1024)
123 
125 #define MAX_QUEUE_MESSAGES (32)
126 typedef uint32_t msg_flag_t;
127 
129 #define INFINITE_DELAY (-1)
130 
132 #define LISTENER_NO_FD (-1)
133 #define LISTENER_SHUTDOWN_COMPLETE_FD (-2)
134 
136 typedef struct listener {
137  struct bus *bus;
138 
139  /* File descriptor which should receive a notification when the
140  * listener is shutting down. It will be set to LISTENER_NO_FD
141  * until shutdown is requested, then the FD to notify will be
142  * saved, then the FD will be notifed and it will be set to
143  * LISTENER_SHUTDOWN_COMPLETE_FD. */
145 
146  /* Pipes used to wake the sleeping listener on queue input. */
149  bool is_idle;
150 
153  uint16_t rx_info_in_use;
155 
158  int16_t msgs_in_use;
160 
162 
163  uint16_t tracked_fds;
164 
166  uint16_t inactive_fds;
167 
175  struct pollfd fds[MAX_FDS + 1];
176 
181 
183 
184  /* Read buffer and it's size. Will be grown on demand. */
186  uint8_t *read_buf;
187 } listener;
188 
189 #endif
const uint16_t id
#define MAX_QUEUE_MESSAGES
Max number of unprocessed queue messages.
Record in table for partially processed messages.
struct rx_info_t::@12::@13 hold
listener_msg * msg_freelist
struct pollfd fds[1000+1]
Tracked file descriptors, for polling.
uint32_t msg_flag_t
struct listener_msg::@6::@7 add_socket
int64_t largest_seq_id_seen
A queue message, with a command in the tagged union.
connection_info * info
Receiver of responses.
listener_msg msgs[(32)]
connection_info * fd_info[1000]
The connection info, corresponding to the the file descriptors tracked in l->fds. ...
bus_unpack_cb_res_t result
struct listener_msg::@6::@10 expect
Message bus.
struct listener_msg * next
struct bus * bus
struct listener_msg::@6::@9 hold
union rx_info_t::@12 u
struct rx_info_t * next
rx_info_t * rx_info_freelist
uint16_t tracked_fds
FDs currently tracked by listener.
rx_info_t rx_info[(1024)]
Per-socket connection context.
uint16_t rx_info_max_used
#define MAX_FDS
Max number of sockets to monitor.
struct rx_info_t::@12::@14 expect
union listener_msg::@6 u
bool error_occured
Flag indicating post-poll handling is necessary.
struct listener_msg::@6::@11 shutdown
rx_info_state state
uint16_t inactive_fds
File descriptors that are inactive due to errors, but have not yet been explicitly removed/closed by ...
struct listener_msg::@6::@8 remove_socket
size_t upstream_backpressure
#define MAX_PENDING_MESSAGES