/branches/network/uspace/srv/net/socket/socket_core.c |
---|
31,7 → 31,7 |
*/ |
/** @file |
* \todo |
* Socket common core implementation. |
*/ |
#include "../err.h" |
51,22 → 51,46 |
#include "socket_core.h" |
/** \todo |
/** Bound port sockets. |
*/ |
struct socket_port{ |
/** The bound sockets map. |
*/ |
socket_port_map_t map; |
/** The bound sockets count. |
*/ |
int count; |
}; |
/** \todo |
/** Binds the socket to the port. |
* The SOCKET_MAP_KEY_LISTENING key identifier is used. |
* @param[in] global_sockets The global sockets to be updated. |
* @param[in] socket The socket to be added. |
* @param[in] port The port number to be bound to. |
* @returns EOK on success. |
* @returns ENOMEM if there is not enough memory left. |
* @returns Other error codes as defined for the socket_ports_add() function. |
*/ |
int socket_bind_insert( socket_ports_ref global_sockets, socket_core_ref socket, int port ); |
/** \todo |
/** 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 The socket to be destroyed. |
* @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. |
*/ |
void socket_destroy_core( int packet_phone, socket_core_ref socket, socket_cores_ref local_sockets, socket_ports_ref global_sockets, void ( * socket_release )( socket_core_ref socket )); |
/** \todo |
/** Adds the socket to a socket port. |
* @param[in,out] socket_port The socket port structure. |
* @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 ENOMEM if there is not enough memory left. |
*/ |
int socket_port_add_core( socket_port_ref socket_port, socket_core_ref socket, const char * key, size_t key_length ); |
267,9 → 291,7 |
size_t * lengths; |
size_t index; |
if( ! length ){ |
return EINVAL; |
} |
if( ! length ) return EBADMEM; |
next_packet = pq_next( packet ); |
if( ! next_packet ){ |
// write all if only one fragment |
/branches/network/uspace/srv/net/socket/socket_messages.h |
---|
33,7 → 33,6 |
/** @file |
* Socket messages. |
* @see socket.h |
* \todo |
*/ |
46,21 → 45,65 |
#include "../include/socket_codes.h" |
/** Socket client messages. |
*/ |
typedef enum{ |
/** Creates a new socket. |
* @see socket() |
*/ |
NET_SOCKET = NET_SOCKET_FIRST, |
/** Binds the socket. |
* @see bind() |
*/ |
NET_SOCKET_BIND, |
/** Creates a new socket. |
* @see socket() |
*/ |
NET_SOCKET_LISTEN, |
/** Accepts an incomming connection. |
* @see accept() |
*/ |
NET_SOCKET_ACCEPT, |
/** Connects the socket. |
* @see connect() |
*/ |
NET_SOCKET_CONNECT, |
/** Closes the socket. |
* @see closesocket() |
*/ |
NET_SOCKET_CLOSE, |
/** Sends data via the stream socket. |
* @see send() |
*/ |
NET_SOCKET_SEND, |
/** Sends data via the datagram socket. |
* @see sendto() |
*/ |
NET_SOCKET_SENDTO, |
/** Receives data from the stream socket. |
* @see socket() |
*/ |
NET_SOCKET_RECV, |
/** Receives data from the datagram socket. |
* @see socket() |
*/ |
NET_SOCKET_RECVFROM, |
/** Gets the socket option. |
* @see getsockopt() |
*/ |
NET_SOCKET_GETSOCKOPT, |
/** Sets the socket option. |
* @see setsockopt() |
*/ |
NET_SOCKET_SETSOCKOPT, |
/** New socket for acceptence notification message. |
*/ |
NET_SOCKET_ACCEPTED, |
/** New data received notification message. |
*/ |
NET_SOCKET_RECEIVED, |
/** New socket data fragment size notification message. |
*/ |
NET_SOCKET_DATA_FRAGMENT_SIZE |
} socket_messages; |
68,27 → 111,86 |
*/ |
/*@{*/ |
#define SOCKET_SET_SOCKET_ID( call ) ( int * ) & IPC_GET_ARG1( call ) |
#define SOCKET_GET_SOCKET_ID( call ) ( int ) IPC_GET_ARG1( call ) |
#define SOCKET_SET_READ_DATA_LENGTH( call ) ( int * ) & IPC_GET_ARG1( call ) |
#define SOCKET_GET_READ_DATA_LENGTH( call ) ( int ) IPC_GET_ARG1( call ) |
/** Sets the socket identifier in the message answer. |
* @param[out] answer The message answer structure. |
*/ |
#define SOCKET_SET_SOCKET_ID( answer ) ( int * ) & IPC_GET_ARG1( answer ) |
#define SOCKET_GET_BACKLOG( call ) ( int ) IPC_GET_ARG2( call ) |
#define SOCKET_GET_OPT_LEVEL( call ) ( int ) IPC_GET_ARG2( call ) |
#define SOCKET_SET_ADDRESS_LENGTH( call ) ( socklen_t * ) & IPC_GET_ARG2( call ) |
#define SOCKET_GET_ADDRESS_LENGTH( call ) ( socklen_t ) IPC_GET_ARG2( call ) |
/** Returns the socket identifier message parameter. |
* @param[in] call The message call structure. |
*/ |
#define SOCKET_GET_SOCKET_ID( call ) ( int ) IPC_GET_ARG1( call ) |
/** Sets the read data length in the message answer. |
* @param[out] answer The message answer structure. |
*/ |
#define SOCKET_SET_READ_DATA_LENGTH( answer ) ( int * ) & IPC_GET_ARG1( answer ) |
/** Returns the read data length message parameter. |
* @param[in] call The message call structure. |
*/ |
#define SOCKET_GET_READ_DATA_LENGTH( call ) ( int ) IPC_GET_ARG1( call ) |
/** Returns the backlog message parameter. |
* @param[in] call The message call structure. |
*/ |
#define SOCKET_GET_BACKLOG( call ) ( int ) IPC_GET_ARG2( call ) |
/** Returns the option level message parameter. |
* @param[in] call The message call structure. |
*/ |
#define SOCKET_GET_OPT_LEVEL( call ) ( int ) IPC_GET_ARG2( call ) |
/** Sets the address length in the message answer. |
* @param[out] answer The message answer structure. |
*/ |
#define SOCKET_SET_ADDRESS_LENGTH( answer ) ( socklen_t * ) & IPC_GET_ARG2( answer ) |
/** Returns the address length message parameter. |
* @param[in] call The message call structure. |
*/ |
#define SOCKET_GET_ADDRESS_LENGTH( call ) ( socklen_t ) IPC_GET_ARG2( call ) |
/** Returns the data fragment size message parameter. |
* @param[in] call The message call structure. |
*/ |
#define SOCKET_GET_DATA_FRAGMENT_SIZE( call ) ( size_t ) IPC_GET_ARG2( call ) |
#define SOCKET_SET_DATA_FRAGMENT_SIZE( call ) ( size_t * ) & IPC_GET_ARG2( call ) |
#define SOCKET_SET_HEADER_SIZE( call ) ( int * ) & IPC_GET_ARG3( call ) |
#define SOCKET_GET_HEADER_SIZE( call ) ( int ) IPC_GET_ARG3( call ) |
/** Sets the data fragment size in the message answer. |
* @param[out] answer The message answer structure. |
*/ |
#define SOCKET_SET_DATA_FRAGMENT_SIZE( answer ) ( size_t * ) & IPC_GET_ARG2( answer ) |
#define SOCKET_GET_FLAGS( call ) ( int ) IPC_GET_ARG4( call ) |
#define SOCKET_GET_OPT_NAME( call ) ( int ) IPC_GET_ARG4( call ) |
/** Sets the header size in the message answer. |
* @param[out] answer The message answer structure. |
*/ |
#define SOCKET_SET_HEADER_SIZE( answer ) ( int * ) & IPC_GET_ARG3( answer ) |
#define SOCKET_GET_DATA_FRAGMENTS( call ) ( int ) IPC_GET_ARG5( call ) |
#define SOCKET_GET_NEW_SOCKET_ID( call ) ( int ) IPC_GET_ARG5( call ) |
/** Returns the header size message parameter. |
* @param[in] call The message call structure. |
*/ |
#define SOCKET_GET_HEADER_SIZE( call ) ( int ) IPC_GET_ARG3( call ) |
/** Returns the flags message parameter. |
* @param[in] call The message call structure. |
*/ |
#define SOCKET_GET_FLAGS( call ) ( int ) IPC_GET_ARG4( call ) |
/** Returns the option name message parameter. |
* @param[in] call The message call structure. |
*/ |
#define SOCKET_GET_OPT_NAME( call ) ( int ) IPC_GET_ARG4( call ) |
/** Returns the data fragments message parameter. |
* @param[in] call The message call structure. |
*/ |
#define SOCKET_GET_DATA_FRAGMENTS( call ) ( int ) IPC_GET_ARG5( call ) |
/** Returns the new socket identifier message parameter. |
* @param[in] call The message call structure. |
*/ |
#define SOCKET_GET_NEW_SOCKET_ID( call ) ( int ) IPC_GET_ARG5( call ) |
/*@}*/ |
#endif |
/branches/network/uspace/srv/net/socket/socket_core.h |
---|
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 |
/branches/network/uspace/srv/net/socket/socket_client.c |
---|
194,17 → 194,17 |
static sockets_ref socket_get_sockets( void ); |
/** Default thread for new connections. |
* @param iid The initial message identifier. Input parameter. |
* @param icall The initial message call structure. Input parameter. |
* @param[in] iid The initial message identifier. |
* @param[in] icall The initial message call structure. |
*/ |
void socket_connection( ipc_callid_t iid, ipc_call_t * icall ); |
/** Sends message to the socket parent module with specified data. |
* @param socket_id Socket identifier. Input parameter. |
* @param message The action message. Input parameter. |
* @param arg2 The second message parameter. Input parameter. |
* @param data The data to be sent. Input parameter. |
* @param datalength The data length. Input parameter. |
* @param[in] socket_id Socket identifier. |
* @param[in] message The action message. |
* @param[in] arg2 The second message parameter. |
* @param[in] data The data to be sent. |
* @param[in] datalength The data length. |
* @returns EOK on success. |
* @returns ENOTSOCK if the socket is not found. |
* @returns EBADMEM if the data parameter is NULL. |
214,26 → 214,26 |
int socket_send_data( int socket_id, ipcarg_t message, ipcarg_t arg2, const void * data, size_t datalength ); |
/** Initializes a new socket specific data. |
* @param socket The socket to be initialized. Input/output parameter. |
* @param socket_id The new socket identifier. Input parameter. |
* @param phone The parent module phone. Input parameter. |
* @param service The parent module service. Input parameter. |
* @param[in,out] socket The socket to be initialized. |
* @param[in] socket_id The new socket identifier. |
* @param[in] phone The parent module phone. |
* @param[in] service The parent module service. |
*/ |
void socket_initialize( socket_ref socket, int socket_id, int phone, services_t service ); |
/** Clears and destroys the socket. |
* @param socket The socket to be destroyed. Input parameter. |
* @param[in] socket The socket to be destroyed. |
*/ |
void socket_destroy( socket_ref socket ); |
/** Receives data via the socket. |
* @param message The action message. Input parameter. |
* @param socket_id Socket identifier. Input parameter. |
* @param data The data buffer to be filled. Output parameter. |
* @param datalength The data length. Input parameter. |
* @param flags Various receive flags. Input parameter. |
* @param fromaddr The source address. May be NULL for connected sockets. Output parameter. |
* @param addrlen The address length. The maximum address length is read. The actual address length is set. Used only if fromaddr is not NULL. Input/output parameter. |
* @param[in] message The action message. |
* @param[in] socket_id Socket identifier. |
* @param[out] data The data buffer to be filled. |
* @param[in] datalength The data length. |
* @param[in] flags Various receive flags. |
* @param[out] fromaddr The source address. May be NULL for connected sockets. |
* @param[in,out] addrlen The address length. The maximum address length is read. The actual address length is set. Used only if fromaddr is not NULL. |
* @returns EOK on success. |
* @returns ENOTSOCK if the socket is not found. |
* @returns EBADMEM if the data parameter is NULL. |
244,13 → 244,13 |
/** Sends data via the socket to the remote address. |
* Binds the socket to a free port if not already connected/bound. |
* @param message The action message. Input parameter. |
* @param socket_id Socket identifier. Input parameter. |
* @param data The data to be sent. Input parameter. |
* @param datalength The data length. Input parameter. |
* @param flags Various send flags. Input parameter. |
* @param toaddr The destination address. May be NULL for connected sockets. Input parameter. |
* @param addrlen The address length. Used only if toaddr is not NULL. Input parameter. |
* @param[in] message The action message. |
* @param[in] socket_id Socket identifier. |
* @param[in] data The data to be sent. |
* @param[in] datalength The data length. |
* @param[in] flags Various send flags. |
* @param[in] toaddr The destination address. May be NULL for connected sockets. |
* @param[in] addrlen The address length. Used only if toaddr is not NULL. |
* @returns EOK on success. |
* @returns ENOTSOCK if the socket is not found. |
* @returns EBADMEM if the data or toaddr parameter is NULL. |