source: rtems/c/src/libnetworking/sys/socket.h @ a6f3cff

4.104.114.84.95
Last change on this file since a6f3cff was a6f3cff, checked in by Joel Sherrill <joel.sherrill@…>, on Jun 11, 1999 at 2:11:44 PM

Patch from Ian Lance Taylor <ian@…>:

The select function is not particularly efficient when dealing with a
large number of sockets. The application has to build a big set of
bits and pass it in. RTEMS has to look through all those bits and see
what is ready. Then the application has to look through all the bits
again.

On the other hand, when using RTEMS, the select function is needed
exactly when you have a large number of sockets, because that is when
it becomes prohibitive to use a separate thread for each socket.

I think it would make more sense for RTEMS to support callback
functions which could be invoked when there is data available to read
from a socket, or when there is space available to write to a socket.

Accordingly, I implemented them.

This patch adds two new SOL_SOCKET options to setsockopt and
getsockopt: SO_SNDWAKEUP and SO_RCVWAKEUP. They take arguments of
type struct sockwakeup:

struct sockwakeup {

void (*sw_pfn) P((struct socket *, caddr_t));
caddr_t sw_arg;

};

They are used to add or remove a function which will be called when
something happens for the socket. Getting a callback doesn't imply
that a read or write will succeed, but it does imply that it is worth
trying.

This adds functionality to RTEMS which is somewhat like interrupt
driven socket I/O on Unix.

After the patch to RTEMS, I have appended a patch to
netdemos-19990407/select/test.c to test the new functionality and
demonstrate one way it might be used. To run the new test instead of
the select test, change doSocket to call echoServer2 instead of
echoServer.

  • Property mode set to 100644
File size: 12.4 KB
Line 
1/*
2 * Copyright (c) 1982, 1985, 1986, 1988, 1993, 1994
3 *      The Regents of the University of California.  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 * 1. Redistributions of source code must retain the above copyright
9 *    notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 *    notice, this list of conditions and the following disclaimer in the
12 *    documentation and/or other materials provided with the distribution.
13 * 3. All advertising materials mentioning features or use of this software
14 *    must display the following acknowledgement:
15 *      This product includes software developed by the University of
16 *      California, Berkeley and its contributors.
17 * 4. Neither the name of the University nor the names of its contributors
18 *    may be used to endorse or promote products derived from this software
19 *    without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * SUCH DAMAGE.
32 *
33 *      @(#)socket.h    8.4 (Berkeley) 2/21/94
34 * $Id$
35 */
36
37#ifndef _SYS_SOCKET_H_
38#define _SYS_SOCKET_H_
39
40#include <sys/cdefs.h>
41
42/*
43 * Definitions related to sockets: types, address families, options.
44 */
45
46/*
47 * Types
48 */
49#define SOCK_STREAM     1               /* stream socket */
50#define SOCK_DGRAM      2               /* datagram socket */
51#define SOCK_RAW        3               /* raw-protocol interface */
52#define SOCK_RDM        4               /* reliably-delivered message */
53#define SOCK_SEQPACKET  5               /* sequenced packet stream */
54
55/*
56 * Option flags per-socket.
57 */
58#define SO_DEBUG        0x0001          /* turn on debugging info recording */
59#define SO_ACCEPTCONN   0x0002          /* socket has had listen() */
60#define SO_REUSEADDR    0x0004          /* allow local address reuse */
61#define SO_KEEPALIVE    0x0008          /* keep connections alive */
62#define SO_DONTROUTE    0x0010          /* just use interface addresses */
63#define SO_BROADCAST    0x0020          /* permit sending of broadcast msgs */
64#define SO_USELOOPBACK  0x0040          /* bypass hardware when possible */
65#define SO_LINGER       0x0080          /* linger on close if data present */
66#define SO_OOBINLINE    0x0100          /* leave received OOB data in line */
67#define SO_REUSEPORT    0x0200          /* allow local address & port reuse */
68#define SO_TIMESTAMP    0x0400          /* timestamp received dgram traffic */
69
70/*
71 * Additional options, not kept in so_options.
72 */
73#define SO_SNDBUF       0x1001          /* send buffer size */
74#define SO_RCVBUF       0x1002          /* receive buffer size */
75#define SO_SNDLOWAT     0x1003          /* send low-water mark */
76#define SO_RCVLOWAT     0x1004          /* receive low-water mark */
77#define SO_SNDTIMEO     0x1005          /* send timeout */
78#define SO_RCVTIMEO     0x1006          /* receive timeout */
79#define SO_ERROR        0x1007          /* get error status and clear */
80#define SO_TYPE         0x1008          /* get socket type */
81#define SO_PRIVSTATE    0x1009          /* get/deny privileged state */
82
83/*
84 * RTEMS addition: get and set wakeup functions.
85 */
86#define SO_SNDWAKEUP    0x1020          /* wakeup when ready to send */
87#define SO_RCVWAKEUP    0x1021          /* wakeup when ready to receive */
88
89/*
90 * Structure used for manipulating linger option.
91 */
92struct  linger {
93        int     l_onoff;                /* option on/off */
94        int     l_linger;               /* linger time */
95};
96
97/*
98 * RTEMS addition: structure used to get and set wakeup function.
99 */
100struct socket;
101struct  sockwakeup {
102        void    (*sw_pfn) __P((struct socket *, caddr_t));
103        caddr_t sw_arg;
104};
105
106/*
107 * Level number for (get/set)sockopt() to apply to socket itself.
108 */
109#define SOL_SOCKET      0xffff          /* options for socket level */
110
111/*
112 * Address families.
113 */
114#define AF_UNSPEC       0               /* unspecified */
115#define AF_LOCAL        1               /* local to host (pipes, portals) */
116#define AF_UNIX         AF_LOCAL        /* backward compatibility */
117#define AF_INET         2               /* internetwork: UDP, TCP, etc. */
118#define AF_IMPLINK      3               /* arpanet imp addresses */
119#define AF_PUP          4               /* pup protocols: e.g. BSP */
120#define AF_CHAOS        5               /* mit CHAOS protocols */
121#define AF_NS           6               /* XEROX NS protocols */
122#define AF_ISO          7               /* ISO protocols */
123#define AF_OSI          AF_ISO
124#define AF_ECMA         8               /* European computer manufacturers */
125#define AF_DATAKIT      9               /* datakit protocols */
126#define AF_CCITT        10              /* CCITT protocols, X.25 etc */
127#define AF_SNA          11              /* IBM SNA */
128#define AF_DECnet       12              /* DECnet */
129#define AF_DLI          13              /* DEC Direct data link interface */
130#define AF_LAT          14              /* LAT */
131#define AF_HYLINK       15              /* NSC Hyperchannel */
132#define AF_APPLETALK    16              /* Apple Talk */
133#define AF_ROUTE        17              /* Internal Routing Protocol */
134#define AF_LINK         18              /* Link layer interface */
135#define pseudo_AF_XTP   19              /* eXpress Transfer Protocol (no AF) */
136#define AF_COIP         20              /* connection-oriented IP, aka ST II */
137#define AF_CNT          21              /* Computer Network Technology */
138#define pseudo_AF_RTIP  22              /* Help Identify RTIP packets */
139#define AF_IPX          23              /* Novell Internet Protocol */
140#define AF_SIP          24              /* Simple Internet Protocol */
141#define pseudo_AF_PIP   25              /* Help Identify PIP packets */
142#define AF_ISDN         26              /* Integrated Services Digital Network*/
143#define AF_E164         AF_ISDN         /* CCITT E.164 recommendation */
144#define pseudo_AF_KEY   27              /* Internal key-management function */
145#define AF_INET6        28              /* IPv6 */
146
147#define AF_MAX          29
148
149/*
150 * Structure used by kernel to store most
151 * addresses.
152 */
153struct sockaddr {
154        u_char  sa_len;                 /* total length */
155        u_char  sa_family;              /* address family */
156        char    sa_data[14];            /* actually longer; address value */
157};
158
159/*
160 * Structure used by kernel to pass protocol
161 * information in raw sockets.
162 */
163struct sockproto {
164        u_short sp_family;              /* address family */
165        u_short sp_protocol;            /* protocol */
166};
167
168/*
169 * Protocol families, same as address families for now.
170 */
171#define PF_UNSPEC       AF_UNSPEC
172#define PF_LOCAL        AF_LOCAL
173#define PF_UNIX         PF_LOCAL        /* backward compatibility */
174#define PF_INET         AF_INET
175#define PF_IMPLINK      AF_IMPLINK
176#define PF_PUP          AF_PUP
177#define PF_CHAOS        AF_CHAOS
178#define PF_NS           AF_NS
179#define PF_ISO          AF_ISO
180#define PF_OSI          AF_ISO
181#define PF_ECMA         AF_ECMA
182#define PF_DATAKIT      AF_DATAKIT
183#define PF_CCITT        AF_CCITT
184#define PF_SNA          AF_SNA
185#define PF_DECnet       AF_DECnet
186#define PF_DLI          AF_DLI
187#define PF_LAT          AF_LAT
188#define PF_HYLINK       AF_HYLINK
189#define PF_APPLETALK    AF_APPLETALK
190#define PF_ROUTE        AF_ROUTE
191#define PF_LINK         AF_LINK
192#define PF_XTP          pseudo_AF_XTP   /* really just proto family, no AF */
193#define PF_COIP         AF_COIP
194#define PF_CNT          AF_CNT
195#define PF_SIP          AF_SIP
196#define PF_IPX          AF_IPX          /* same format as AF_NS */
197#define PF_RTIP         pseudo_AF_RTIP  /* same format as AF_INET */
198#define PF_PIP          pseudo_AF_PIP
199#define PF_ISDN         AF_ISDN
200#define PF_KEY          pseudo_AF_KEY
201#define PF_INET6        AF_INET6
202
203#define PF_MAX          AF_MAX
204
205/*
206 * Definitions for network related sysctl, CTL_NET.
207 *
208 * Second level is protocol family.
209 * Third level is protocol number.
210 *
211 * Further levels are defined by the individual families below.
212 */
213#define NET_MAXID       AF_MAX
214
215#define CTL_NET_NAMES { \
216        { 0, 0 }, \
217        { "unix", CTLTYPE_NODE }, \
218        { "inet", CTLTYPE_NODE }, \
219        { "implink", CTLTYPE_NODE }, \
220        { "pup", CTLTYPE_NODE }, \
221        { "chaos", CTLTYPE_NODE }, \
222        { "xerox_ns", CTLTYPE_NODE }, \
223        { "iso", CTLTYPE_NODE }, \
224        { "emca", CTLTYPE_NODE }, \
225        { "datakit", CTLTYPE_NODE }, \
226        { "ccitt", CTLTYPE_NODE }, \
227        { "ibm_sna", CTLTYPE_NODE }, \
228        { "decnet", CTLTYPE_NODE }, \
229        { "dec_dli", CTLTYPE_NODE }, \
230        { "lat", CTLTYPE_NODE }, \
231        { "hylink", CTLTYPE_NODE }, \
232        { "appletalk", CTLTYPE_NODE }, \
233        { "route", CTLTYPE_NODE }, \
234        { "link_layer", CTLTYPE_NODE }, \
235        { "xtp", CTLTYPE_NODE }, \
236        { "coip", CTLTYPE_NODE }, \
237        { "cnt", CTLTYPE_NODE }, \
238        { "rtip", CTLTYPE_NODE }, \
239        { "ipx", CTLTYPE_NODE }, \
240        { "sip", CTLTYPE_NODE }, \
241        { "pip", CTLTYPE_NODE }, \
242        { "isdn", CTLTYPE_NODE }, \
243        { "key", CTLTYPE_NODE }, \
244}
245
246/*
247 * PF_ROUTE - Routing table
248 *
249 * Three additional levels are defined:
250 *      Fourth: address family, 0 is wildcard
251 *      Fifth: type of info, defined below
252 *      Sixth: flag(s) to mask with for NET_RT_FLAGS
253 */
254#define NET_RT_DUMP     1               /* dump; may limit to a.f. */
255#define NET_RT_FLAGS    2               /* by flags, e.g. RESOLVING */
256#define NET_RT_IFLIST   3               /* survey interface list */
257#define NET_RT_MAXID    4
258
259#define CTL_NET_RT_NAMES { \
260        { 0, 0 }, \
261        { "dump", CTLTYPE_STRUCT }, \
262        { "flags", CTLTYPE_STRUCT }, \
263        { "iflist", CTLTYPE_STRUCT }, \
264}
265
266/*
267 * Maximum queue length specifiable by listen.
268 */
269#define SOMAXCONN       128
270
271/*
272 * Message header for recvmsg and sendmsg calls.
273 * Used value-result for recvmsg, value only for sendmsg.
274 */
275struct msghdr {
276        caddr_t msg_name;               /* optional address */
277        u_int   msg_namelen;            /* size of address */
278        struct  iovec *msg_iov;         /* scatter/gather array */
279        u_int   msg_iovlen;             /* # elements in msg_iov */
280        caddr_t msg_control;            /* ancillary data, see below */
281        u_int   msg_controllen;         /* ancillary data buffer len */
282        int     msg_flags;              /* flags on received message */
283};
284
285#define MSG_OOB         0x1             /* process out-of-band data */
286#define MSG_PEEK        0x2             /* peek at incoming message */
287#define MSG_DONTROUTE   0x4             /* send without using routing tables */
288#define MSG_EOR         0x8             /* data completes record */
289#define MSG_TRUNC       0x10            /* data discarded before delivery */
290#define MSG_CTRUNC      0x20            /* control data lost before delivery */
291#define MSG_WAITALL     0x40            /* wait for full request or error */
292#define MSG_DONTWAIT    0x80            /* this message should be nonblocking */
293#define MSG_EOF         0x100           /* data completes connection */
294#define MSG_COMPAT      0x8000          /* used in sendit() */
295
296/*
297 * Header for ancillary data objects in msg_control buffer.
298 * Used for additional information with/about a datagram
299 * not expressible by flags.  The format is a sequence
300 * of message elements headed by cmsghdr structures.
301 */
302struct cmsghdr {
303        u_int   cmsg_len;               /* data byte count, including hdr */
304        int     cmsg_level;             /* originating protocol */
305        int     cmsg_type;              /* protocol-specific type */
306/* followed by  u_char  cmsg_data[]; */
307};
308
309/* given pointer to struct cmsghdr, return pointer to data */
310#define CMSG_DATA(cmsg)         ((u_char *)((cmsg) + 1))
311
312/* given pointer to struct cmsghdr, return pointer to next cmsghdr */
313#define CMSG_NXTHDR(mhdr, cmsg) \
314        (((caddr_t)(cmsg) + (cmsg)->cmsg_len + sizeof(struct cmsghdr) > \
315            (mhdr)->msg_control + (mhdr)->msg_controllen) ? \
316            (struct cmsghdr *)NULL : \
317            (struct cmsghdr *)((caddr_t)(cmsg) + ALIGN((cmsg)->cmsg_len)))
318
319#define CMSG_FIRSTHDR(mhdr)     ((struct cmsghdr *)(mhdr)->msg_control)
320
321/* "Socket"-level control message types: */
322#define SCM_RIGHTS      0x01            /* access rights (array of int) */
323#define SCM_TIMESTAMP   0x02            /* timestamp (struct timeval) */
324
325/*
326 * 4.3 compat sockaddr, move to compat file later
327 */
328struct osockaddr {
329        u_short sa_family;              /* address family */
330        char    sa_data[14];            /* up to 14 bytes of direct address */
331};
332
333/*
334 * 4.3-compat message header (move to compat file later).
335 */
336struct omsghdr {
337        caddr_t msg_name;               /* optional address */
338        int     msg_namelen;            /* size of address */
339        struct  iovec *msg_iov;         /* scatter/gather array */
340        int     msg_iovlen;             /* # elements in msg_iov */
341        caddr_t msg_accrights;          /* access rights sent/received */
342        int     msg_accrightslen;
343};
344
345#ifndef KERNEL
346
347__BEGIN_DECLS
348int     accept __P((int, struct sockaddr *, int *));
349int     bind __P((int, const struct sockaddr *, int));
350int     connect __P((int, const struct sockaddr *, int));
351int     getpeername __P((int, struct sockaddr *, int *));
352int     getsockname __P((int, struct sockaddr *, int *));
353int     getsockopt __P((int, int, int, void *, int *));
354int     listen __P((int, int));
355ssize_t recv __P((int, void *, size_t, int));
356ssize_t recvfrom __P((int, void *, size_t, int, struct sockaddr *, int *));
357ssize_t recvmsg __P((int, struct msghdr *, int));
358ssize_t send __P((int, const void *, size_t, int));
359ssize_t sendto __P((int, const void *,
360            size_t, int, const struct sockaddr *, int));
361ssize_t sendmsg __P((int, const struct msghdr *, int));
362int     setsockopt __P((int, int, int, const void *, int));
363int     shutdown __P((int, int));
364int     socket __P((int, int, int));
365int     socketpair __P((int, int, int, int *));
366__END_DECLS
367
368#else /* KERNEL */
369void    pfctlinput __P((int, struct sockaddr *));
370#endif /* !KERNEL */
371#endif /* !_SYS_SOCKET_H_ */
Note: See TracBrowser for help on using the repository browser.