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

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 55091847 was 61bfc370, checked in by Martin Decky <martin@…>, 14 years ago
  • make measured_string and other network-related data types binary-safe
  • fix several network-related routines binary-safe (replace clearly suspicious use of str_lcmp() with bcmp())
  • rename spawn() to net_spawn()
  • Property mode set to 100644
File size: 4.0 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 port.
69 * @see socket_port
70 */
71typedef struct socket_port socket_port_t;
72
73/** Socket core. */
74struct socket_core {
75 /** Socket identifier. */
76 int socket_id;
77 /** Client application phone. */
78 int phone;
79 /** Bound port. */
80 int port;
81 /** Received packets queue. */
82 dyn_fifo_t received;
83 /** Sockets for acceptance queue. */
84 dyn_fifo_t accepted;
85 /** Protocol specific data. */
86 void *specific_data;
87 /** Socket ports map key. */
88 const uint8_t *key;
89 /** Length of the Socket ports map key. */
90 size_t key_length;
91};
92
93/** Sockets map.
94 * The key is the socket identifier.
95 */
96INT_MAP_DECLARE(socket_cores, socket_core_t);
97
98/** Bount port sockets map.
99 *
100 * The listening socket has the SOCKET_MAP_KEY_LISTENING key identifier whereas
101 * the other use the remote addresses.
102 */
103GENERIC_CHAR_MAP_DECLARE(socket_port_map, socket_core_t *);
104
105/** Ports map.
106 * The key is the port number.
107 */
108INT_MAP_DECLARE(socket_ports, socket_port_t);
109
110extern void socket_cores_release(int, socket_cores_t *, socket_ports_t *,
111 void (*)(socket_core_t *));
112extern int socket_bind(socket_cores_t *, socket_ports_t *, int, void *, size_t,
113 int, int, int);
114extern int socket_bind_free_port(socket_ports_t *, socket_core_t *, int, int,
115 int);
116extern int socket_create(socket_cores_t *, int, void *, int *);
117extern int socket_destroy(int, int, socket_cores_t *, socket_ports_t *,
118 void (*)(socket_core_t *));
119extern int socket_reply_packets(packet_t *, size_t *);
120extern socket_core_t *socket_port_find(socket_ports_t *, int, const uint8_t *,
121 size_t);
122extern void socket_port_release(socket_ports_t *, socket_core_t *);
123extern int socket_port_add(socket_ports_t *, int, socket_core_t *,
124 const uint8_t *, size_t);
125
126#endif
127
128/** @}
129 */
Note: See TracBrowser for help on using the repository browser.