source: mainline/uspace/srv/net/udp/udp_type.h@ 2f19103

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 2f19103 was 2f19103, checked in by Jiri Svoboda <jiri@…>, 11 years ago

TCP and UDP servers can make use of inet/endpoint.h types internally.

  • Property mode set to 100644
File size: 4.1 KB
Line 
1/*
2 * Copyright (c) 2015 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 <async.h>
39#include <fibril.h>
40#include <fibril_synch.h>
41#include <inet/endpoint.h>
42#include <ipc/loc.h>
43#include <sys/types.h>
44#include <inet/addr.h>
45
46#define UDP_FRAGMENT_SIZE 65535
47
48typedef enum {
49 UDP_EOK,
50 /* Insufficient resources */
51 UDP_ENORES,
52 /* Remote endpoint unspecified */
53 UDP_EUNSPEC,
54 /* No route to destination */
55 UDP_ENOROUTE,
56 /** Association reset by user */
57 UDP_ERESET
58} udp_error_t;
59
60typedef enum {
61 XF_DUMMY = 0x1
62} xflags_t;
63
64enum udp_port {
65 UDP_PORT_ANY = 0
66};
67
68/** Unencoded UDP message (datagram) */
69typedef struct {
70 /** Message data */
71 void *data;
72 /** Message data size */
73 size_t data_size;
74} udp_msg_t;
75
76/** Encoded PDU */
77typedef struct {
78 /** IP link (optional) */
79 service_id_t iplink;
80 /** Source address */
81 inet_addr_t src;
82 /** Destination address */
83 inet_addr_t dest;
84 /** Encoded PDU data including header */
85 void *data;
86 /** Encoded PDU data size */
87 size_t data_size;
88} udp_pdu_t;
89
90typedef struct {
91 void (*recv_msg)(void *, inet_ep2_t *, udp_msg_t *);
92} udp_assoc_cb_t;
93
94/** UDP association
95 *
96 * This is a rough equivalent of a TCP connection endpoint. It allows
97 * sending and receiving UDP datagrams and it is uniquely identified
98 * by an endpoint pair.
99 */
100typedef struct {
101 char *name;
102 link_t link;
103
104 /** Association identification (endpoint pair) */
105 inet_ep2_t ident;
106
107 /** True if association was reset by user */
108 bool reset;
109
110 /** True if association was deleted by user */
111 bool deleted;
112
113 /** Protects access to association structure */
114 fibril_mutex_t lock;
115 /** Reference count */
116 atomic_t refcnt;
117
118 /** Receive queue */
119 list_t rcv_queue;
120 /** Receive queue CV. Broadcast when new datagram is inserted */
121 fibril_condvar_t rcv_queue_cv;
122
123 udp_assoc_cb_t *cb;
124 void *cb_arg;
125} udp_assoc_t;
126
127typedef struct {
128} udp_assoc_status_t;
129
130typedef struct {
131 /** Link to receive queue */
132 link_t link;
133 /** Endpoint pair */
134 inet_ep2_t epp;
135 /** Message */
136 udp_msg_t *msg;
137} udp_rcv_queue_entry_t;
138
139typedef struct udp_cassoc {
140 /** Association */
141 udp_assoc_t *assoc;
142 /** Association ID for the client */
143 sysarg_t id;
144 /** Client */
145 struct udp_client *client;
146 link_t lclient;
147} udp_cassoc_t;
148
149typedef struct {
150 /** Link to receive queue */
151 link_t link;
152 /** Endpoint pair */
153 inet_ep2_t epp;
154 /** Message */
155 udp_msg_t *msg;
156 /** Client association */
157 udp_cassoc_t *cassoc;
158} udp_crcv_queue_entry_t;
159
160typedef struct udp_client {
161 /** Client callback session */
162 async_sess_t *sess;
163 /** Client assocations */
164 list_t cassoc; /* of udp_cassoc_t */
165 /** Client receive queue */
166 list_t crcv_queue;
167} udp_client_t;
168
169#endif
170
171/** @}
172 */
Note: See TracBrowser for help on using the repository browser.