|
|
1.1 root 1: /* socketvar.h 6.1 83/07/29 */
2:
3: /*
4: * Kernel structure per socket.
5: * Contains send and receive buffer queues,
6: * handle on protocol and pointer to protocol
7: * private data and error information.
8: */
9: struct socket {
10: short so_type; /* generic type, see socket.h */
11: short so_options; /* from socket call, see socket.h */
12: short so_linger; /* time to linger while closing */
13: short so_state; /* internal state flags SS_*, below */
14: caddr_t so_pcb; /* protocol control block */
15: struct protosw *so_proto; /* protocol handle */
16: /*
17: * Variables for connection queueing.
18: * Socket where accepts occur is so_head in all subsidiary sockets.
19: * If so_head is 0, socket is not related to an accept.
20: * For head socket so_q0 queues partially completed connections,
21: * while so_q is a queue of connections ready to be accepted.
22: * If a connection is aborted and it has so_head set, then
23: * it has to be pulled out of either so_q0 or so_q.
24: * We allow connections to queue up based on current queue lengths
25: * and limit on number of queued connections for this socket.
26: */
27: struct socket *so_head; /* back pointer to accept socket */
28: struct socket *so_q0; /* queue of partial connections */
29: short so_q0len; /* partials on so_q0 */
30: struct socket *so_q; /* queue of incoming connections */
31: short so_qlen; /* number of connections on so_q */
32: short so_qlimit; /* max number queued connections */
33: /*
34: * Variables for socket buffering.
35: */
36: struct sockbuf {
37: short sb_cc; /* actual chars in buffer */
38: short sb_hiwat; /* max actual char count */
39: short sb_mbcnt; /* chars of mbufs used */
40: short sb_mbmax; /* max chars of mbufs to use */
41: short sb_lowat; /* low water mark (not used yet) */
42: short sb_timeo; /* timeout (not used yet) */
43: struct mbuf *sb_mb; /* the mbuf chain */
44: struct proc *sb_sel; /* process selecting read/write */
45: short sb_flags; /* flags, see below */
46: } so_rcv, so_snd;
47: #define SB_LOCK 0x01 /* lock on data queue (so_rcv only) */
48: #define SB_WANT 0x02 /* someone is waiting to lock */
49: #define SB_WAIT 0x04 /* someone is waiting for data/space */
50: #define SB_SEL 0x08 /* buffer is selected */
51: #define SB_COLL 0x10 /* collision selecting */
52: short so_timeo; /* connection timeout */
53: u_short so_error; /* error affecting connection */
54: short so_oobmark; /* chars to oob mark */
55: short so_pgrp; /* pgrp for signals */
56: };
57:
58: /*
59: * Socket state bits.
60: */
61: #define SS_NOFDREF 0x001 /* no file table ref any more */
62: #define SS_ISCONNECTED 0x002 /* socket connected to a peer */
63: #define SS_ISCONNECTING 0x004 /* in process of connecting to peer */
64: #define SS_ISDISCONNECTING 0x008 /* in process of disconnecting */
65: #define SS_CANTSENDMORE 0x010 /* can't send more data to peer */
66: #define SS_CANTRCVMORE 0x020 /* can't receive more data from peer */
67: #define SS_RCVATMARK 0x040 /* at mark on input */
68:
69: #define SS_PRIV 0x080 /* privileged for broadcast, raw... */
70: #define SS_NBIO 0x100 /* non-blocking ops */
71: #define SS_ASYNC 0x200 /* async i/o notify */
72:
73:
74: /*
75: * Macros for sockets and socket buffering.
76: */
77:
78: /* how much space is there in a socket buffer (so->so_snd or so->so_rcv) */
79: #define sbspace(sb) \
80: (MIN((sb)->sb_hiwat-(sb)->sb_cc, ((sb)->sb_mbmax-(sb)->sb_mbcnt)))
81:
82: /* do we have to send all at once on a socket? */
83: #define sosendallatonce(so) \
84: (((so)->so_state & SS_NBIO) || ((so)->so_proto->pr_flags & PR_ATOMIC))
85:
86: /* can we read something from so? */
87: #define soreadable(so) \
88: ((so)->so_rcv.sb_cc || ((so)->so_state & SS_CANTRCVMORE) || (so)->so_qlen)
89:
90: /* can we write something to so? */
91: #define sowriteable(so) \
92: (sbspace(&(so)->so_snd) > 0 && \
93: (((so)->so_state&SS_ISCONNECTED) || \
94: ((so)->so_proto->pr_flags&PR_CONNREQUIRED)==0) || \
95: ((so)->so_state & SS_CANTSENDMORE))
96:
97: /* adjust counters in sb reflecting allocation of m */
98: #define sballoc(sb, m) { \
99: (sb)->sb_cc += (m)->m_len; \
100: (sb)->sb_mbcnt += MSIZE; \
101: if ((m)->m_off > MMAXOFF) \
102: (sb)->sb_mbcnt += CLBYTES; \
103: }
104:
105: /* adjust counters in sb reflecting freeing of m */
106: #define sbfree(sb, m) { \
107: (sb)->sb_cc -= (m)->m_len; \
108: (sb)->sb_mbcnt -= MSIZE; \
109: if ((m)->m_off > MMAXOFF) \
110: (sb)->sb_mbcnt -= CLBYTES; \
111: }
112:
113: /* set lock on sockbuf sb */
114: #define sblock(sb) { \
115: while ((sb)->sb_flags & SB_LOCK) { \
116: (sb)->sb_flags |= SB_WANT; \
117: sleep((caddr_t)&(sb)->sb_flags, PZERO+1); \
118: } \
119: (sb)->sb_flags |= SB_LOCK; \
120: }
121:
122: /* release lock on sockbuf sb */
123: #define sbunlock(sb) { \
124: (sb)->sb_flags &= ~SB_LOCK; \
125: if ((sb)->sb_flags & SB_WANT) { \
126: (sb)->sb_flags &= ~SB_WANT; \
127: wakeup((caddr_t)&(sb)->sb_flags); \
128: } \
129: }
130:
131: #define sorwakeup(so) sbwakeup(&(so)->so_rcv)
132: #define sowwakeup(so) sbwakeup(&(so)->so_snd)
133:
134: #ifdef KERNEL
135: struct socket *sonewconn();
136: #endif
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.