Rev 4747 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
| Rev 4747 | Rev 4756 | ||
|---|---|---|---|
| Line 29... | Line 29... | ||
| 29 | /** @addtogroup socket |
29 | /** @addtogroup socket |
| 30 | * @{ |
30 | * @{ |
| 31 | */ |
31 | */ |
| 32 | 32 | ||
| 33 | /** @file |
33 | /** @file |
| 34 | * \todo |
34 | * Socket common core. |
| 35 | */ |
35 | */ |
| 36 | 36 | ||
| 37 | #ifndef __NET_SOCKET_CORE_H__ |
37 | #ifndef __NET_SOCKET_CORE_H__ |
| 38 | #define __NET_SOCKET_CORE_H__ |
38 | #define __NET_SOCKET_CORE_H__ |
| 39 | 39 | ||
| Line 45... | Line 45... | ||
| 45 | #include "../structures/generic_char_map.h" |
45 | #include "../structures/generic_char_map.h" |
| 46 | #include "../structures/dynamic_fifo.h" |
46 | #include "../structures/dynamic_fifo.h" |
| 47 | #include "../structures/int_map.h" |
47 | #include "../structures/int_map.h" |
| 48 | #include "../structures/packet/packet.h" |
48 | #include "../structures/packet/packet.h" |
| 49 | 49 | ||
| - | 50 | /** Initial size of the received packet queue. |
|
| - | 51 | */ |
|
| 50 | #define SOCKET_INITIAL_RECEIVED_SIZE 4 |
52 | #define SOCKET_INITIAL_RECEIVED_SIZE 4 |
| - | 53 | ||
| - | 54 | /** Maximum size of the received packet queue. |
|
| - | 55 | */ |
|
| 51 | #define SOCKET_MAX_RECEIVED_SIZE 0 |
56 | #define SOCKET_MAX_RECEIVED_SIZE 0 |
| 52 | 57 | ||
| - | 58 | /** Initial size of the sockets for acceptance queue. |
|
| - | 59 | */ |
|
| 53 | #define SOCKET_INITIAL_ACCEPTED_SIZE 1 |
60 | #define SOCKET_INITIAL_ACCEPTED_SIZE 1 |
| - | 61 | ||
| - | 62 | /** Maximum size of the sockets for acceptance queue. |
|
| - | 63 | */ |
|
| 54 | #define SOCKET_MAX_ACCEPTEDED_SIZE 0 |
64 | #define SOCKET_MAX_ACCEPTEDED_SIZE 0 |
| 55 | 65 | ||
| 56 | /** \todo |
66 | /** Listening sockets' port map key. |
| 57 | */ |
67 | */ |
| 58 | #define SOCKET_MAP_KEY_LISTENING "L" |
68 | #define SOCKET_MAP_KEY_LISTENING "L" |
| 59 | 69 | ||
| - | 70 | /** Type definition of the socket core. |
|
| - | 71 | * @see socket_core |
|
| - | 72 | */ |
|
| 60 | typedef struct socket_core socket_core_t; |
73 | typedef struct socket_core socket_core_t; |
| 61 | typedef socket_core_t * socket_core_ref; |
- | |
| 62 | 74 | ||
| - | 75 | /** Type definition of the socket core pointer. |
|
| - | 76 | * @see socket_core |
|
| - | 77 | */ |
|
| - | 78 | typedef socket_core_t * socket_core_ref; |
|
| - | 79 | ||
| - | 80 | /** Type definition of the socket port. |
|
| - | 81 | * @see socket_port |
|
| - | 82 | */ |
|
| 63 | typedef struct socket_port socket_port_t; |
83 | typedef struct socket_port socket_port_t; |
| 64 | typedef socket_port_t * socket_port_ref; |
- | |
| 65 | 84 | ||
| - | 85 | /** Type definition of the socket port pointer. |
|
| - | 86 | * @see socket_port |
|
| - | 87 | */ |
|
| - | 88 | typedef socket_port_t * socket_port_ref; |
|
| - | 89 | ||
| - | 90 | /** Socket core. |
|
| - | 91 | */ |
|
| 66 | struct socket_core{ |
92 | struct socket_core{ |
| - | 93 | /** Socket identifier. |
|
| - | 94 | */ |
|
| 67 | int socket_id; |
95 | int socket_id; |
| - | 96 | /** Client application phone. |
|
| - | 97 | */ |
|
| 68 | int phone; |
98 | int phone; |
| - | 99 | /** Bound port. |
|
| - | 100 | */ |
|
| 69 | int port; |
101 | int port; |
| - | 102 | /** Received packets queue. |
|
| - | 103 | */ |
|
| 70 | dyn_fifo_t received; |
104 | dyn_fifo_t received; |
| - | 105 | /** Sockets for acceptance queue. |
|
| - | 106 | */ |
|
| 71 | dyn_fifo_t accepted; |
107 | dyn_fifo_t accepted; |
| - | 108 | /** Protocol specific data. |
|
| - | 109 | */ |
|
| 72 | void * specific_data; |
110 | void * specific_data; |
| - | 111 | /** Socket ports map key. |
|
| - | 112 | */ |
|
| 73 | const char * key; |
113 | const char * key; |
| - | 114 | /** Length of the Socket ports map key. |
|
| - | 115 | */ |
|
| 74 | size_t key_length; |
116 | size_t key_length; |
| 75 | }; |
117 | }; |
| 76 | 118 | ||
| - | 119 | /** Sockets map. |
|
| - | 120 | * The key is the socket identifier. |
|
| - | 121 | */ |
|
| 77 | INT_MAP_DECLARE( socket_cores, socket_core_t ); |
122 | INT_MAP_DECLARE( socket_cores, socket_core_t ); |
| 78 | 123 | ||
| - | 124 | /** Bount port sockets map. |
|
| - | 125 | * The listening socket has the SOCKET_MAP_KEY_LISTENING key identifier whereas the other use the remote addresses. |
|
| - | 126 | */ |
|
| 79 | GENERIC_CHAR_MAP_DECLARE( socket_port_map, socket_core_ref ); |
127 | GENERIC_CHAR_MAP_DECLARE( socket_port_map, socket_core_ref ); |
| 80 | 128 | ||
| - | 129 | /** Ports map. |
|
| - | 130 | * The key is the port number. |
|
| - | 131 | */ |
|
| 81 | INT_MAP_DECLARE( socket_ports, socket_port_t ); |
132 | INT_MAP_DECLARE( socket_ports, socket_port_t ); |
| 82 | 133 | ||
| - | 134 | /** Destroys local sockets. |
|
| - | 135 | * Releases all buffered packets and calls the release function for each of the sockets. |
|
| - | 136 | * @param[in] packet_phone The packet server phone to release buffered packets. |
|
| - | 137 | * @param[in] local_sockets The local sockets to be destroyed. |
|
| - | 138 | * @param[in,out] global_sockets The global sockets to be updated. |
|
| - | 139 | * @param[in] socket_release The client release callback function. |
|
| - | 140 | */ |
|
| 83 | void socket_cores_release( int packet_phone, socket_cores_ref local_sockets, socket_ports_ref global_sockets, void ( * socket_release )( socket_core_ref socket )); |
141 | void socket_cores_release( int packet_phone, socket_cores_ref local_sockets, socket_ports_ref global_sockets, void ( * socket_release )( socket_core_ref socket )); |
| 84 | 142 | ||
| - | 143 | /** Binds the socket to the port. |
|
| - | 144 | * The address port is used if set, a free port is used if not. |
|
| - | 145 | * @param[in] local_sockets The local sockets to be searched. |
|
| - | 146 | * @param[in,out] global_sockets The global sockets to be updated. |
|
| - | 147 | * @param[in] socket_id The new socket identifier. |
|
| - | 148 | * @param[in] addr The address to be bound to. |
|
| - | 149 | * @param[in] addrlen The address length. |
|
| - | 150 | * @param[in] free_ports_start The minimum free port. |
|
| - | 151 | * @param[in] free_ports_end The maximum free port. |
|
| - | 152 | * @param[in] last_used_port The last used free port. |
|
| - | 153 | * @returns EOK on success. |
|
| - | 154 | * @returns ENOTSOCK if the socket was not found. |
|
| - | 155 | * @returns EAFNOSUPPORT if the address family is not supported. |
|
| - | 156 | * @returns EADDRINUSE if the port is already in use. |
|
| - | 157 | * @returns Other error codes as defined for the socket_bind_free_port() function. |
|
| - | 158 | * @returns Other error codes as defined for the socket_bind_insert() function. |
|
| - | 159 | */ |
|
| 85 | int socket_bind( socket_cores_ref local_sockets, socket_ports_ref global_sockets, int socket_id, void * addr, size_t addrlen, int free_ports_start, int free_ports_end, int last_used_port ); |
160 | int socket_bind( socket_cores_ref local_sockets, socket_ports_ref global_sockets, int socket_id, void * addr, size_t addrlen, int free_ports_start, int free_ports_end, int last_used_port ); |
| - | 161 | ||
| - | 162 | /** Binds the socket to a free port. |
|
| - | 163 | * The first free port is used. |
|
| - | 164 | * @param[in,out] global_sockets The global sockets to be updated. |
|
| - | 165 | * @param[in,out] socket The socket to be bound. |
|
| - | 166 | * @param[in] free_ports_start The minimum free port. |
|
| - | 167 | * @param[in] free_ports_end The maximum free port. |
|
| - | 168 | * @param[in] last_used_port The last used free port. |
|
| - | 169 | * @returns EOK on success. |
|
| - | 170 | * @returns ENOTCONN if no free port was found. |
|
| - | 171 | * @returns Other error codes as defined for the socket_bind_insert() function. |
|
| - | 172 | */ |
|
| 86 | int socket_bind_free_port( socket_ports_ref global_sockets, socket_core_ref socket, int free_ports_start, int free_ports_end, int last_used_port ); |
173 | int socket_bind_free_port( socket_ports_ref global_sockets, socket_core_ref socket, int free_ports_start, int free_ports_end, int last_used_port ); |
| - | 174 | ||
| - | 175 | /** Creates a new socket. |
|
| - | 176 | * @param[in,out] local_sockets The local sockets to be updated. |
|
| - | 177 | * @param[in] app_phone The application phone. |
|
| - | 178 | * @param[in] specific_data The socket specific data. |
|
| - | 179 | * @param[out] socket_id The new socket identifier. |
|
| - | 180 | * @returns EOK on success. |
|
| - | 181 | * @returns EBADMEM if the socket_id parameter is NULL. |
|
| - | 182 | * @returns ENOMEM if there is not enough memory left. |
|
| - | 183 | */ |
|
| 87 | int socket_create( socket_cores_ref local_sockets, int app_phone, void * specific_data, int * socket_id ); |
184 | int socket_create( socket_cores_ref local_sockets, int app_phone, void * specific_data, int * socket_id ); |
| - | 185 | ||
| - | 186 | /** Destroys the socket. |
|
| - | 187 | * If the socket is bound, the port is released. |
|
| - | 188 | * Releases all buffered packets, calls the release function and removes the socket from the local sockets. |
|
| - | 189 | * @param[in] packet_phone The packet server phone to release buffered packets. |
|
| - | 190 | * @param[in] socket_id The socket identifier. |
|
| - | 191 | * @param[in,out] local_sockets The local sockets to be updated. |
|
| - | 192 | * @param[in,out] global_sockets The global sockets to be updated. |
|
| - | 193 | * @param[in] socket_release The client release callback function. |
|
| - | 194 | * @returns EOK on success. |
|
| - | 195 | * @returns ENOTSOCK if the socket is not found. |
|
| - | 196 | */ |
|
| 88 | int socket_destroy( int packet_phone, int socket_id, socket_cores_ref local_sockets, socket_ports_ref global_sockets, void ( * socket_release )( socket_core_ref socket )); |
197 | int socket_destroy( int packet_phone, int socket_id, socket_cores_ref local_sockets, socket_ports_ref global_sockets, void ( * socket_release )( socket_core_ref socket )); |
| - | 198 | ||
| - | 199 | /** Replies the packet or the packet queue data to the application via the socket. |
|
| - | 200 | * Uses the current message processing fibril. |
|
| - | 201 | * @param[in] packet The packet to be transfered. |
|
| - | 202 | * @param[out] length The total data length. |
|
| - | 203 | * @returns EOK on success. |
|
| - | 204 | * @returns EBADMEM if the length parameter is NULL. |
|
| - | 205 | * @returns ENOMEM if there is not enough memory left. |
|
| - | 206 | * @returns Other error codes as defined for the data_reply() function. |
|
| - | 207 | */ |
|
| 89 | int socket_reply_packets( packet_t packet, size_t * length ); |
208 | int socket_reply_packets( packet_t packet, size_t * length ); |
| - | 209 | ||
| - | 210 | /** Finds the bound port socket. |
|
| - | 211 | * @param[in] global_sockets The global sockets to be searched. |
|
| - | 212 | * @param[in] port The port number. |
|
| - | 213 | * @param[in] key The socket key identifier. |
|
| - | 214 | * @param[in] key_length The socket key length. |
|
| - | 215 | * @returns The found socket. |
|
| - | 216 | * @returns NULL if no socket was found. |
|
| - | 217 | */ |
|
| 90 | socket_core_ref socket_port_find( socket_ports_ref global_sockets, int port, const char * key, size_t key_length ); |
218 | socket_core_ref socket_port_find( socket_ports_ref global_sockets, int port, const char * key, size_t key_length ); |
| - | 219 | ||
| - | 220 | /** Releases the socket port. |
|
| - | 221 | * If the socket is bound the port entry is released. |
|
| - | 222 | * If there are no more port entries the port is release. |
|
| - | 223 | * @param[in] global_sockets The global sockets to be updated. |
|
| - | 224 | * @param[in] socket The socket to be unbound. |
|
| - | 225 | */ |
|
| 91 | void socket_port_release( socket_ports_ref global_sockets, socket_core_ref socket ); |
226 | void socket_port_release( socket_ports_ref global_sockets, socket_core_ref socket ); |
| - | 227 | ||
| - | 228 | /** Adds the socket to an already bound port. |
|
| - | 229 | * @param[in] global_sockets The global sockets to be updated. |
|
| - | 230 | * @param[in] port The port number to be bound to. |
|
| - | 231 | * @param[in] socket The socket to be added. |
|
| - | 232 | * @param[in] key The socket key identifier. |
|
| - | 233 | * @param[in] key_length The socket key length. |
|
| - | 234 | * @returns EOK on success. |
|
| - | 235 | * @returns ENOENT if the port is not already used. |
|
| - | 236 | * @returns Other error codes as defined for the socket_port_add_core() function. |
|
| - | 237 | */ |
|
| 92 | int socket_port_add( socket_ports_ref global_sockets, int port, socket_core_ref socket, const char * key, size_t key_length ); |
238 | int socket_port_add( socket_ports_ref global_sockets, int port, socket_core_ref socket, const char * key, size_t key_length ); |
| 93 | 239 | ||
| 94 | #endif |
240 | #endif |
| 95 | 241 | ||
| 96 | /** @} |
242 | /** @} |