source: rtems/cpukit/libnetworking/sys/socketvar.h @ 23d748dc

4.104.114.84.95
Last change on this file since 23d748dc was 8fc471a5, checked in by Ralf Corsepius <ralf.corsepius@…>, on 05/10/07 at 05:07:28

Include <rtems/bsd/sys/queue.h> instead of <sys/queue.h>.

  • Property mode set to 100644
File size: 10.7 KB
Line 
1/* $Id$ */
2
3/*-
4 * Copyright (c) 1982, 1986, 1990, 1993
5 *      The Regents of the University of California.  All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 *    notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 *    notice, this list of conditions and the following disclaimer in the
14 *    documentation and/or other materials provided with the distribution.
15 * 4. Neither the name of the University nor the names of its contributors
16 *    may be used to endorse or promote products derived from this software
17 *    without specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 * SUCH DAMAGE.
30 *
31 *      @(#)socketvar.h 8.3 (Berkeley) 2/19/95
32 * $FreeBSD: src/sys/sys/socketvar.h,v 1.135 2004/10/18 22:19:43 rwatson Exp $
33 */
34
35#ifndef _SYS_SOCKETVAR_H_
36#define _SYS_SOCKETVAR_H_
37
38#include <rtems/bsd/sys/queue.h>                        /* for TAILQ macros */
39#include <sys/select.h>                 /* for struct selinfo */
40
41
42/*
43 * Kernel structure per socket.
44 * Contains send and receive buffer queues,
45 * handle on protocol and pointer to protocol
46 * private data and error information.
47 */
48typedef u_quad_t so_gen_t;
49
50struct socket {
51        short   so_type;                /* generic type, see socket.h */
52        short   so_options;             /* from socket call, see socket.h */
53        short   so_linger;              /* time to linger while closing */
54        short   so_state;               /* internal state flags SS_*, below */
55        void    *so_pcb;                /* protocol control block */
56        struct  protosw *so_proto;      /* protocol handle */
57/*
58 * Variables for connection queuing.
59 * Socket where accepts occur is so_head in all subsidiary sockets.
60 * If so_head is 0, socket is not related to an accept.
61 * For head socket so_q0 queues partially completed connections,
62 * while so_q is a queue of connections ready to be accepted.
63 * If a connection is aborted and it has so_head set, then
64 * it has to be pulled out of either so_q0 or so_q.
65 * We allow connections to queue up based on current queue lengths
66 * and limit on number of queued connections for this socket.
67 */
68        struct  socket *so_head;        /* back pointer to accept socket */
69        TAILQ_HEAD(, socket) so_incomp; /* queue of partial unaccepted connections */
70        TAILQ_HEAD(, socket) so_comp;   /* queue of complete unaccepted connections */
71        TAILQ_ENTRY(socket) so_list;    /* list of unaccepted connections */
72        short   so_qlen;                /* number of unaccepted connections */
73        short   so_incqlen;             /* number of unaccepted incomplete
74                                           connections */
75        short   so_qlimit;              /* max number queued connections */
76        short   so_timeo;               /* connection timeout */
77        u_short so_error;               /* error affecting connection */
78        pid_t   so_pgid;                /* pgid for signals */
79        u_long  so_oobmark;             /* chars to oob mark */
80/*
81 * Variables for socket buffering.
82 */
83        struct sockbuf {
84                u_int   sb_cc;          /* actual chars in buffer */
85                u_int   sb_hiwat;       /* max actual char count */
86                u_int   sb_mbcnt;       /* chars of mbufs used */
87                u_int   sb_mbmax;       /* max chars of mbufs to use */
88                int     sb_lowat;       /* low water mark */
89                struct  mbuf *sb_mb;    /* the mbuf chain */
90                struct  selinfo sb_sel; /* process selecting read/write */
91                short   sb_flags;       /* flags, see below */
92                int     sb_timeo;       /* timeout for read/write */
93                void    (*sb_wakeup)(struct socket *, caddr_t);
94                caddr_t sb_wakeuparg;   /* arg for above */
95        } so_rcv, so_snd;
96#define SB_MAX          (256L*1024L)    /* default for max chars in sockbuf */
97#define SB_LOCK         0x01            /* lock on data queue */
98#define SB_WANT         0x02            /* someone is waiting to lock */
99#define SB_WAIT         0x04            /* someone is waiting for data/space */
100#define SB_SEL          0x08            /* someone is selecting */
101#define SB_ASYNC        0x10            /* ASYNC I/O, need signals */
102#define SB_NOTIFY       (SB_WAIT|SB_SEL|SB_ASYNC)
103#define SB_NOINTR       0x40            /* operations not interruptible */
104
105        caddr_t so_tpcb;                /* Wisc. protocol control block XXX */
106        void    (*so_upcall)(struct socket *, void *arg, int);
107        void    *so_upcallarg;          /* Arg for above */
108        uid_t   so_uid;                 /* who opened the socket */
109};
110
111/*
112 * Socket state bits.
113 */
114#define SS_NOFDREF              0x0001  /* no file table ref any more */
115#define SS_ISCONNECTED          0x0002  /* socket connected to a peer */
116#define SS_ISCONNECTING         0x0004  /* in process of connecting to peer */
117#define SS_ISDISCONNECTING      0x0008  /* in process of disconnecting */
118#define SS_CANTSENDMORE         0x0010  /* can't send more data to peer */
119#define SS_CANTRCVMORE          0x0020  /* can't receive more data from peer */
120#define SS_RCVATMARK            0x0040  /* at mark on input */
121
122#define SS_PRIV                 0x0080  /* privileged for broadcast, raw... */
123#define SS_NBIO                 0x0100  /* non-blocking ops */
124#define SS_ASYNC                0x0200  /* async i/o notify */
125#define SS_ISCONFIRMING         0x0400  /* deciding to accept connection req */
126
127#define SS_INCOMP               0x0800  /* unaccepted, incomplete connection */
128#define SS_COMP                 0x1000  /* unaccepted, complete connection */
129
130
131/*
132 * Macros for sockets and socket buffering.
133 */
134
135/*
136 * How much space is there in a socket buffer (so->so_snd or so->so_rcv)?
137 * This is problematical if the fields are unsigned, as the space might
138 * still be negative (cc > hiwat or mbcnt > mbmax).  Should detect
139 * overflow and return 0.  Should use "lmin" but it doesn't exist now.
140 */
141#define sbspace(sb) \
142    ((long) imin((int)((sb)->sb_hiwat - (sb)->sb_cc), \
143         (int)((sb)->sb_mbmax - (sb)->sb_mbcnt)))
144
145/* do we have to send all at once on a socket? */
146#define sosendallatonce(so) \
147    ((so)->so_proto->pr_flags & PR_ATOMIC)
148
149/* can we read something from so? */
150#define soreadable(so) \
151    ((so)->so_rcv.sb_cc >= (so)->so_rcv.sb_lowat || \
152        ((so)->so_state & SS_CANTRCVMORE) || \
153        (so)->so_comp.tqh_first || (so)->so_error)
154
155/* can we write something to so? */
156#define sowriteable(so) \
157    ((sbspace(&(so)->so_snd) >= (so)->so_snd.sb_lowat && \
158        (((so)->so_state&SS_ISCONNECTED) || \
159          ((so)->so_proto->pr_flags&PR_CONNREQUIRED)==0)) || \
160     ((so)->so_state & SS_CANTSENDMORE) || \
161     (so)->so_error)
162
163/* adjust counters in sb reflecting allocation of m */
164#define sballoc(sb, m) { \
165        (sb)->sb_cc += (m)->m_len; \
166        (sb)->sb_mbcnt += MSIZE; \
167        if ((m)->m_flags & M_EXT) \
168                (sb)->sb_mbcnt += (m)->m_ext.ext_size; \
169}
170
171/* adjust counters in sb reflecting freeing of m */
172#define sbfree(sb, m) { \
173        (sb)->sb_cc -= (m)->m_len; \
174        (sb)->sb_mbcnt -= MSIZE; \
175        if ((m)->m_flags & M_EXT) \
176                (sb)->sb_mbcnt -= (m)->m_ext.ext_size; \
177}
178
179/*
180 * Set lock on sockbuf sb; sleep if lock is already held.
181 * Unless SB_NOINTR is set on sockbuf, sleep is interruptible.
182 * Returns error without lock if sleep is interrupted.
183 */
184#define sblock(sb, wf) ((sb)->sb_flags & SB_LOCK ? \
185                (((wf) == M_WAITOK) ? sb_lock(sb) : EWOULDBLOCK) : \
186                ((sb)->sb_flags |= SB_LOCK), 0)
187
188/* release lock on sockbuf sb */
189#define sbunlock(sb) { \
190        (sb)->sb_flags &= ~SB_LOCK; \
191        if ((sb)->sb_flags & SB_WANT) { \
192                (sb)->sb_flags &= ~SB_WANT; \
193                wakeup((caddr_t)&(sb)->sb_flags); \
194        } \
195}
196
197#define sorwakeup(so)   { sowakeup((so), &(so)->so_rcv); \
198                          if ((so)->so_upcall) \
199                            (*((so)->so_upcall))((so), (so)->so_upcallarg, M_DONTWAIT); \
200                        }
201
202#define sowwakeup(so)   sowakeup((so), &(so)->so_snd)
203
204#ifdef _KERNEL
205extern u_long   sb_max;
206
207/* to catch callers missing new second argument to sonewconn: */
208#define sonewconn(head, connstatus)     sonewconn1((head), (connstatus))
209
210struct filedesc;
211struct mbuf;
212struct sockaddr;
213struct stat;
214struct file;
215
216/*
217 * File operations on sockets.
218 */
219int     soo_ioctl(struct file *fp, int cmd, caddr_t data,
220            struct proc *p);
221int     soo_select(struct file *fp, int which, struct proc *p);
222int     soo_stat(struct socket *so, struct stat *ub);
223
224/*
225 * From uipc_socket and friends
226 */
227int     getsock(struct filedesc *fdp, int fdes, struct file **fpp);
228int     sockargs(struct mbuf **mp, caddr_t buf, int buflen, int type);
229void    sbappend(struct sockbuf *sb, struct mbuf *m);
230int     sbappendaddr(struct sockbuf *sb, struct sockaddr *asa,
231            struct mbuf *m0, struct mbuf *control);
232int     sbappendcontrol(struct sockbuf *sb, struct mbuf *m0,
233            struct mbuf *control);
234void    sbappendrecord(struct sockbuf *sb, struct mbuf *m0);
235void    sbcheck(struct sockbuf *sb);
236void    sbcompress(struct sockbuf *sb, struct mbuf *m, struct mbuf *n);
237struct mbuf *
238        sbcreatecontrol(caddr_t p, int size, int type, int level);
239void    sbdrop(struct sockbuf *sb, int len);
240void    sbdroprecord(struct sockbuf *sb);
241void    sbflush(struct sockbuf *sb);
242void    sbinsertoob(struct sockbuf *sb, struct mbuf *m0);
243void    sbrelease(struct sockbuf *sb);
244int     sbreserve(struct sockbuf *sb, u_long cc);
245int     sbwait(struct sockbuf *sb);
246int     sb_lock(struct sockbuf *sb);
247int     soabort(struct socket *so);
248int     soaccept(struct socket *so, struct mbuf *nam);
249int     sobind(struct socket *so, struct mbuf *nam);
250void    socantrcvmore(struct socket *so);
251void    socantsendmore(struct socket *so);
252int     soclose(struct socket *so);
253int     soconnect(struct socket *so, struct mbuf *nam);
254int     soconnect2(struct socket *so1, struct socket *so2);
255int     socreate(int dom, struct socket **aso, int type, int proto,
256            struct proc *p);
257int     sodisconnect(struct socket *so);
258void    sofree(struct socket *so);
259int     sogetopt(struct socket *so, int level, int optname,
260            struct mbuf **mp);
261void    sohasoutofband(struct socket *so);
262void    soisconnected(struct socket *so);
263void    soisconnecting(struct socket *so);
264void    soisdisconnected(struct socket *so);
265void    soisdisconnecting(struct socket *so);
266int     solisten(struct socket *so, int backlog);
267struct socket *
268        sodropablereq(struct socket *head);
269struct socket *
270        sonewconn1(struct socket *head, int connstatus);
271int     soreceive(struct socket *so, struct mbuf **paddr, struct uio *uio,
272            struct mbuf **mp0, struct mbuf **controlp, int *flagsp);
273int     soreserve(struct socket *so, u_long sndcc, u_long rcvcc);
274void    sorflush(struct socket *so);
275int     sosend(struct socket *so, struct mbuf *addr, struct uio *uio,
276            struct mbuf *top, struct mbuf *control, int flags);
277int     sosetopt(struct socket *so, int level, int optname,
278            struct mbuf *m0);
279int     soshutdown(struct socket *so, int how);
280void    sowakeup(struct socket *so, struct sockbuf *sb);
281#endif /* _KERNEL */
282
283#endif /* !_SYS_SOCKETVAR_H_ */
Note: See TracBrowser for help on using the repository browser.