Changeset a7a85d16 in mainline for uspace/lib/net/include/socket_core.h
- Timestamp:
- 2010-10-16T17:16:30Z (14 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 668f8cbf, e0e568ff, f14291b
- Parents:
- ef689ef0 (diff), c62ae1d6 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/net/include/socket_core.h
ref689ef0 ra7a85d16 27 27 */ 28 28 29 /** @addtogroup socket29 /** @addtogroup libnet 30 30 * @{ 31 31 */ 32 32 33 33 /** @file 34 * 34 * Socket common core. 35 35 */ 36 36 37 #ifndef __NET_SOCKET_CORE_H__38 #define __NET_SOCKET_CORE_H__37 #ifndef LIBNET_SOCKET_CORE_H_ 38 #define LIBNET_SOCKET_CORE_H_ 39 39 40 40 #include <sys/types.h> 41 42 #include <net/in.h>43 #include <net/device.h>44 41 #include <adt/generic_char_map.h> 45 42 #include <adt/dynamic_fifo.h> 46 43 #include <adt/int_map.h> 44 #include <net/in.h> 45 #include <net/device.h> 47 46 #include <net/packet.h> 48 47 49 /** Initial size of the received packet queue. 50 */ 48 /** Initial size of the received packet queue. */ 51 49 #define SOCKET_INITIAL_RECEIVED_SIZE 4 52 50 53 /** Maximum size of the received packet queue. 54 */ 55 #define SOCKET_MAX_RECEIVED_SIZE 0 51 /** Maximum size of the received packet queue. */ 52 #define SOCKET_MAX_RECEIVED_SIZE 0 56 53 57 /** Initial size of the sockets for acceptance queue. 58 */ 54 /** Initial size of the sockets for acceptance queue. */ 59 55 #define SOCKET_INITIAL_ACCEPTED_SIZE 1 60 56 61 /** Maximum size of the sockets for acceptance queue. 62 */ 63 #define SOCKET_MAX_ACCEPTEDED_SIZE 0 57 /** Maximum size of the sockets for acceptance queue. */ 58 #define SOCKET_MAX_ACCEPTEDED_SIZE 0 64 59 65 /** Listening sockets' port map key. 66 */ 60 /** Listening sockets' port map key. */ 67 61 #define SOCKET_MAP_KEY_LISTENING "L" 68 62 69 63 /** Type definition of the socket core. 70 * 64 * @see socket_core 71 65 */ 72 typedef struct socket_core 66 typedef struct socket_core socket_core_t; 73 67 74 68 /** Type definition of the socket core pointer. 75 * 69 * @see socket_core 76 70 */ 77 typedef socket_core_t * 71 typedef socket_core_t *socket_core_ref; 78 72 79 73 /** Type definition of the socket port. 80 * 74 * @see socket_port 81 75 */ 82 typedef struct socket_port 76 typedef struct socket_port socket_port_t; 83 77 84 78 /** Type definition of the socket port pointer. 85 * 79 * @see socket_port 86 80 */ 87 typedef socket_port_t * 81 typedef socket_port_t *socket_port_ref; 88 82 89 /** Socket core. 90 */ 91 struct socket_core{ 92 /** Socket identifier. 93 */ 83 /** Socket core. */ 84 struct socket_core { 85 /** Socket identifier. */ 94 86 int socket_id; 95 /** Client application phone. 96 */ 87 /** Client application phone. */ 97 88 int phone; 98 /** Bound port. 99 */ 89 /** Bound port. */ 100 90 int port; 101 /** Received packets queue. 102 */ 91 /** Received packets queue. */ 103 92 dyn_fifo_t received; 104 /** Sockets for acceptance queue. 105 */ 93 /** Sockets for acceptance queue. */ 106 94 dyn_fifo_t accepted; 107 /** Protocol specific data. 108 */ 109 void * specific_data; 110 /** Socket ports map key. 111 */ 112 const char * key; 113 /** Length of the Socket ports map key. 114 */ 95 /** Protocol specific data. */ 96 void *specific_data; 97 /** Socket ports map key. */ 98 const char *key; 99 /** Length of the Socket ports map key. */ 115 100 size_t key_length; 116 101 }; 117 102 118 103 /** Sockets map. 119 * 104 * The key is the socket identifier. 120 105 */ 121 106 INT_MAP_DECLARE(socket_cores, socket_core_t); 122 107 123 108 /** Bount port sockets map. 124 * The listening socket has the SOCKET_MAP_KEY_LISTENING key identifier whereas the other use the remote addresses. 109 * 110 * The listening socket has the SOCKET_MAP_KEY_LISTENING key identifier whereas 111 * the other use the remote addresses. 125 112 */ 126 113 GENERIC_CHAR_MAP_DECLARE(socket_port_map, socket_core_ref); 127 114 128 115 /** Ports map. 129 * 116 * The key is the port number. 130 117 */ 131 118 INT_MAP_DECLARE(socket_ports, socket_port_t); 132 119 133 /** Destroys local sockets. 134 * Releases all buffered packets and calls the release function for each of the sockets. 135 * @param[in] packet_phone The packet server phone to release buffered packets. 136 * @param[in] local_sockets The local sockets to be destroyed. 137 * @param[in,out] global_sockets The global sockets to be updated. 138 * @param[in] socket_release The client release callback function. 139 */ 140 extern 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 142 /** Binds the socket to the port. 143 * The address port is used if set, a free port is used if not. 144 * @param[in] local_sockets The local sockets to be searched. 145 * @param[in,out] global_sockets The global sockets to be updated. 146 * @param[in] socket_id The new socket identifier. 147 * @param[in] addr The address to be bound to. 148 * @param[in] addrlen The address length. 149 * @param[in] free_ports_start The minimum free port. 150 * @param[in] free_ports_end The maximum free port. 151 * @param[in] last_used_port The last used free port. 152 * @returns EOK on success. 153 * @returns ENOTSOCK if the socket was not found. 154 * @returns EAFNOSUPPORT if the address family is not supported. 155 * @returns EADDRINUSE if the port is already in use. 156 * @returns Other error codes as defined for the socket_bind_free_port() function. 157 * @returns Other error codes as defined for the socket_bind_insert() function. 158 */ 159 extern 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 161 /** Binds the socket to a free port. 162 * The first free port is used. 163 * @param[in,out] global_sockets The global sockets to be updated. 164 * @param[in,out] socket The socket to be bound. 165 * @param[in] free_ports_start The minimum free port. 166 * @param[in] free_ports_end The maximum free port. 167 * @param[in] last_used_port The last used free port. 168 * @returns EOK on success. 169 * @returns ENOTCONN if no free port was found. 170 * @returns Other error codes as defined for the socket_bind_insert() function. 171 */ 172 extern 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 174 /** Creates a new socket. 175 * @param[in,out] local_sockets The local sockets to be updated. 176 * @param[in] app_phone The application phone. 177 * @param[in] specific_data The socket specific data. 178 * @param[in,out] socket_id The new socket identifier. A new identifier is chosen if set to zero (0) or negative. A negative identifier is chosen if set to negative. 179 * @returns EOK on success. 180 * @returns EINVAL if the socket_id parameter is NULL. 181 * @returns ENOMEM if there is not enough memory left. 182 */ 183 extern int socket_create(socket_cores_ref local_sockets, int app_phone, void * specific_data, int * socket_id); 184 185 /** Destroys the socket. 186 * If the socket is bound, the port is released. 187 * Releases all buffered packets, calls the release function and removes the socket from the local sockets. 188 * @param[in] packet_phone The packet server phone to release buffered packets. 189 * @param[in] socket_id The socket identifier. 190 * @param[in,out] local_sockets The local sockets to be updated. 191 * @param[in,out] global_sockets The global sockets to be updated. 192 * @param[in] socket_release The client release callback function. 193 * @returns EOK on success. 194 * @returns ENOTSOCK if the socket is not found. 195 */ 196 extern 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 198 /** Replies the packet or the packet queue data to the application via the socket. 199 * Uses the current message processing fibril. 200 * @param[in] packet The packet to be transfered. 201 * @param[out] length The total data length. 202 * @returns EOK on success. 203 * @returns EBADMEM if the length parameter is NULL. 204 * @returns ENOMEM if there is not enough memory left. 205 * @returns Other error codes as defined for the data_reply() function. 206 */ 207 extern int socket_reply_packets(packet_t packet, size_t * length); 208 209 /** Finds the bound port socket. 210 * @param[in] global_sockets The global sockets to be searched. 211 * @param[in] port The port number. 212 * @param[in] key The socket key identifier. 213 * @param[in] key_length The socket key length. 214 * @returns The found socket. 215 * @returns NULL if no socket was found. 216 */ 217 extern socket_core_ref socket_port_find(socket_ports_ref global_sockets, int port, const char * key, size_t key_length); 218 219 /** Releases the socket port. 220 * If the socket is bound the port entry is released. 221 * If there are no more port entries the port is release. 222 * @param[in] global_sockets The global sockets to be updated. 223 * @param[in] socket The socket to be unbound. 224 */ 225 extern void socket_port_release(socket_ports_ref global_sockets, socket_core_ref socket); 226 227 /** Adds the socket to an already bound port. 228 * @param[in] global_sockets The global sockets to be updated. 229 * @param[in] port The port number to be bound to. 230 * @param[in] socket The socket to be added. 231 * @param[in] key The socket key identifier. 232 * @param[in] key_length The socket key length. 233 * @returns EOK on success. 234 * @returns ENOENT if the port is not already used. 235 * @returns Other error codes as defined for the socket_port_add_core() function. 236 */ 237 extern int socket_port_add(socket_ports_ref global_sockets, int port, socket_core_ref socket, const char * key, size_t key_length); 120 extern void socket_cores_release(int, socket_cores_ref, socket_ports_ref, 121 void (*)(socket_core_ref)); 122 extern int socket_bind(socket_cores_ref, socket_ports_ref, int, void *, size_t, 123 int, int, int); 124 extern int socket_bind_free_port(socket_ports_ref, socket_core_ref, int, int, 125 int); 126 extern int socket_create(socket_cores_ref, int, void *, int *); 127 extern int socket_destroy(int, int, socket_cores_ref, socket_ports_ref, 128 void (*)(socket_core_ref)); 129 extern int socket_reply_packets(packet_t, size_t *); 130 extern socket_core_ref socket_port_find(socket_ports_ref, int, const char *, 131 size_t); 132 extern void socket_port_release(socket_ports_ref, socket_core_ref); 133 extern int socket_port_add(socket_ports_ref, int, socket_core_ref, 134 const char *, size_t); 238 135 239 136 #endif
Note:
See TracChangeset
for help on using the changeset viewer.