31,7 → 31,7 |
*/ |
|
/** @file |
* \todo |
* Socket common core. |
*/ |
|
#ifndef __NET_SOCKET_CORE_H__ |
47,48 → 47,194 |
#include "../structures/int_map.h" |
#include "../structures/packet/packet.h" |
|
/** Initial size of the received packet queue. |
*/ |
#define SOCKET_INITIAL_RECEIVED_SIZE 4 |
|
/** Maximum size of the received packet queue. |
*/ |
#define SOCKET_MAX_RECEIVED_SIZE 0 |
|
/** Initial size of the sockets for acceptance queue. |
*/ |
#define SOCKET_INITIAL_ACCEPTED_SIZE 1 |
|
/** Maximum size of the sockets for acceptance queue. |
*/ |
#define SOCKET_MAX_ACCEPTEDED_SIZE 0 |
|
/** \todo |
/** Listening sockets' port map key. |
*/ |
#define SOCKET_MAP_KEY_LISTENING "L" |
|
/** Type definition of the socket core. |
* @see socket_core |
*/ |
typedef struct socket_core socket_core_t; |
typedef socket_core_t * socket_core_ref; |
|
/** Type definition of the socket core pointer. |
* @see socket_core |
*/ |
typedef socket_core_t * socket_core_ref; |
|
/** Type definition of the socket port. |
* @see socket_port |
*/ |
typedef struct socket_port socket_port_t; |
typedef socket_port_t * socket_port_ref; |
|
/** Type definition of the socket port pointer. |
* @see socket_port |
*/ |
typedef socket_port_t * socket_port_ref; |
|
/** Socket core. |
*/ |
struct socket_core{ |
/** Socket identifier. |
*/ |
int socket_id; |
/** Client application phone. |
*/ |
int phone; |
/** Bound port. |
*/ |
int port; |
/** Received packets queue. |
*/ |
dyn_fifo_t received; |
/** Sockets for acceptance queue. |
*/ |
dyn_fifo_t accepted; |
/** Protocol specific data. |
*/ |
void * specific_data; |
/** Socket ports map key. |
*/ |
const char * key; |
/** Length of the Socket ports map key. |
*/ |
size_t key_length; |
}; |
|
/** Sockets map. |
* The key is the socket identifier. |
*/ |
INT_MAP_DECLARE( socket_cores, socket_core_t ); |
|
/** Bount port sockets map. |
* The listening socket has the SOCKET_MAP_KEY_LISTENING key identifier whereas the other use the remote addresses. |
*/ |
GENERIC_CHAR_MAP_DECLARE( socket_port_map, socket_core_ref ); |
|
/** Ports map. |
* The key is the port number. |
*/ |
INT_MAP_DECLARE( socket_ports, socket_port_t ); |
|
/** Destroys local sockets. |
* Releases all buffered packets and calls the release function for each of the sockets. |
* @param[in] packet_phone The packet server phone to release buffered packets. |
* @param[in] local_sockets The local sockets to be destroyed. |
* @param[in,out] global_sockets The global sockets to be updated. |
* @param[in] socket_release The client release callback function. |
*/ |
void socket_cores_release( int packet_phone, socket_cores_ref local_sockets, socket_ports_ref global_sockets, void ( * socket_release )( socket_core_ref socket )); |
|
/** Binds the socket to the port. |
* The address port is used if set, a free port is used if not. |
* @param[in] local_sockets The local sockets to be searched. |
* @param[in,out] global_sockets The global sockets to be updated. |
* @param[in] socket_id The new socket identifier. |
* @param[in] addr The address to be bound to. |
* @param[in] addrlen The address length. |
* @param[in] free_ports_start The minimum free port. |
* @param[in] free_ports_end The maximum free port. |
* @param[in] last_used_port The last used free port. |
* @returns EOK on success. |
* @returns ENOTSOCK if the socket was not found. |
* @returns EAFNOSUPPORT if the address family is not supported. |
* @returns EADDRINUSE if the port is already in use. |
* @returns Other error codes as defined for the socket_bind_free_port() function. |
* @returns Other error codes as defined for the socket_bind_insert() function. |
*/ |
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 ); |
|
/** Binds the socket to a free port. |
* The first free port is used. |
* @param[in,out] global_sockets The global sockets to be updated. |
* @param[in,out] socket The socket to be bound. |
* @param[in] free_ports_start The minimum free port. |
* @param[in] free_ports_end The maximum free port. |
* @param[in] last_used_port The last used free port. |
* @returns EOK on success. |
* @returns ENOTCONN if no free port was found. |
* @returns Other error codes as defined for the socket_bind_insert() function. |
*/ |
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 ); |
|
/** Creates a new socket. |
* @param[in,out] local_sockets The local sockets to be updated. |
* @param[in] app_phone The application phone. |
* @param[in] specific_data The socket specific data. |
* @param[out] socket_id The new socket identifier. |
* @returns EOK on success. |
* @returns EBADMEM if the socket_id parameter is NULL. |
* @returns ENOMEM if there is not enough memory left. |
*/ |
int socket_create( socket_cores_ref local_sockets, int app_phone, void * specific_data, int * socket_id ); |
|
/** Destroys the socket. |
* If the socket is bound, the port is released. |
* Releases all buffered packets, calls the release function and removes the socket from the local sockets. |
* @param[in] packet_phone The packet server phone to release buffered packets. |
* @param[in] socket_id The socket identifier. |
* @param[in,out] local_sockets The local sockets to be updated. |
* @param[in,out] global_sockets The global sockets to be updated. |
* @param[in] socket_release The client release callback function. |
* @returns EOK on success. |
* @returns ENOTSOCK if the socket is not found. |
*/ |
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 )); |
|
/** Replies the packet or the packet queue data to the application via the socket. |
* Uses the current message processing fibril. |
* @param[in] packet The packet to be transfered. |
* @param[out] length The total data length. |
* @returns EOK on success. |
* @returns EBADMEM if the length parameter is NULL. |
* @returns ENOMEM if there is not enough memory left. |
* @returns Other error codes as defined for the data_reply() function. |
*/ |
int socket_reply_packets( packet_t packet, size_t * length ); |
|
/** Finds the bound port socket. |
* @param[in] global_sockets The global sockets to be searched. |
* @param[in] port The port number. |
* @param[in] key The socket key identifier. |
* @param[in] key_length The socket key length. |
* @returns The found socket. |
* @returns NULL if no socket was found. |
*/ |
socket_core_ref socket_port_find( socket_ports_ref global_sockets, int port, const char * key, size_t key_length ); |
|
/** Releases the socket port. |
* If the socket is bound the port entry is released. |
* If there are no more port entries the port is release. |
* @param[in] global_sockets The global sockets to be updated. |
* @param[in] socket The socket to be unbound. |
*/ |
void socket_port_release( socket_ports_ref global_sockets, socket_core_ref socket ); |
|
/** Adds the socket to an already bound port. |
* @param[in] global_sockets The global sockets to be updated. |
* @param[in] port The port number to be bound to. |
* @param[in] socket The socket to be added. |
* @param[in] key The socket key identifier. |
* @param[in] key_length The socket key length. |
* @returns EOK on success. |
* @returns ENOENT if the port is not already used. |
* @returns Other error codes as defined for the socket_port_add_core() function. |
*/ |
int socket_port_add( socket_ports_ref global_sockets, int port, socket_core_ref socket, const char * key, size_t key_length ); |
|
#endif |