* Took Philippe's hints into account - we now do some locking in socket_spawn_pending() :-)
* Also take the max backlog into account as set by listen() - but reserve a little extra room for never completing connections, and that listen(..., 0) always accepts at least a single connection (as the BSDs do). * Spawned connections won't accept new connections, so SO_ACCEPTCONN must be cleared. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@19248 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
parent
44b3faaa19
commit
d2021d5766
@ -13,6 +13,7 @@
|
||||
#include <net_stack.h>
|
||||
|
||||
#include <KernelExport.h>
|
||||
#include <util/AutoLock.h>
|
||||
#include <util/list.h>
|
||||
#include <fs/select_sync_pool.h>
|
||||
|
||||
@ -190,6 +191,14 @@ socket_receive_data(net_socket *socket, size_t length, uint32 flags,
|
||||
status_t
|
||||
socket_spawn_pending(net_socket *parent, net_socket **_socket)
|
||||
{
|
||||
BenaphoreLocker locker(parent->lock);
|
||||
|
||||
// We actually accept more pending connections to compensate for those
|
||||
// that never complete, and also make sure at least a single connection
|
||||
// can always be accepted
|
||||
if (parent->child_count > 3 * parent->max_backlog / 2)
|
||||
return ENOBUFS;
|
||||
|
||||
net_socket *socket;
|
||||
status_t status = socket_create(parent->family, parent->type, parent->protocol, &socket);
|
||||
if (status < B_OK)
|
||||
@ -198,7 +207,7 @@ socket_spawn_pending(net_socket *parent, net_socket **_socket)
|
||||
// inherit parent's properties
|
||||
socket->send = parent->send;
|
||||
socket->receive = parent->receive;
|
||||
socket->options = parent->options;
|
||||
socket->options = parent->options & ~SO_ACCEPTCONN;
|
||||
socket->linger = parent->linger;
|
||||
memcpy(&socket->address, &parent->address, parent->address.ss_len);
|
||||
memcpy(&socket->peer, &parent->peer, parent->peer.ss_len);
|
||||
|
Loading…
Reference in New Issue
Block a user