summaryrefslogtreecommitdiffstats
path: root/sys/kern/uipc_socket2.c
diff options
context:
space:
mode:
authordg <dg@FreeBSD.org>1996-03-11 15:37:44 +0000
committerdg <dg@FreeBSD.org>1996-03-11 15:37:44 +0000
commita30b0a83b7ea8a0a022098b93d8cb4522d0b4cae (patch)
tree6a82fd66563f7ec21f07ec05191d9fb246d36575 /sys/kern/uipc_socket2.c
parent3f0638f73bd459a7f1a75fb0f6357b469188bb70 (diff)
downloadFreeBSD-src-a30b0a83b7ea8a0a022098b93d8cb4522d0b4cae.zip
FreeBSD-src-a30b0a83b7ea8a0a022098b93d8cb4522d0b4cae.tar.gz
Changed socket code to use 4.4BSD queue macros. This includes removing
the obsolete soqinsque and soqremque functions as well as collapsing so_q0len and so_qlen into a single queue length of unaccepted connections. Now the queue of unaccepted & complete connections is checked directly for queued sockets. The new code should be functionally equivilent to the old while being substantially faster - especially in cases where large numbers of connections are often queued for accept (e.g. http).
Diffstat (limited to 'sys/kern/uipc_socket2.c')
-rw-r--r--sys/kern/uipc_socket2.c79
1 files changed, 22 insertions, 57 deletions
diff --git a/sys/kern/uipc_socket2.c b/sys/kern/uipc_socket2.c
index 725dc3a..a09ed21 100644
--- a/sys/kern/uipc_socket2.c
+++ b/sys/kern/uipc_socket2.c
@@ -31,7 +31,7 @@
* SUCH DAMAGE.
*
* @(#)uipc_socket2.c 8.1 (Berkeley) 6/10/93
- * $Id: uipc_socket2.c,v 1.7 1995/12/14 22:51:02 bde Exp $
+ * $Id: uipc_socket2.c,v 1.8 1996/01/05 21:41:54 wollman Exp $
*/
#include <sys/param.h>
@@ -107,8 +107,11 @@ soisconnected(so)
so->so_state &= ~(SS_ISCONNECTING|SS_ISDISCONNECTING|SS_ISCONFIRMING);
so->so_state |= SS_ISCONNECTED;
- if (head && soqremque(so, 0)) {
- soqinsque(head, so, 1);
+ if (head && (so->so_state & SS_INCOMP)) {
+ TAILQ_REMOVE(&head->so_incomp, so, so_list);
+ so->so_state &= ~SS_INCOMP;
+ TAILQ_INSERT_TAIL(&head->so_comp, so, so_list);
+ so->so_state |= SS_COMP;
sorwakeup(head);
wakeup((caddr_t)&head->so_timeo);
} else {
@@ -161,12 +164,13 @@ sonewconn1(head, connstatus)
register struct socket *so;
int soqueue = connstatus ? 1 : 0;
- if (head->so_qlen + head->so_q0len > 3 * head->so_qlimit / 2)
+ if (head->so_qlen > 3 * head->so_qlimit / 2)
return ((struct socket *)0);
MALLOC(so, struct socket *, sizeof(*so), M_SOCKET, M_DONTWAIT);
if (so == NULL)
return ((struct socket *)0);
bzero((caddr_t)so, sizeof(*so));
+ so->so_head = head;
so->so_type = head->so_type;
so->so_options = head->so_options &~ SO_ACCEPTCONN;
so->so_linger = head->so_linger;
@@ -175,10 +179,22 @@ sonewconn1(head, connstatus)
so->so_timeo = head->so_timeo;
so->so_pgid = head->so_pgid;
(void) soreserve(so, head->so_snd.sb_hiwat, head->so_rcv.sb_hiwat);
- soqinsque(head, so, soqueue);
+ if (connstatus) {
+ TAILQ_INSERT_TAIL(&head->so_comp, so, so_list);
+ so->so_state |= SS_COMP;
+ } else {
+ TAILQ_INSERT_TAIL(&head->so_incomp, so, so_list);
+ so->so_state |= SS_INCOMP;
+ }
+ head->so_qlen++;
if ((*so->so_proto->pr_usrreq)(so, PRU_ATTACH,
(struct mbuf *)0, (struct mbuf *)0, (struct mbuf *)0)) {
- (void) soqremque(so, soqueue);
+ if (so->so_state & SS_COMP) {
+ TAILQ_REMOVE(&head->so_comp, so, so_list);
+ } else {
+ TAILQ_REMOVE(&head->so_incomp, so, so_list);
+ }
+ head->so_qlen--;
(void) free((caddr_t)so, M_SOCKET);
return ((struct socket *)0);
}
@@ -190,57 +206,6 @@ sonewconn1(head, connstatus)
return (so);
}
-void
-soqinsque(head, so, q)
- register struct socket *head, *so;
- int q;
-{
-
- register struct socket **prev;
- so->so_head = head;
- if (q == 0) {
- head->so_q0len++;
- so->so_q0 = 0;
- for (prev = &(head->so_q0); *prev; )
- prev = &((*prev)->so_q0);
- } else {
- head->so_qlen++;
- so->so_q = 0;
- for (prev = &(head->so_q); *prev; )
- prev = &((*prev)->so_q);
- }
- *prev = so;
-}
-
-int
-soqremque(so, q)
- register struct socket *so;
- int q;
-{
- register struct socket *head, *prev, *next;
-
- head = so->so_head;
- prev = head;
- for (;;) {
- next = q ? prev->so_q : prev->so_q0;
- if (next == so)
- break;
- if (next == 0)
- return (0);
- prev = next;
- }
- if (q == 0) {
- prev->so_q0 = next->so_q0;
- head->so_q0len--;
- } else {
- prev->so_q = next->so_q;
- head->so_qlen--;
- }
- next->so_q0 = next->so_q = 0;
- next->so_head = 0;
- return (1);
-}
-
/*
* Socantsendmore indicates that no more data will be sent on the
* socket; it would normally be applied to a socket when the user
OpenPOWER on IntegriCloud