source: mainline/uspace/lib/net/include/socket_core.h@ 137f8aa0

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 137f8aa0 was 137f8aa0, checked in by Jakub Jermar <jakub@…>, 15 years ago

Cleanup socket_core.[ch].

  • Property mode set to 100644
File size: 4.2 KB
Line 
1/*
2 * Copyright (c) 2009 Lukas Mejdrech
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * - Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * - Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * - The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29/** @addtogroup libnet
30 * @{
31 */
32
33/** @file
34 * Socket common core.
35 */
36
37#ifndef LIBNET_SOCKET_CORE_H_
38#define LIBNET_SOCKET_CORE_H_
39
40#include <sys/types.h>
41#include <adt/generic_char_map.h>
42#include <adt/dynamic_fifo.h>
43#include <adt/int_map.h>
44#include <net/in.h>
45#include <net/device.h>
46#include <net/packet.h>
47
48/** Initial size of the received packet queue. */
49#define SOCKET_INITIAL_RECEIVED_SIZE 4
50
51/** Maximum size of the received packet queue. */
52#define SOCKET_MAX_RECEIVED_SIZE 0
53
54/** Initial size of the sockets for acceptance queue. */
55#define SOCKET_INITIAL_ACCEPTED_SIZE 1
56
57/** Maximum size of the sockets for acceptance queue. */
58#define SOCKET_MAX_ACCEPTEDED_SIZE 0
59
60/** Listening sockets' port map key. */
61#define SOCKET_MAP_KEY_LISTENING "L"
62
63/** Type definition of the socket core.
64 * @see socket_core
65 */
66typedef struct socket_core socket_core_t;
67
68/** Type definition of the socket core pointer.
69 * @see socket_core
70 */
71typedef socket_core_t *socket_core_ref;
72
73/** Type definition of the socket port.
74 * @see socket_port
75 */
76typedef struct socket_port socket_port_t;
77
78/** Type definition of the socket port pointer.
79 * @see socket_port
80 */
81typedef socket_port_t *socket_port_ref;
82
83/** Socket core. */
84struct socket_core {
85 /** Socket identifier. */
86 int socket_id;
87 /** Client application phone. */
88 int phone;
89 /** Bound port. */
90 int port;
91 /** Received packets queue. */
92 dyn_fifo_t received;
93 /** Sockets for acceptance queue. */
94 dyn_fifo_t accepted;
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. */
100 size_t key_length;
101};
102
103/** Sockets map.
104 * The key is the socket identifier.
105 */
106INT_MAP_DECLARE(socket_cores, socket_core_t);
107
108/** Bount port sockets map.
109 *
110 * The listening socket has the SOCKET_MAP_KEY_LISTENING key identifier whereas
111 * the other use the remote addresses.
112 */
113GENERIC_CHAR_MAP_DECLARE(socket_port_map, socket_core_ref);
114
115/** Ports map.
116 * The key is the port number.
117 */
118INT_MAP_DECLARE(socket_ports, socket_port_t);
119
120extern void socket_cores_release(int, socket_cores_ref, socket_ports_ref,
121 void (*)(socket_core_ref));
122extern int socket_bind(socket_cores_ref, socket_ports_ref, int, void *, size_t,
123 int, int, int);
124extern int socket_bind_free_port(socket_ports_ref, socket_core_ref, int, int,
125 int);
126extern int socket_create(socket_cores_ref, int, void *, int *);
127extern int socket_destroy(int, int, socket_cores_ref, socket_ports_ref,
128 void (*)(socket_core_ref));
129extern int socket_reply_packets(packet_t, size_t *);
130extern socket_core_ref socket_port_find(socket_ports_ref, int, const char *,
131 size_t);
132extern void socket_port_release(socket_ports_ref, socket_core_ref);
133extern int socket_port_add(socket_ports_ref, int, socket_core_ref,
134 const char *, size_t);
135
136#endif
137
138/** @}
139 */
Note: See TracBrowser for help on using the repository browser.