Deleted Added
full compact
uipc_sockbuf.c (95759) uipc_sockbuf.c (95883)
1/*
2 * Copyright (c) 1982, 1986, 1988, 1990, 1993
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

--- 17 unchanged lines hidden (view full) ---

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 * @(#)uipc_socket2.c 8.1 (Berkeley) 6/10/93
1/*
2 * Copyright (c) 1982, 1986, 1988, 1990, 1993
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

--- 17 unchanged lines hidden (view full) ---

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 * @(#)uipc_socket2.c 8.1 (Berkeley) 6/10/93
34 * $FreeBSD: head/sys/kern/uipc_sockbuf.c 95759 2002-04-30 01:54:54Z tanimura $
34 * $FreeBSD: head/sys/kern/uipc_sockbuf.c 95883 2002-05-01 20:44:46Z alfred $
35 */
36
37#include "opt_param.h"
38#include <sys/param.h>
39#include <sys/aio.h> /* for aio_swake proto */
40#include <sys/domain.h>
41#include <sys/event.h>
42#include <sys/file.h> /* for maxfiles */

--- 4 unchanged lines hidden (view full) ---

47#include <sys/mutex.h>
48#include <sys/proc.h>
49#include <sys/protosw.h>
50#include <sys/resourcevar.h>
51#include <sys/signalvar.h>
52#include <sys/socket.h>
53#include <sys/socketvar.h>
54#include <sys/stat.h>
35 */
36
37#include "opt_param.h"
38#include <sys/param.h>
39#include <sys/aio.h> /* for aio_swake proto */
40#include <sys/domain.h>
41#include <sys/event.h>
42#include <sys/file.h> /* for maxfiles */

--- 4 unchanged lines hidden (view full) ---

47#include <sys/mutex.h>
48#include <sys/proc.h>
49#include <sys/protosw.h>
50#include <sys/resourcevar.h>
51#include <sys/signalvar.h>
52#include <sys/socket.h>
53#include <sys/socketvar.h>
54#include <sys/stat.h>
55#include <sys/sx.h>
56#include <sys/sysctl.h>
57#include <sys/systm.h>
58
59int maxsockets;
60
61void (*aio_swake)(struct socket *, struct sockbuf *);
62
63/*

--- 44 unchanged lines hidden (view full) ---

108}
109
110void
111soisconnected_locked(so)
112 struct socket *so;
113{
114 struct socket *head = so->so_head;
115
55#include <sys/sysctl.h>
56#include <sys/systm.h>
57
58int maxsockets;
59
60void (*aio_swake)(struct socket *, struct sockbuf *);
61
62/*

--- 44 unchanged lines hidden (view full) ---

107}
108
109void
110soisconnected_locked(so)
111 struct socket *so;
112{
113 struct socket *head = so->so_head;
114
116 SIGIO_ASSERT(SX_SLOCKED); /* XXX */
117 so->so_state &= ~(SS_ISCONNECTING|SS_ISDISCONNECTING|SS_ISCONFIRMING);
118 so->so_state |= SS_ISCONNECTED;
119 if (head && (so->so_state & SS_INCOMP)) {
120 if ((so->so_options & SO_ACCEPTFILTER) != 0) {
121 so->so_upcall = head->so_accf->so_accept_filter->accf_callback;
122 so->so_upcallarg = head->so_accf->so_accept_filter_arg;
123 so->so_rcv.sb_flags |= SB_UPCALL;
124 so->so_options &= ~SO_ACCEPTFILTER;
115 so->so_state &= ~(SS_ISCONNECTING|SS_ISDISCONNECTING|SS_ISCONFIRMING);
116 so->so_state |= SS_ISCONNECTED;
117 if (head && (so->so_state & SS_INCOMP)) {
118 if ((so->so_options & SO_ACCEPTFILTER) != 0) {
119 so->so_upcall = head->so_accf->so_accept_filter->accf_callback;
120 so->so_upcallarg = head->so_accf->so_accept_filter_arg;
121 so->so_rcv.sb_flags |= SB_UPCALL;
122 so->so_options &= ~SO_ACCEPTFILTER;
125 SIGIO_SUNLOCK(); /* XXX */
126 so->so_upcall(so, so->so_upcallarg, 0);
123 so->so_upcall(so, so->so_upcallarg, 0);
127 SIGIO_SLOCK();
128 return;
129 }
130 TAILQ_REMOVE(&head->so_incomp, so, so_list);
131 head->so_incqlen--;
132 so->so_state &= ~SS_INCOMP;
133 TAILQ_INSERT_TAIL(&head->so_comp, so, so_list);
134 so->so_state |= SS_COMP;
135 sorwakeup_locked(head);

--- 6 unchanged lines hidden (view full) ---

142}
143
144void
145soisconnected(so)
146 struct socket *so;
147{
148 struct socket *head = so->so_head;
149
124 return;
125 }
126 TAILQ_REMOVE(&head->so_incomp, so, so_list);
127 head->so_incqlen--;
128 so->so_state &= ~SS_INCOMP;
129 TAILQ_INSERT_TAIL(&head->so_comp, so, so_list);
130 so->so_state |= SS_COMP;
131 sorwakeup_locked(head);

--- 6 unchanged lines hidden (view full) ---

138}
139
140void
141soisconnected(so)
142 struct socket *so;
143{
144 struct socket *head = so->so_head;
145
150 SIGIO_SLOCK();
151 so->so_state &= ~(SS_ISCONNECTING|SS_ISDISCONNECTING|SS_ISCONFIRMING);
152 so->so_state |= SS_ISCONNECTED;
153 if (head && (so->so_state & SS_INCOMP)) {
154 if ((so->so_options & SO_ACCEPTFILTER) != 0) {
155 so->so_upcall = head->so_accf->so_accept_filter->accf_callback;
156 so->so_upcallarg = head->so_accf->so_accept_filter_arg;
157 so->so_rcv.sb_flags |= SB_UPCALL;
158 so->so_options &= ~SO_ACCEPTFILTER;
146 so->so_state &= ~(SS_ISCONNECTING|SS_ISDISCONNECTING|SS_ISCONFIRMING);
147 so->so_state |= SS_ISCONNECTED;
148 if (head && (so->so_state & SS_INCOMP)) {
149 if ((so->so_options & SO_ACCEPTFILTER) != 0) {
150 so->so_upcall = head->so_accf->so_accept_filter->accf_callback;
151 so->so_upcallarg = head->so_accf->so_accept_filter_arg;
152 so->so_rcv.sb_flags |= SB_UPCALL;
153 so->so_options &= ~SO_ACCEPTFILTER;
159 SIGIO_SUNLOCK();
160 so->so_upcall(so, so->so_upcallarg, 0);
161 return;
162 }
163 TAILQ_REMOVE(&head->so_incomp, so, so_list);
164 head->so_incqlen--;
165 so->so_state &= ~SS_INCOMP;
166 TAILQ_INSERT_TAIL(&head->so_comp, so, so_list);
167 head->so_qlen++;
168 so->so_state |= SS_COMP;
169 sorwakeup_locked(head);
170 wakeup_one(&head->so_timeo);
171 } else {
172 wakeup(&so->so_timeo);
173 sorwakeup_locked(so);
174 sowwakeup_locked(so);
175 }
154 so->so_upcall(so, so->so_upcallarg, 0);
155 return;
156 }
157 TAILQ_REMOVE(&head->so_incomp, so, so_list);
158 head->so_incqlen--;
159 so->so_state &= ~SS_INCOMP;
160 TAILQ_INSERT_TAIL(&head->so_comp, so, so_list);
161 head->so_qlen++;
162 so->so_state |= SS_COMP;
163 sorwakeup_locked(head);
164 wakeup_one(&head->so_timeo);
165 } else {
166 wakeup(&so->so_timeo);
167 sorwakeup_locked(so);
168 sowwakeup_locked(so);
169 }
176 SIGIO_SUNLOCK();
177}
178
179void
180soisdisconnecting(so)
181 register struct socket *so;
182{
183
170}
171
172void
173soisdisconnecting(so)
174 register struct socket *so;
175{
176
184 SIGIO_SLOCK();
185 so->so_state &= ~SS_ISCONNECTING;
186 so->so_state |= (SS_ISDISCONNECTING|SS_CANTRCVMORE|SS_CANTSENDMORE);
187 wakeup((caddr_t)&so->so_timeo);
188 sowwakeup_locked(so);
189 sorwakeup_locked(so);
177 so->so_state &= ~SS_ISCONNECTING;
178 so->so_state |= (SS_ISDISCONNECTING|SS_CANTRCVMORE|SS_CANTSENDMORE);
179 wakeup((caddr_t)&so->so_timeo);
180 sowwakeup_locked(so);
181 sorwakeup_locked(so);
190 SIGIO_SUNLOCK();
191}
192
193void
194soisdisconnected_locked(so)
195 register struct socket *so;
196{
197
182}
183
184void
185soisdisconnected_locked(so)
186 register struct socket *so;
187{
188
198 SIGIO_ASSERT(SX_LOCKED);
199 so->so_state &= ~(SS_ISCONNECTING|SS_ISCONNECTED|SS_ISDISCONNECTING);
200 so->so_state |= (SS_CANTRCVMORE|SS_CANTSENDMORE|SS_ISDISCONNECTED);
201 wakeup((caddr_t)&so->so_timeo);
202 sowwakeup_locked(so);
203 sorwakeup_locked(so);
204}
205
206void
207soisdisconnected(so)
208 register struct socket *so;
209{
210
189 so->so_state &= ~(SS_ISCONNECTING|SS_ISCONNECTED|SS_ISDISCONNECTING);
190 so->so_state |= (SS_CANTRCVMORE|SS_CANTSENDMORE|SS_ISDISCONNECTED);
191 wakeup((caddr_t)&so->so_timeo);
192 sowwakeup_locked(so);
193 sorwakeup_locked(so);
194}
195
196void
197soisdisconnected(so)
198 register struct socket *so;
199{
200
211 SIGIO_SLOCK();
212 soisdisconnected_locked(so);
201 soisdisconnected_locked(so);
213 SIGIO_SUNLOCK();
214}
215
216/*
217 * When an attempt at a new connection is noted on a socket
218 * which accepts connections, sonewconn is called. If the
219 * connection is possible (subject to space constraints, etc.)
220 * then we allocate a new structure, propoerly linked into the
221 * data structure of the original socket, and return this.

--- 39 unchanged lines hidden (view full) ---

261 sp = TAILQ_FIRST(&head->so_incomp);
262 (void) soabort(sp);
263 }
264 TAILQ_INSERT_TAIL(&head->so_incomp, so, so_list);
265 so->so_state |= SS_INCOMP;
266 head->so_incqlen++;
267 }
268 if (connstatus) {
202}
203
204/*
205 * When an attempt at a new connection is noted on a socket
206 * which accepts connections, sonewconn is called. If the
207 * connection is possible (subject to space constraints, etc.)
208 * then we allocate a new structure, propoerly linked into the
209 * data structure of the original socket, and return this.

--- 39 unchanged lines hidden (view full) ---

249 sp = TAILQ_FIRST(&head->so_incomp);
250 (void) soabort(sp);
251 }
252 TAILQ_INSERT_TAIL(&head->so_incomp, so, so_list);
253 so->so_state |= SS_INCOMP;
254 head->so_incqlen++;
255 }
256 if (connstatus) {
269 SIGIO_SLOCK();
270 sorwakeup_locked(head);
257 sorwakeup_locked(head);
271 SIGIO_SUNLOCK();
272 wakeup((caddr_t)&head->so_timeo);
273 so->so_state |= connstatus;
274 }
275 return (so);
276}
277
278/*
279 * Socantsendmore indicates that no more data will be sent on the

--- 5 unchanged lines hidden (view full) ---

285 * Data queued for reading in the socket may yet be read.
286 */
287
288void
289socantsendmore(so)
290 struct socket *so;
291{
292
258 wakeup((caddr_t)&head->so_timeo);
259 so->so_state |= connstatus;
260 }
261 return (so);
262}
263
264/*
265 * Socantsendmore indicates that no more data will be sent on the

--- 5 unchanged lines hidden (view full) ---

271 * Data queued for reading in the socket may yet be read.
272 */
273
274void
275socantsendmore(so)
276 struct socket *so;
277{
278
293 SIGIO_SLOCK();
294 so->so_state |= SS_CANTSENDMORE;
295 sowwakeup_locked(so);
279 so->so_state |= SS_CANTSENDMORE;
280 sowwakeup_locked(so);
296 SIGIO_SUNLOCK();
297}
298
299void
300socantrcvmore(so)
301 struct socket *so;
302{
303
281}
282
283void
284socantrcvmore(so)
285 struct socket *so;
286{
287
304 SIGIO_SLOCK();
305 so->so_state |= SS_CANTRCVMORE;
306 sorwakeup_locked(so);
288 so->so_state |= SS_CANTRCVMORE;
289 sorwakeup_locked(so);
307 SIGIO_SUNLOCK();
308}
309
310/*
311 * Wait for data to arrive at/drain from a socket buffer.
312 */
313int
314sbwait(sb)
315 struct sockbuf *sb;

--- 32 unchanged lines hidden (view full) ---

348 * Do asynchronous notification via SIGIO
349 * if the socket has the SS_ASYNC flag set.
350 */
351void
352sowakeup(so, sb)
353 register struct socket *so;
354 register struct sockbuf *sb;
355{
290}
291
292/*
293 * Wait for data to arrive at/drain from a socket buffer.
294 */
295int
296sbwait(sb)
297 struct sockbuf *sb;

--- 32 unchanged lines hidden (view full) ---

330 * Do asynchronous notification via SIGIO
331 * if the socket has the SS_ASYNC flag set.
332 */
333void
334sowakeup(so, sb)
335 register struct socket *so;
336 register struct sockbuf *sb;
337{
356 SIGIO_ASSERT(SX_LOCKED);
357
358 selwakeup(&sb->sb_sel);
359 sb->sb_flags &= ~SB_SEL;
360 if (sb->sb_flags & SB_WAIT) {
361 sb->sb_flags &= ~SB_WAIT;
362 wakeup((caddr_t)&sb->sb_cc);
363 }
364 if ((so->so_state & SS_ASYNC) && so->so_sigio != NULL)
338
339 selwakeup(&sb->sb_sel);
340 sb->sb_flags &= ~SB_SEL;
341 if (sb->sb_flags & SB_WAIT) {
342 sb->sb_flags &= ~SB_WAIT;
343 wakeup((caddr_t)&sb->sb_cc);
344 }
345 if ((so->so_state & SS_ASYNC) && so->so_sigio != NULL)
365 pgsigio(so->so_sigio, SIGIO, 0);
346 pgsigio(&so->so_sigio, SIGIO, 0);
366 if (sb->sb_flags & SB_UPCALL)
367 (*so->so_upcall)(so, so->so_upcallarg, M_DONTWAIT);
368 if (sb->sb_flags & SB_AIO)
369 aio_swake(so, sb);
370 KNOTE(&sb->sb_sel.si_note, 0);
371}
372
373/*

--- 668 unchanged lines hidden ---
347 if (sb->sb_flags & SB_UPCALL)
348 (*so->so_upcall)(so, so->so_upcallarg, M_DONTWAIT);
349 if (sb->sb_flags & SB_AIO)
350 aio_swake(so, sb);
351 KNOTE(&sb->sb_sel.si_note, 0);
352}
353
354/*

--- 668 unchanged lines hidden ---