source: mainline/uspace/srv/net/udp/udp_type.h@ 4163d0d

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 4163d0d was 4163d0d, checked in by Martin Decky <martin@…>, 13 years ago

cstyle

  • Property mode set to 100644
File size: 3.9 KB
Line 
1/*
2 * Copyright (c) 2012 Jiri Svoboda
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 udp
30 * @{
31 */
32/** @file UDP type definitions
33 */
34
35#ifndef UDP_TYPE_H
36#define UDP_TYPE_H
37
38#include <fibril.h>
39#include <fibril_synch.h>
40#include <socket_core.h>
41#include <sys/types.h>
42
43#define UDP_FRAGMENT_SIZE 4096
44
45
46typedef enum {
47 UDP_EOK,
48 /* Insufficient resources */
49 UDP_ENORES,
50 /* Foreign socket unspecified */
51 UDP_EUNSPEC,
52 /* No route to destination */
53 UDP_ENOROUTE
54} udp_error_t;
55
56typedef enum {
57 XF_DUMMY = 0x1
58} xflags_t;
59
60typedef struct {
61 uint32_t ipv4;
62} netaddr_t;
63
64enum netaddr {
65 UDP_IPV4_ANY = 0
66};
67
68enum udp_port {
69 UDP_PORT_ANY = 0
70};
71
72typedef struct {
73 netaddr_t addr;
74 uint16_t port;
75} udp_sock_t;
76
77typedef struct {
78 udp_sock_t local;
79 udp_sock_t foreign;
80} udp_sockpair_t;
81
82/** Unencoded UDP message (datagram) */
83typedef struct {
84 /** Message data */
85 void *data;
86 /** Message data size */
87 size_t data_size;
88} udp_msg_t;
89
90/** Encoded PDU */
91typedef struct {
92 /** Source address */
93 netaddr_t src;
94 /** Destination address */
95 netaddr_t dest;
96
97 /** Encoded PDU data including header */
98 void *data;
99 /** Encoded PDU data size */
100 size_t data_size;
101} udp_pdu_t;
102
103typedef struct {
104 async_sess_t *sess;
105 socket_cores_t sockets;
106} udp_client_t;
107
108/** UDP association
109 *
110 * This is a rough equivalent of a TCP connection endpoint. It allows
111 * sending and receiving UDP datagrams and it is uniquely identified
112 * by a socket pair.
113 */
114typedef struct {
115 char *name;
116 link_t link;
117
118 /** Association identification (local and foreign socket) */
119 udp_sockpair_t ident;
120
121 /** True if association was deleted by user */
122 bool deleted;
123
124 /** Protects access to association structure */
125 fibril_mutex_t lock;
126 /** Reference count */
127 atomic_t refcnt;
128
129 /** Receive queue */
130 list_t rcv_queue;
131 /** Receive queue CV. Broadcast when new datagram is inserted */
132 fibril_condvar_t rcv_queue_cv;
133} udp_assoc_t;
134
135typedef struct {
136} udp_assoc_status_t;
137
138typedef struct udp_sockdata {
139 /** Lock */
140 fibril_mutex_t lock;
141 /** Socket core */
142 socket_core_t *sock_core;
143 /** Client */
144 udp_client_t *client;
145 /** Connection */
146 udp_assoc_t *assoc;
147 /** Receiving fibril */
148 fid_t recv_fibril;
149 uint8_t recv_buffer[UDP_FRAGMENT_SIZE];
150 size_t recv_buffer_used;
151 udp_sock_t recv_fsock;
152 fibril_mutex_t recv_buffer_lock;
153 fibril_condvar_t recv_buffer_cv;
154 udp_error_t recv_error;
155} udp_sockdata_t;
156
157typedef struct {
158 /** Link to receive queue */
159 link_t link;
160 /** Socket pair */
161 udp_sockpair_t sp;
162 /** Message */
163 udp_msg_t *msg;
164} udp_rcv_queue_entry_t;
165
166#endif
167
168/** @}
169 */
Note: See TracBrowser for help on using the repository browser.