OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-3.0/] [packages/] [net/] [tcpip/] [current/] [include/] [sys/] [socketvar.h] - Blame information for rev 786

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 786 skrzyp
//==========================================================================
2
//
3
//      include/sys/socketvar.h
4
//
5
//      
6
//
7
//==========================================================================
8
// ####BSDALTCOPYRIGHTBEGIN####                                             
9
// -------------------------------------------                              
10
// Portions of this software may have been derived from OpenBSD             
11
// or other sources, and if so are covered by the appropriate copyright     
12
// and license included herein.                                             
13
// -------------------------------------------                              
14
// ####BSDALTCOPYRIGHTEND####                                               
15
//==========================================================================
16
//#####DESCRIPTIONBEGIN####
17
//
18
// Author(s):    gthomas
19
// Contributors: gthomas
20
// Date:         2000-01-10
21
// Purpose:      
22
// Description:  
23
//              
24
//
25
//####DESCRIPTIONEND####
26
//
27
//==========================================================================
28
 
29
 
30
/*      $OpenBSD: socketvar.h,v 1.17 1999/12/08 06:50:24 itojun Exp $   */
31
/*      $NetBSD: socketvar.h,v 1.18 1996/02/09 18:25:38 christos Exp $  */
32
 
33
/*-
34
 * Copyright (c) 1982, 1986, 1990, 1993
35
 *      The Regents of the University of California.  All rights reserved.
36
 *
37
 * Redistribution and use in source and binary forms, with or without
38
 * modification, are permitted provided that the following conditions
39
 * are met:
40
 * 1. Redistributions of source code must retain the above copyright
41
 *    notice, this list of conditions and the following disclaimer.
42
 * 2. Redistributions in binary form must reproduce the above copyright
43
 *    notice, this list of conditions and the following disclaimer in the
44
 *    documentation and/or other materials provided with the distribution.
45
 * 3. All advertising materials mentioning features or use of this software
46
 *    must display the following acknowledgement:
47
 *      This product includes software developed by the University of
48
 *      California, Berkeley and its contributors.
49
 * 4. Neither the name of the University nor the names of its contributors
50
 *    may be used to endorse or promote products derived from this software
51
 *    without specific prior written permission.
52
 *
53
 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
54
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
55
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
56
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
57
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
58
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
59
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
60
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
61
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
62
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
63
 * SUCH DAMAGE.
64
 *
65
 *      @(#)socketvar.h 8.1 (Berkeley) 6/2/93
66
 */
67
 
68
#ifndef _SYS_SOCKETVAR_H_
69
#define _SYS_SOCKETVAR_H_
70
 
71
#include <sys/bsdselect.h>                      /* for struct selinfo */
72
 
73
/*
74
 * Kernel structure per socket.
75
 * Contains send and receive buffer queues,
76
 * handle on protocol and pointer to protocol
77
 * private data and error information.
78
 */
79
struct socket {
80
        short   so_type;                /* generic type, see socket.h */
81
        short   so_options;             /* from socket call, see socket.h */
82
        short   so_linger;              /* time to linger while closing */
83
        short   so_state;               /* internal state flags SS_*, below */
84
        void    *so_pcb;                /* protocol control block */
85
        struct  protosw *so_proto;      /* protocol handle */
86
/*
87
 * Variables for connection queueing.
88
 * Socket where accepts occur is so_head in all subsidiary sockets.
89
 * If so_head is 0, socket is not related to an accept.
90
 * For head socket so_q0 queues partially completed connections,
91
 * while so_q is a queue of connections ready to be accepted.
92
 * If a connection is aborted and it has so_head set, then
93
 * it has to be pulled out of either so_q0 or so_q.
94
 * We allow connections to queue up based on current queue lengths
95
 * and limit on number of queued connections for this socket.
96
 */
97
        struct  socket *so_head;        /* back pointer to accept socket */
98
        struct  socket *so_q0;          /* queue of partial connections */
99
        struct  socket *so_q;           /* queue of incoming connections */
100
        short   so_q0len;               /* partials on so_q0 */
101
        short   so_qlen;                /* number of connections on so_q */
102
        short   so_qlimit;              /* max number queued connections */
103
        short   so_timeo;               /* connection timeout */
104
        u_short so_error;               /* error affecting connection */
105
        pid_t   so_pgid;                /* pgid for signals */
106
        uid_t   so_siguid;              /* uid of process who set so_pgid */
107
        uid_t   so_sigeuid;             /* euid of process who set so_pgid */
108
        u_long  so_oobmark;             /* chars to oob mark */
109
/*
110
 * Variables for socket buffering.
111
 */
112
        struct  sockbuf {
113
                u_long  sb_cc;          /* actual chars in buffer */
114
                u_long  sb_hiwat;       /* max actual char count */
115
                u_long  sb_mbcnt;       /* chars of mbufs used */
116
                u_long  sb_mbmax;       /* max chars of mbufs to use */
117
                long    sb_lowat;       /* low water mark */
118
                struct  mbuf *sb_mb;    /* the mbuf chain */
119
                struct  selinfo sb_sel; /* process selecting read/write */
120
                short   sb_flags;       /* flags, see below */
121
                short   sb_timeo;       /* timeout for read/write */
122
        } so_rcv, so_snd;
123
#define SB_MAX          (256*1024)      /* default for max chars in sockbuf */
124
#define SB_LOCK         0x01            /* lock on data queue */
125
#define SB_WANT         0x02            /* someone is waiting to lock */
126
#define SB_WAIT         0x04            /* someone is waiting for data/space */
127
#define SB_SEL          0x08            /* someone is selecting */
128
#define SB_ASYNC        0x10            /* ASYNC I/O, need signals */
129
#define SB_NOINTR       0x40            /* operations not interruptible */
130
 
131
        void    *so_internal;           /* Space for svr4 stream data */
132
        void    (*so_upcall) __P((struct socket *so, caddr_t arg, int waitf));
133
        caddr_t so_upcallarg;           /* Arg for above */
134
        uid_t   so_euid;                /* who opened the socket */
135
        uid_t   so_ruid;                /* who opened the socket */
136
};
137
 
138
/*
139
 * Socket state bits.
140
 */
141
#define SS_NOFDREF              0x001   /* no file table ref any more */
142
#define SS_ISCONNECTED          0x002   /* socket connected to a peer */
143
#define SS_ISCONNECTING         0x004   /* in process of connecting to peer */
144
#define SS_ISDISCONNECTING      0x008   /* in process of disconnecting */
145
#define SS_CANTSENDMORE         0x010   /* can't send more data to peer */
146
#define SS_CANTRCVMORE          0x020   /* can't receive more data from peer */
147
#define SS_RCVATMARK            0x040   /* at mark on input */
148
#define SS_ISDISCONNECTED       0x800   /* socket disconnected from peer */
149
 
150
#define SS_PRIV                 0x080   /* privileged for broadcast, raw... */
151
#define SS_NBIO                 0x100   /* non-blocking ops */
152
#define SS_ASYNC                0x200   /* async i/o notify */
153
#define SS_ISCONFIRMING         0x400   /* deciding to accept connection req */
154
#define SS_CONNECTOUT           0x1000  /* connect, not accept, at this end */
155
 
156
/*
157
 * Macros for sockets and socket buffering.
158
 */
159
 
160
/*
161
 * Do we need to notify the other side when I/O is possible?
162
 */
163
#define sb_notify(sb)   (((sb)->sb_flags & (SB_WAIT|SB_SEL|SB_ASYNC)) != 0)
164
 
165
/*
166
 * How much space is there in a socket buffer (so->so_snd or so->so_rcv)?
167
 * This is problematical if the fields are unsigned, as the space might
168
 * still be negative (cc > hiwat or mbcnt > mbmax).  Should detect
169
 * overflow and return 0.  Should use "lmin" but it doesn't exist now.
170
 */
171
#define sbspace(sb) \
172
    ((long) imin((int)((sb)->sb_hiwat - (sb)->sb_cc), \
173
         (int)((sb)->sb_mbmax - (sb)->sb_mbcnt)))
174
 
175
/* do we have to send all at once on a socket? */
176
#define sosendallatonce(so) \
177
    ((so)->so_proto->pr_flags & PR_ATOMIC)
178
 
179
/* can we read something from so? */
180
#define soreadable(so) \
181
    ((so)->so_rcv.sb_cc >= (so)->so_rcv.sb_lowat || \
182
        ((so)->so_state & SS_CANTRCVMORE) || \
183
        (so)->so_qlen || (so)->so_error)
184
 
185
/* can we write something to so? */
186
#define sowriteable(so) \
187
    ((sbspace(&(so)->so_snd) >= (so)->so_snd.sb_lowat && \
188
        (((so)->so_state&SS_ISCONNECTED) || \
189
          ((so)->so_proto->pr_flags&PR_CONNREQUIRED)==0)) || \
190
     ((so)->so_state & SS_CANTSENDMORE) || \
191
     (so)->so_error)
192
 
193
/* adjust counters in sb reflecting allocation of m */
194
#define sballoc(sb, m) { \
195
        (sb)->sb_cc += (m)->m_len; \
196
        (sb)->sb_mbcnt += MSIZE; \
197
        if ((m)->m_flags & M_EXT) \
198
                (sb)->sb_mbcnt += (m)->m_ext.ext_size; \
199
}
200
 
201
/* adjust counters in sb reflecting freeing of m */
202
#define sbfree(sb, m) { \
203
        (sb)->sb_cc -= (m)->m_len; \
204
        (sb)->sb_mbcnt -= MSIZE; \
205
        if ((m)->m_flags & M_EXT) \
206
                (sb)->sb_mbcnt -= (m)->m_ext.ext_size; \
207
}
208
 
209
/*
210
 * Set lock on sockbuf sb; sleep if lock is already held.
211
 * Unless SB_NOINTR is set on sockbuf, sleep is interruptible.
212
 * Returns error without lock if sleep is interrupted.
213
 */
214
#ifdef __ECOS
215
extern int  sblock(struct sockbuf *sb, int wf);
216
extern void sbunlock(struct sockbuf *sb);
217
#else
218
#define sblock(sb, wf) ((sb)->sb_flags & SB_LOCK ? \
219
                (((wf) == M_WAITOK) ? sb_lock(sb) : EWOULDBLOCK) : \
220
                ((sb)->sb_flags |= SB_LOCK), 0)
221
 
222
/* release lock on sockbuf sb */
223
#define sbunlock(sb) { \
224
        (sb)->sb_flags &= ~SB_LOCK; \
225
        if ((sb)->sb_flags & SB_WANT) { \
226
                (sb)->sb_flags &= ~SB_WANT; \
227
                wakeup((caddr_t)&(sb)->sb_flags); \
228
        } \
229
}
230
#endif
231
 
232
#define sorwakeup(so)   { sowakeup((so), &(so)->so_rcv); \
233
                          if ((so)->so_upcall) \
234
                            (*((so)->so_upcall))((so), (so)->so_upcallarg, M_DONTWAIT); \
235
                        }
236
 
237
#define sowwakeup(so)   sowakeup((so), &(so)->so_snd)
238
 
239
#ifdef _KERNEL
240
u_long  sb_max;
241
/* to catch callers missing new second argument to sonewconn: */
242
#define sonewconn(head, connstatus)     sonewconn1((head), (connstatus))
243
struct  socket *sonewconn1 __P((struct socket *head, int connstatus));
244
 
245
/* strings for sleep message: */
246
extern  char netio[], netcon[], netcls[];
247
 
248
struct mbuf;
249
struct sockaddr;
250
struct proc;
251
struct msghdr;
252
struct stat;
253
 
254
/*
255
 * File operations on sockets.
256
 */
257
#ifdef __ECOS
258
int     soo_read __P((struct file *fp, struct uio *uio));
259
int     soo_write __P((struct file *fp, struct uio *uio));
260
int     soo_ioctl __P((struct file *fp, CYG_ADDRWORD cmd, CYG_ADDRWORD data));
261
int     soo_select __P((struct file *fp, int which));
262
int     soo_close __P((struct file *fp));
263
#else
264
int     soo_read __P((struct file *fp, struct uio *uio, struct ucred *cred));
265
int     soo_write __P((struct file *fp, struct uio *uio, struct ucred *cred));
266
int     soo_ioctl __P((struct file *fp, u_long cmd, caddr_t data,
267
            struct proc *p));
268
int     soo_select __P((struct file *fp, int which, struct proc *p));
269
int     soo_close __P((struct file *fp, struct proc *p));
270
#endif
271
 
272
int     soo_stat __P((struct socket *, struct stat *));
273
int     uipc_usrreq __P((struct socket *, int , struct mbuf *,
274
                         struct mbuf *, struct mbuf *));
275
void    sbappend __P((struct sockbuf *sb, struct mbuf *m));
276
int     sbappendaddr __P((struct sockbuf *sb, struct sockaddr *asa,
277
            struct mbuf *m0, struct mbuf *control));
278
int     sbappendcontrol __P((struct sockbuf *sb, struct mbuf *m0,
279
            struct mbuf *control));
280
void    sbappendrecord __P((struct sockbuf *sb, struct mbuf *m0));
281
void    sbcheck __P((struct sockbuf *sb));
282
void    sbcompress __P((struct sockbuf *sb, struct mbuf *m, struct mbuf *n));
283
struct mbuf *
284
        sbcreatecontrol __P((caddr_t p, int size, int type, int level));
285
void    sbdrop __P((struct sockbuf *sb, int len));
286
void    sbdroprecord __P((struct sockbuf *sb));
287
void    sbflush __P((struct sockbuf *sb));
288
void    sbinsertoob __P((struct sockbuf *sb, struct mbuf *m0));
289
void    sbrelease __P((struct sockbuf *sb));
290
int     sbreserve __P((struct sockbuf *sb, u_long cc));
291
int     sbwait __P((struct sockbuf *sb));
292
int     sb_lock __P((struct sockbuf *sb));
293
int     soabort __P((struct socket *so));
294
int     soaccept __P((struct socket *so, struct mbuf *nam));
295
int     sobind __P((struct socket *so, struct mbuf *nam));
296
void    socantrcvmore __P((struct socket *so));
297
void    socantsendmore __P((struct socket *so));
298
int     soclose __P((struct socket *so));
299
int     soconnect __P((struct socket *so, struct mbuf *nam));
300
int     soconnect2 __P((struct socket *so1, struct socket *so2));
301
int     socreate __P((int dom, struct socket **aso, int type, int proto));
302
int     sodisconnect __P((struct socket *so));
303
void    sofree __P((struct socket *so));
304
int     sogetopt __P((struct socket *so, int level, int optname,
305
            struct mbuf **mp));
306
void    sohasoutofband __P((struct socket *so));
307
void    soisconnected __P((struct socket *so));
308
void    soisconnecting __P((struct socket *so));
309
void    soisdisconnected __P((struct socket *so));
310
void    soisdisconnecting __P((struct socket *so));
311
int     solisten __P((struct socket *so, int backlog));
312
struct socket *
313
        sonewconn1 __P((struct socket *head, int connstatus));
314
void    soqinsque __P((struct socket *head, struct socket *so, int q));
315
int     soqremque __P((struct socket *so, int q));
316
int     soreceive __P((struct socket *so, struct mbuf **paddr, struct uio *uio,
317
                       struct mbuf **mp0, struct mbuf **controlp, int *flagsp));
318
int     soreserve __P((struct socket *so, u_long sndcc, u_long rcvcc));
319
void    sorflush __P((struct socket *so));
320
int     sosend __P((struct socket *so, struct mbuf *addr, struct uio *uio,
321
            struct mbuf *top, struct mbuf *control, int flags));
322
int     sosetopt __P((struct socket *so, int level, int optname,
323
            struct mbuf *m0));
324
int     soshutdown __P((struct socket *so, int how));
325
void    sowakeup __P((struct socket *so, struct sockbuf *sb));
326
int     sockargs __P((struct mbuf **, caddr_t, socklen_t, int));
327
 
328
#ifdef __ECOS
329
int     sendit __P((int, struct msghdr *, int, register_t *));
330
int     recvit __P((int, struct msghdr *, caddr_t, register_t *));
331
#else
332
int     sendit __P((struct proc *, int, struct msghdr *, int, register_t *));
333
int     recvit __P((struct proc *, int, struct msghdr *, caddr_t,
334
                    register_t *));
335
#endif
336
#endif /* _KERNEL */
337
 
338
#endif // _SYS_SOCKETVAR_H_

powered by: WebSVN 2.1.0

© copyright 1999-2025 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.