Libtrap: Internal development docs  1.16.1
ifc_tcpip_internal.h
Go to the documentation of this file.
1 /**
2  * \file ifc_tcpip_internal.h
3  * \brief TRAP TCP/IP interfaces private structures
4  * \author Tomas Cejka <cejkat@cesnet.cz>
5  * \date 2014
6  */
7 /*
8  * Copyright (C) 2013 CESNET
9  *
10  * LICENSE TERMS
11  *
12  * Redistribution and use in source and binary forms, with or without
13  * modification, are permitted provided that the following conditions
14  * are met:
15  * 1. Redistributions of source code must retain the above copyright
16  * notice, this list of conditions and the following disclaimer.
17  * 2. Redistributions in binary form must reproduce the above copyright
18  * notice, this list of conditions and the following disclaimer in
19  * the documentation and/or other materials provided with the
20  * distribution.
21  * 3. Neither the name of the Company nor the names of its contributors
22  * may be used to endorse or promote products derived from this
23  * software without specific prior written permission.
24  *
25  * ALTERNATIVELY, provided that this notice is retained in full, this
26  * product may be distributed under the terms of the GNU General Public
27  * License (GPL) version 2 or later, in which case the provisions
28  * of the GPL apply INSTEAD OF those given above.
29  *
30  * This software is provided ``as is'', and any express or implied
31  * warranties, including, but not limited to, the implied warranties of
32  * merchantability and fitness for a particular purpose are disclaimed.
33  * In no event shall the company or contributors be liable for any
34  * direct, indirect, incidental, special, exemplary, or consequential
35  * damages (including, but not limited to, procurement of substitute
36  * goods or services; loss of use, data, or profits; or business
37  * interruption) however caused and on any theory of liability, whether
38  * in contract, strict liability, or tort (including negligence or
39  * otherwise) arising in any way out of the use of this software, even
40  * if advised of the possibility of such damage.
41  *
42  */
43 
44 #include "ifc_socket_common.h"
45 
46 /** \addtogroup trap_ifc
47  * @{
48  */
49 
50 /** \addtogroup tcpip_ifc
51  * @{
52  */
53 
54  /**
55  * \defgroup tcpip_sender TCPIP output IFC
56  * @{
57  */
58 
59 /**
60  * \brief Structure for TCP/IP IFC client information.
61  */
62 typedef struct client_s {
63  int sd; /**< Client socket descriptor */
64  int pfds_index; /**< Client pfds struct array index. */
65  void *sending_pointer; /**< Pointer to data in client's assigned buffer */
66 
67  uint64_t timer_total; /**< Total time spent sending (microseconds) since client connection */
68  uint64_t timeouts; /**< Number of messages dropped (since connection) due to client blocking active buffer */
69 
70  uint32_t timer_last; /**< Time spent on last send call [microseconds] */
71  uint32_t pending_bytes; /**< The size of data that must be sent */
72  uint32_t id; /**< Client identification - PID for unix socket, port number for TCP socket */
73  uint32_t assigned_buffer; /**< Index of assigned buffer in array of buffers */
74 } client_t;
75 
76 /**
77  * \brief Structure for TCP/IP IFC private information.
78  */
79 typedef struct tcpip_sender_private_s {
80  trap_ctx_priv_t *ctx; /**< Libtrap context */
81 
82  enum tcpip_ifc_sockettype socket_type; /**< Socket type (TCPIP / UNIX) */
83 
84  int term_pipe[2]; /**< File descriptor pair for select() termination */
85  int server_sd; /**< Server socket descriptor */
86 
87  char *server_port; /**< TCPIP port number / UNIX socket path */
88  char is_terminated; /**< Termination flag */
89  char initialized; /**< Initialization flag */
90 
91  uint64_t autoflush_timestamp; /**< Time when the last buffer was finished - used for autoflush */
92  uint64_t clients_bit_arr; /**< Bit array of currently connected clients - lowest bit = index 0, highest bit = index 63 */
93 
94  uint32_t ifc_idx; /**< Index of interface in 'out_ifc_list' array */
95  uint32_t connected_clients; /**< Number of currently connected clients */
96  uint32_t clients_arr_size; /**< Maximum number of clients */
97  uint32_t buffer_count; /**< Number of buffers used */
98  uint32_t buffer_size; /**< Buffer size [bytes] */
99  uint32_t active_buffer; /**< Index of active buffer in 'buffers' array */
100 
101  buffer_t *buffers; /**< Array of buffer structures */
102  client_t *clients; /**< Array of client structures */
103 
104  struct pollfd *clients_pfds; /**< Array of clients pfds for poll */
105 
106  pthread_t accept_thr; /**< Pthread structure containing info about accept thread */
107  pthread_t send_thr; /**< Pthread structure containing info about sending thread */
108 
109  pthread_mutex_t mtx_no_data; /**< Mutex for cond_no_data */
110  pthread_cond_t cond_no_data; /**< Condition struct used when waiting for new data */
111  pthread_cond_t cond_full_buffer; /**< Condition struct used when waiting for free buffer */
113 
114 /**
115  * @}
116  */
117 
118 /**
119  * \defgroup tcpip_receiver TCPIP input IFC
120  * @{
121  */
122 typedef struct tcpip_receiver_private_s {
123  trap_ctx_priv_t *ctx; /**< Libtrap context */
124  char *dest_addr;
125  char *dest_port;
126  char connected;
128  int sd;
130  void *data_pointer; /**< Pointer to next free byte, if NULL, we ended in header */
131  uint32_t data_wait_size; /**< Missing data to accept in the next function call */
132  void *ext_buffer; /**< Pointer to buffer that was passed by higher layer - this is the place we write */
133  uint32_t ext_buffer_size; /**< size of content of the extbuffer */
134  trap_buffer_header_t int_mess_header; /**< Internal message header - used for message_buffer payload size \note message_buffer size is sizeof(tcpip_tdu_header_t) + payload size */
135  uint32_t ifc_idx;
137 
138 /**
139  * @}
140  */
141 
142 /**
143  * @}
144  */
145 
146 /**
147  * @}
148  */
149 
void * sending_pointer
Output buffer structure.
pthread_cond_t cond_full_buffer
uint64_t timer_total
enum tcpip_ifc_sockettype socket_type
uint32_t assigned_buffer
uint64_t timeouts
struct tcpip_receiver_private_s tcpip_receiver_private_t
struct pollfd * clients_pfds
uint32_t timer_last
Structure for TCP/IP IFC private information.
struct tcpip_sender_private_s tcpip_sender_private_t
Structure for TCP/IP IFC private information.
trap_buffer_header_t int_mess_header
Structure for TCP/IP IFC client information.
struct client_s client_t
Structure for TCP/IP IFC client information.
This file contains common functions and structures used in socket based interfaces (tcp-ip / tls)...
enum tcpip_ifc_sockettype socket_type
uint32_t pending_bytes
tcpip_ifc_sockettype
Definition: ifc_tcpip.h:70