3 kHTTPd -- the next generation
8 /****************************************************************
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2, or (at your option)
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 ****************************************************************/
25 #include "structure.h"
26 #include "prototypes.h"
29 #include <linux/smp_lock.h>
35 AcceptConnections puts all "accepted" connections in the
36 "WaitForHeader" queue.
39 The number of accepted connections
43 int AcceptConnections(const int CPUNR
, struct socket
*Socket
)
45 struct http_request
*NewRequest
;
46 struct socket
*NewSock
;
50 EnterFunction("AcceptConnections");
52 if (atomic_read(&ConnectCount
)>sysctl_khttpd_maxconnect
)
54 LeaveFunction("AcceptConnections - to many active connections");
58 if (Socket
==NULL
) return 0;
61 Quick test to see if there are connections on the queue.
62 This is cheaper than accept() itself because this saves us
63 the allocation of a new socket. (Which doesn't seem to be
66 if (Socket
->sk
->tp_pinfo
.af_tcp
.accept_queue
==NULL
)
74 NewSock
= sock_alloc();
79 NewSock
->type
= Socket
->type
;
80 NewSock
->ops
= Socket
->ops
;
83 error
= Socket
->ops
->accept(Socket
,NewSock
,O_NONBLOCK
);
88 sock_release(NewSock
);
92 if (NewSock
->sk
->state
==TCP_CLOSE
)
94 sock_release(NewSock
);
98 /* Allocate a request-entry for the connection */
99 NewRequest
= kmalloc(sizeof(struct http_request
),(int)GFP_KERNEL
);
101 if (NewRequest
== NULL
)
103 Send50x(NewSock
); /* Service not available. Try again later */
104 sock_release(NewSock
);
107 memset(NewRequest
,0,sizeof(struct http_request
));
109 NewRequest
->sock
= NewSock
;
111 NewRequest
->Next
= threadinfo
[CPUNR
].WaitForHeaderQueue
;
113 init_waitqueue_entry(&NewRequest
->sleep
,current
);
115 add_wait_queue(NewSock
->sk
->sleep
,&(NewRequest
->sleep
));
117 threadinfo
[CPUNR
].WaitForHeaderQueue
= NewRequest
;
119 atomic_inc(&ConnectCount
);
125 LeaveFunction("AcceptConnections");