|
|
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 {
1.1.1.2 ! root 37: #ifdef KPRF
! 38: unsigned long sb_cc; /* actual chars in buffer */
! 39: unsigned long sb_hiwat; /* max actual char count */
! 40: unsigned long sb_mbcnt; /* chars of mbufs used */
! 41: unsigned long sb_mbmax; /* max chars of mbufs to use */
! 42: unsigned long sb_lowat; /* low water mark (not used yet) */
! 43: unsigned long sb_timeo; /* timeout (not used yet) */
! 44: #else
1.1 root 45: short sb_cc; /* actual chars in buffer */
46: short sb_hiwat; /* max actual char count */
47: short sb_mbcnt; /* chars of mbufs used */
48: short sb_mbmax; /* max chars of mbufs to use */
49: short sb_lowat; /* low water mark (not used yet) */
50: short sb_timeo; /* timeout (not used yet) */
1.1.1.2 ! root 51: #endif KPRF
1.1 root 52: struct mbuf *sb_mb; /* the mbuf chain */
53: struct proc *sb_sel; /* process selecting read/write */
54: short sb_flags; /* flags, see below */
55: } so_rcv, so_snd;
56: #define SB_LOCK 0x01 /* lock on data queue (so_rcv only) */
57: #define SB_WANT 0x02 /* someone is waiting to lock */
58: #define SB_WAIT 0x04 /* someone is waiting for data/space */
59: #define SB_SEL 0x08 /* buffer is selected */
60: #define SB_COLL 0x10 /* collision selecting */
61: short so_timeo; /* connection timeout */
62: u_short so_error; /* error affecting connection */
63: short so_oobmark; /* chars to oob mark */
64: short so_pgrp; /* pgrp for signals */
65: };
66:
67: /*
68: * Socket state bits.
69: */
70: #define SS_NOFDREF 0x001 /* no file table ref any more */
71: #define SS_ISCONNECTED 0x002 /* socket connected to a peer */
72: #define SS_ISCONNECTING 0x004 /* in process of connecting to peer */
73: #define SS_ISDISCONNECTING 0x008 /* in process of disconnecting */
74: #define SS_CANTSENDMORE 0x010 /* can't send more data to peer */
75: #define SS_CANTRCVMORE 0x020 /* can't receive more data from peer */
76: #define SS_RCVATMARK 0x040 /* at mark on input */
77:
78: #define SS_PRIV 0x080 /* privileged for broadcast, raw... */
79: #define SS_NBIO 0x100 /* non-blocking ops */
80: #define SS_ASYNC 0x200 /* async i/o notify */
81:
82:
83: /*
84: * Macros for sockets and socket buffering.
85: */
86:
87: /* how much space is there in a socket buffer (so->so_snd or so->so_rcv) */
88: #define sbspace(sb) \
89: (MIN((sb)->sb_hiwat-(sb)->sb_cc, ((sb)->sb_mbmax-(sb)->sb_mbcnt)))
90:
91: /* do we have to send all at once on a socket? */
92: #define sosendallatonce(so) \
93: (((so)->so_state & SS_NBIO) || ((so)->so_proto->pr_flags & PR_ATOMIC))
94:
95: /* can we read something from so? */
96: #define soreadable(so) \
97: ((so)->so_rcv.sb_cc || ((so)->so_state & SS_CANTRCVMORE) || (so)->so_qlen)
98:
99: /* can we write something to so? */
100: #define sowriteable(so) \
101: (sbspace(&(so)->so_snd) > 0 && \
102: (((so)->so_state&SS_ISCONNECTED) || \
103: ((so)->so_proto->pr_flags&PR_CONNREQUIRED)==0) || \
104: ((so)->so_state & SS_CANTSENDMORE))
105:
106: /* adjust counters in sb reflecting allocation of m */
107: #define sballoc(sb, m) { \
108: (sb)->sb_cc += (m)->m_len; \
109: (sb)->sb_mbcnt += MSIZE; \
110: if ((m)->m_off > MMAXOFF) \
111: (sb)->sb_mbcnt += CLBYTES; \
112: }
113:
114: /* adjust counters in sb reflecting freeing of m */
115: #define sbfree(sb, m) { \
116: (sb)->sb_cc -= (m)->m_len; \
117: (sb)->sb_mbcnt -= MSIZE; \
118: if ((m)->m_off > MMAXOFF) \
119: (sb)->sb_mbcnt -= CLBYTES; \
120: }
121:
122: /* set lock on sockbuf sb */
123: #define sblock(sb) { \
124: while ((sb)->sb_flags & SB_LOCK) { \
125: (sb)->sb_flags |= SB_WANT; \
126: sleep((caddr_t)&(sb)->sb_flags, PZERO+1); \
127: } \
128: (sb)->sb_flags |= SB_LOCK; \
129: }
130:
131: /* release lock on sockbuf sb */
132: #define sbunlock(sb) { \
133: (sb)->sb_flags &= ~SB_LOCK; \
134: if ((sb)->sb_flags & SB_WANT) { \
135: (sb)->sb_flags &= ~SB_WANT; \
136: wakeup((caddr_t)&(sb)->sb_flags); \
137: } \
138: }
139:
140: #define sorwakeup(so) sbwakeup(&(so)->so_rcv)
141: #define sowwakeup(so) sbwakeup(&(so)->so_snd)
142:
143: #ifdef KERNEL
144: struct socket *sonewconn();
145: #endif
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.