* Now uses DoublyLinkedList instead of the struct list C stuff.
* Cleanup. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@29981 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2006-2008, Haiku, Inc. All Rights Reserved.
|
* Copyright 2006-2009, Haiku, Inc. All Rights Reserved.
|
||||||
* Distributed under the terms of the MIT License.
|
* Distributed under the terms of the MIT License.
|
||||||
*
|
*
|
||||||
* Authors:
|
* Authors:
|
||||||
@@ -35,32 +35,35 @@
|
|||||||
#include "utility.h"
|
#include "utility.h"
|
||||||
|
|
||||||
|
|
||||||
struct net_socket_private : net_socket {
|
struct net_socket_private;
|
||||||
struct list_link link;
|
typedef DoublyLinkedList<net_socket_private> SocketList;
|
||||||
team_id owner;
|
|
||||||
uint32 max_backlog;
|
|
||||||
uint32 child_count;
|
|
||||||
struct list pending_children;
|
|
||||||
struct list connected_children;
|
|
||||||
|
|
||||||
struct select_sync_pool *select_pool;
|
struct net_socket_private
|
||||||
mutex lock;
|
: net_socket, DoublyLinkedListLinkImpl<net_socket_private> {
|
||||||
|
team_id owner;
|
||||||
|
uint32 max_backlog;
|
||||||
|
uint32 child_count;
|
||||||
|
SocketList pending_children;
|
||||||
|
SocketList connected_children;
|
||||||
|
|
||||||
|
struct select_sync_pool* select_pool;
|
||||||
|
mutex lock;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
void socket_delete(net_socket *socket);
|
void socket_delete(net_socket* socket);
|
||||||
int socket_bind(net_socket *socket, const struct sockaddr *address,
|
int socket_bind(net_socket* socket, const struct sockaddr* address,
|
||||||
socklen_t addressLength);
|
socklen_t addressLength);
|
||||||
int socket_setsockopt(net_socket *socket, int level, int option,
|
int socket_setsockopt(net_socket* socket, int level, int option,
|
||||||
const void *value, int length);
|
const void* value, int length);
|
||||||
|
|
||||||
|
|
||||||
struct list sSocketList;
|
static SocketList sSocketList;
|
||||||
mutex sSocketLock;
|
static mutex sSocketLock;
|
||||||
|
|
||||||
|
|
||||||
static size_t
|
static size_t
|
||||||
compute_user_iovec_length(iovec *userVec, uint32 count)
|
compute_user_iovec_length(iovec* userVec, uint32 count)
|
||||||
{
|
{
|
||||||
size_t length = 0;
|
size_t length = 0;
|
||||||
|
|
||||||
@@ -77,14 +80,9 @@ compute_user_iovec_length(iovec *userVec, uint32 count)
|
|||||||
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
delete_children(struct list *list)
|
delete_children(SocketList& list)
|
||||||
{
|
{
|
||||||
while (true) {
|
while (net_socket_private* child = list.RemoveHead()) {
|
||||||
net_socket_private *child
|
|
||||||
= (net_socket_private *)list_remove_head_item(list);
|
|
||||||
if (child == NULL)
|
|
||||||
break;
|
|
||||||
|
|
||||||
child->parent = NULL;
|
child->parent = NULL;
|
||||||
socket_delete(child);
|
socket_delete(child);
|
||||||
}
|
}
|
||||||
@@ -92,9 +90,9 @@ delete_children(struct list *list)
|
|||||||
|
|
||||||
|
|
||||||
static status_t
|
static status_t
|
||||||
create_socket(int family, int type, int protocol, net_socket_private **_socket)
|
create_socket(int family, int type, int protocol, net_socket_private** _socket)
|
||||||
{
|
{
|
||||||
struct net_socket_private *socket = new (std::nothrow) net_socket_private;
|
struct net_socket_private* socket = new(std::nothrow) net_socket_private;
|
||||||
if (socket == NULL)
|
if (socket == NULL)
|
||||||
return B_NO_MEMORY;
|
return B_NO_MEMORY;
|
||||||
|
|
||||||
@@ -113,11 +111,6 @@ create_socket(int family, int type, int protocol, net_socket_private **_socket)
|
|||||||
socket->receive.low_water_mark = 1;
|
socket->receive.low_water_mark = 1;
|
||||||
socket->receive.timeout = B_INFINITE_TIMEOUT;
|
socket->receive.timeout = B_INFINITE_TIMEOUT;
|
||||||
|
|
||||||
list_init_etc(&socket->pending_children, offsetof(net_socket_private,
|
|
||||||
link));
|
|
||||||
list_init_etc(&socket->connected_children, offsetof(net_socket_private,
|
|
||||||
link));
|
|
||||||
|
|
||||||
status_t status = get_domain_protocols(socket);
|
status_t status = get_domain_protocols(socket);
|
||||||
if (status < B_OK) {
|
if (status < B_OK) {
|
||||||
mutex_destroy(&socket->lock);
|
mutex_destroy(&socket->lock);
|
||||||
@@ -131,10 +124,10 @@ create_socket(int family, int type, int protocol, net_socket_private **_socket)
|
|||||||
|
|
||||||
|
|
||||||
static status_t
|
static status_t
|
||||||
add_ancillary_data(net_socket *socket, ancillary_data_container* container,
|
add_ancillary_data(net_socket* socket, ancillary_data_container* container,
|
||||||
void *data, size_t dataLen)
|
void* data, size_t dataLen)
|
||||||
{
|
{
|
||||||
cmsghdr *header = (cmsghdr*)data;
|
cmsghdr* header = (cmsghdr*)data;
|
||||||
|
|
||||||
while (dataLen > 0) {
|
while (dataLen > 0) {
|
||||||
if (header->cmsg_len < sizeof(cmsghdr) || header->cmsg_len > dataLen)
|
if (header->cmsg_len < sizeof(cmsghdr) || header->cmsg_len > dataLen)
|
||||||
@@ -157,10 +150,10 @@ add_ancillary_data(net_socket *socket, ancillary_data_container* container,
|
|||||||
|
|
||||||
|
|
||||||
static status_t
|
static status_t
|
||||||
process_ancillary_data(net_socket *socket, ancillary_data_container* container,
|
process_ancillary_data(net_socket* socket, ancillary_data_container* container,
|
||||||
msghdr *messageHeader)
|
msghdr* messageHeader)
|
||||||
{
|
{
|
||||||
uint8 *dataBuffer = (uint8*)messageHeader->msg_control;
|
uint8* dataBuffer = (uint8*)messageHeader->msg_control;
|
||||||
int dataBufferLen = messageHeader->msg_controllen;
|
int dataBufferLen = messageHeader->msg_controllen;
|
||||||
|
|
||||||
if (container == NULL || dataBuffer == NULL) {
|
if (container == NULL || dataBuffer == NULL) {
|
||||||
@@ -169,7 +162,7 @@ process_ancillary_data(net_socket *socket, ancillary_data_container* container,
|
|||||||
}
|
}
|
||||||
|
|
||||||
ancillary_data_header header;
|
ancillary_data_header header;
|
||||||
void *data = NULL;
|
void* data = NULL;
|
||||||
|
|
||||||
while ((data = next_ancillary_data(container, data, &header)) != NULL) {
|
while ((data = next_ancillary_data(container, data, &header)) != NULL) {
|
||||||
if (socket->first_info->process_ancillary_data == NULL)
|
if (socket->first_info->process_ancillary_data == NULL)
|
||||||
@@ -191,7 +184,7 @@ process_ancillary_data(net_socket *socket, ancillary_data_container* container,
|
|||||||
|
|
||||||
|
|
||||||
static ssize_t
|
static ssize_t
|
||||||
socket_receive_no_buffer(net_socket *socket, msghdr *header, void *data,
|
socket_receive_no_buffer(net_socket* socket, msghdr* header, void* data,
|
||||||
size_t length, int flags)
|
size_t length, int flags)
|
||||||
{
|
{
|
||||||
iovec stackVec = { data, length };
|
iovec stackVec = { data, length };
|
||||||
@@ -227,9 +220,9 @@ socket_receive_no_buffer(net_socket *socket, msghdr *header, void *data,
|
|||||||
|
|
||||||
|
|
||||||
status_t
|
status_t
|
||||||
socket_open(int family, int type, int protocol, net_socket **_socket)
|
socket_open(int family, int type, int protocol, net_socket** _socket)
|
||||||
{
|
{
|
||||||
net_socket_private *socket;
|
net_socket_private* socket;
|
||||||
status_t status = create_socket(family, type, protocol, &socket);
|
status_t status = create_socket(family, type, protocol, &socket);
|
||||||
if (status < B_OK)
|
if (status < B_OK)
|
||||||
return status;
|
return status;
|
||||||
@@ -243,7 +236,7 @@ socket_open(int family, int type, int protocol, net_socket **_socket)
|
|||||||
socket->owner = team_get_current_team_id();
|
socket->owner = team_get_current_team_id();
|
||||||
|
|
||||||
mutex_lock(&sSocketLock);
|
mutex_lock(&sSocketLock);
|
||||||
list_add_item(&sSocketList, socket);
|
sSocketList.Add(socket);
|
||||||
mutex_unlock(&sSocketLock);
|
mutex_unlock(&sSocketLock);
|
||||||
|
|
||||||
*_socket = socket;
|
*_socket = socket;
|
||||||
@@ -252,15 +245,15 @@ socket_open(int family, int type, int protocol, net_socket **_socket)
|
|||||||
|
|
||||||
|
|
||||||
status_t
|
status_t
|
||||||
socket_close(net_socket *_socket)
|
socket_close(net_socket* _socket)
|
||||||
{
|
{
|
||||||
net_socket_private *socket = (net_socket_private *)_socket;
|
net_socket_private* socket = (net_socket_private*)_socket;
|
||||||
return socket->first_info->close(socket->first_protocol);
|
return socket->first_info->close(socket->first_protocol);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
status_t
|
status_t
|
||||||
socket_free(net_socket *socket)
|
socket_free(net_socket* socket)
|
||||||
{
|
{
|
||||||
status_t status = socket->first_info->free(socket->first_protocol);
|
status_t status = socket->first_info->free(socket->first_protocol);
|
||||||
if (status == B_BUSY)
|
if (status == B_BUSY)
|
||||||
@@ -272,16 +265,16 @@ socket_free(net_socket *socket)
|
|||||||
|
|
||||||
|
|
||||||
status_t
|
status_t
|
||||||
socket_readv(net_socket *socket, const iovec *vecs, size_t vecCount,
|
socket_readv(net_socket* socket, const iovec* vecs, size_t vecCount,
|
||||||
size_t *_length)
|
size_t* _length)
|
||||||
{
|
{
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
status_t
|
status_t
|
||||||
socket_writev(net_socket *socket, const iovec *vecs, size_t vecCount,
|
socket_writev(net_socket* socket, const iovec* vecs, size_t vecCount,
|
||||||
size_t *_length)
|
size_t* _length)
|
||||||
{
|
{
|
||||||
if (socket->peer.ss_len == 0)
|
if (socket->peer.ss_len == 0)
|
||||||
return ECONNRESET;
|
return ECONNRESET;
|
||||||
@@ -294,7 +287,7 @@ socket_writev(net_socket *socket, const iovec *vecs, size_t vecCount,
|
|||||||
}
|
}
|
||||||
|
|
||||||
// TODO: useful, maybe even computed header space!
|
// TODO: useful, maybe even computed header space!
|
||||||
net_buffer *buffer = gNetBufferModule.create(256);
|
net_buffer* buffer = gNetBufferModule.create(256);
|
||||||
if (buffer == NULL)
|
if (buffer == NULL)
|
||||||
return ENOBUFS;
|
return ENOBUFS;
|
||||||
|
|
||||||
@@ -329,7 +322,7 @@ socket_writev(net_socket *socket, const iovec *vecs, size_t vecCount,
|
|||||||
|
|
||||||
|
|
||||||
status_t
|
status_t
|
||||||
socket_control(net_socket *socket, int32 op, void *data, size_t length)
|
socket_control(net_socket* socket, int32 op, void* data, size_t length)
|
||||||
{
|
{
|
||||||
switch (op) {
|
switch (op) {
|
||||||
case FIONBIO:
|
case FIONBIO:
|
||||||
@@ -365,21 +358,21 @@ socket_control(net_socket *socket, int32 op, void *data, size_t length)
|
|||||||
|
|
||||||
|
|
||||||
ssize_t
|
ssize_t
|
||||||
socket_read_avail(net_socket *socket)
|
socket_read_avail(net_socket* socket)
|
||||||
{
|
{
|
||||||
return socket->first_info->read_avail(socket->first_protocol);
|
return socket->first_info->read_avail(socket->first_protocol);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
ssize_t
|
ssize_t
|
||||||
socket_send_avail(net_socket *socket)
|
socket_send_avail(net_socket* socket)
|
||||||
{
|
{
|
||||||
return socket->first_info->send_avail(socket->first_protocol);
|
return socket->first_info->send_avail(socket->first_protocol);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
status_t
|
status_t
|
||||||
socket_send_data(net_socket *socket, net_buffer *buffer)
|
socket_send_data(net_socket* socket, net_buffer* buffer)
|
||||||
{
|
{
|
||||||
return socket->first_info->send_data(socket->first_protocol,
|
return socket->first_info->send_data(socket->first_protocol,
|
||||||
buffer);
|
buffer);
|
||||||
@@ -387,8 +380,8 @@ socket_send_data(net_socket *socket, net_buffer *buffer)
|
|||||||
|
|
||||||
|
|
||||||
status_t
|
status_t
|
||||||
socket_receive_data(net_socket *socket, size_t length, uint32 flags,
|
socket_receive_data(net_socket* socket, size_t length, uint32 flags,
|
||||||
net_buffer **_buffer)
|
net_buffer** _buffer)
|
||||||
{
|
{
|
||||||
status_t status = socket->first_info->read_data(socket->first_protocol,
|
status_t status = socket->first_info->read_data(socket->first_protocol,
|
||||||
length, flags, _buffer);
|
length, flags, _buffer);
|
||||||
@@ -406,15 +399,17 @@ socket_receive_data(net_socket *socket, size_t length, uint32 flags,
|
|||||||
|
|
||||||
|
|
||||||
status_t
|
status_t
|
||||||
socket_get_next_stat(uint32 *_cookie, int family, struct net_stat *stat)
|
socket_get_next_stat(uint32* _cookie, int family, struct net_stat* stat)
|
||||||
{
|
{
|
||||||
MutexLocker locker(sSocketLock);
|
MutexLocker locker(sSocketLock);
|
||||||
|
|
||||||
net_socket_private *socket = NULL;
|
net_socket_private* socket = NULL;
|
||||||
|
SocketList::Iterator iterator = sSocketList.GetIterator();
|
||||||
uint32 cookie = *_cookie;
|
uint32 cookie = *_cookie;
|
||||||
uint32 count = 0;
|
uint32 count = 0;
|
||||||
while ((socket = (net_socket_private *)list_get_next_item(&sSocketList,
|
while (iterator.HasNext()) {
|
||||||
socket)) != NULL) {
|
socket = iterator.Next();
|
||||||
|
|
||||||
// TODO: also traverse the pending connections
|
// TODO: also traverse the pending connections
|
||||||
if (count == cookie)
|
if (count == cookie)
|
||||||
break;
|
break;
|
||||||
@@ -451,9 +446,9 @@ socket_get_next_stat(uint32 *_cookie, int family, struct net_stat *stat)
|
|||||||
|
|
||||||
|
|
||||||
status_t
|
status_t
|
||||||
socket_spawn_pending(net_socket *_parent, net_socket **_socket)
|
socket_spawn_pending(net_socket* _parent, net_socket** _socket)
|
||||||
{
|
{
|
||||||
net_socket_private *parent = (net_socket_private *)_parent;
|
net_socket_private* parent = (net_socket_private*)_parent;
|
||||||
|
|
||||||
MutexLocker locker(parent->lock);
|
MutexLocker locker(parent->lock);
|
||||||
|
|
||||||
@@ -463,7 +458,7 @@ socket_spawn_pending(net_socket *_parent, net_socket **_socket)
|
|||||||
if (parent->child_count > 3 * parent->max_backlog / 2)
|
if (parent->child_count > 3 * parent->max_backlog / 2)
|
||||||
return ENOBUFS;
|
return ENOBUFS;
|
||||||
|
|
||||||
net_socket_private *socket;
|
net_socket_private* socket;
|
||||||
status_t status = create_socket(parent->family, parent->type,
|
status_t status = create_socket(parent->family, parent->type,
|
||||||
parent->protocol, &socket);
|
parent->protocol, &socket);
|
||||||
if (status < B_OK)
|
if (status < B_OK)
|
||||||
@@ -479,7 +474,7 @@ socket_spawn_pending(net_socket *_parent, net_socket **_socket)
|
|||||||
memcpy(&socket->peer, &parent->peer, parent->peer.ss_len);
|
memcpy(&socket->peer, &parent->peer, parent->peer.ss_len);
|
||||||
|
|
||||||
// add to the parent's list of pending connections
|
// add to the parent's list of pending connections
|
||||||
list_add_item(&parent->pending_children, socket);
|
parent->pending_children.Add(socket);
|
||||||
socket->parent = parent;
|
socket->parent = parent;
|
||||||
parent->child_count++;
|
parent->child_count++;
|
||||||
|
|
||||||
@@ -489,20 +484,20 @@ socket_spawn_pending(net_socket *_parent, net_socket **_socket)
|
|||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
socket_delete(net_socket *_socket)
|
socket_delete(net_socket* _socket)
|
||||||
{
|
{
|
||||||
net_socket_private *socket = (net_socket_private *)_socket;
|
net_socket_private* socket = (net_socket_private*)_socket;
|
||||||
|
|
||||||
if (socket->parent != NULL)
|
if (socket->parent != NULL)
|
||||||
panic("socket still has a parent!");
|
panic("socket still has a parent!");
|
||||||
|
|
||||||
mutex_lock(&sSocketLock);
|
mutex_lock(&sSocketLock);
|
||||||
list_remove_item(&sSocketList, socket);
|
sSocketList.Remove(socket);
|
||||||
mutex_unlock(&sSocketLock);
|
mutex_unlock(&sSocketLock);
|
||||||
|
|
||||||
// also delete all children of this socket
|
// also delete all children of this socket
|
||||||
delete_children(&socket->pending_children);
|
delete_children(socket->pending_children);
|
||||||
delete_children(&socket->connected_children);
|
delete_children(socket->connected_children);
|
||||||
|
|
||||||
put_domain_protocols(socket);
|
put_domain_protocols(socket);
|
||||||
mutex_destroy(&socket->lock);
|
mutex_destroy(&socket->lock);
|
||||||
@@ -511,14 +506,13 @@ socket_delete(net_socket *_socket)
|
|||||||
|
|
||||||
|
|
||||||
status_t
|
status_t
|
||||||
socket_dequeue_connected(net_socket *_parent, net_socket **_socket)
|
socket_dequeue_connected(net_socket* _parent, net_socket** _socket)
|
||||||
{
|
{
|
||||||
net_socket_private *parent = (net_socket_private *)_parent;
|
net_socket_private* parent = (net_socket_private*)_parent;
|
||||||
|
|
||||||
mutex_lock(&parent->lock);
|
mutex_lock(&parent->lock);
|
||||||
|
|
||||||
net_socket_private *socket = (net_socket_private *)list_remove_head_item(
|
net_socket_private* socket = parent->connected_children.RemoveHead();
|
||||||
&parent->connected_children);
|
|
||||||
if (socket != NULL) {
|
if (socket != NULL) {
|
||||||
socket->parent = NULL;
|
socket->parent = NULL;
|
||||||
parent->child_count--;
|
parent->child_count--;
|
||||||
@@ -531,7 +525,7 @@ socket_dequeue_connected(net_socket *_parent, net_socket **_socket)
|
|||||||
return B_ENTRY_NOT_FOUND;
|
return B_ENTRY_NOT_FOUND;
|
||||||
|
|
||||||
mutex_lock(&sSocketLock);
|
mutex_lock(&sSocketLock);
|
||||||
list_add_item(&sSocketList, socket);
|
sSocketList.Add(socket);
|
||||||
mutex_unlock(&sSocketLock);
|
mutex_unlock(&sSocketLock);
|
||||||
|
|
||||||
return B_OK;
|
return B_OK;
|
||||||
@@ -539,78 +533,65 @@ socket_dequeue_connected(net_socket *_parent, net_socket **_socket)
|
|||||||
|
|
||||||
|
|
||||||
ssize_t
|
ssize_t
|
||||||
socket_count_connected(net_socket *_parent)
|
socket_count_connected(net_socket* _parent)
|
||||||
{
|
{
|
||||||
net_socket_private *parent = (net_socket_private *)_parent;
|
net_socket_private* parent = (net_socket_private*)_parent;
|
||||||
|
|
||||||
MutexLocker _(parent->lock);
|
MutexLocker _(parent->lock);
|
||||||
|
return parent->connected_children.Count();
|
||||||
ssize_t count = 0;
|
|
||||||
void *item = NULL;
|
|
||||||
while ((item = list_get_next_item(&parent->connected_children,
|
|
||||||
item)) != NULL) {
|
|
||||||
count++;
|
|
||||||
}
|
|
||||||
|
|
||||||
return count;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
status_t
|
status_t
|
||||||
socket_set_max_backlog(net_socket *_socket, uint32 backlog)
|
socket_set_max_backlog(net_socket* _socket, uint32 backlog)
|
||||||
{
|
{
|
||||||
net_socket_private *socket = (net_socket_private *)_socket;
|
net_socket_private* socket = (net_socket_private*)_socket;
|
||||||
|
|
||||||
// we enforce an upper limit of connections waiting to be accepted
|
// we enforce an upper limit of connections waiting to be accepted
|
||||||
if (backlog > 256)
|
if (backlog > 256)
|
||||||
backlog = 256;
|
backlog = 256;
|
||||||
|
|
||||||
mutex_lock(&socket->lock);
|
MutexLocker _(socket->lock);
|
||||||
|
|
||||||
// first remove the pending connections, then the already connected
|
// first remove the pending connections, then the already connected
|
||||||
// ones as needed
|
// ones as needed
|
||||||
net_socket_private *child;
|
net_socket_private* child;
|
||||||
while (socket->child_count > backlog
|
while (socket->child_count > backlog
|
||||||
&& (child = (net_socket_private *)list_remove_tail_item(
|
&& (child = socket->pending_children.RemoveTail()) != NULL) {
|
||||||
&socket->pending_children)) != NULL) {
|
|
||||||
child->parent = NULL;
|
child->parent = NULL;
|
||||||
socket->child_count--;
|
socket->child_count--;
|
||||||
}
|
}
|
||||||
while (socket->child_count > backlog
|
while (socket->child_count > backlog
|
||||||
&& (child = (net_socket_private *)list_remove_tail_item(
|
&& (child = socket->connected_children.RemoveTail()) != NULL) {
|
||||||
&socket->connected_children)) != NULL) {
|
|
||||||
child->parent = NULL;
|
child->parent = NULL;
|
||||||
socket_delete(child);
|
socket_delete(child);
|
||||||
socket->child_count--;
|
socket->child_count--;
|
||||||
}
|
}
|
||||||
|
|
||||||
socket->max_backlog = backlog;
|
socket->max_backlog = backlog;
|
||||||
mutex_unlock(&socket->lock);
|
|
||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*!
|
/*! The socket has been connected. It will be moved to the connected queue
|
||||||
The socket has been connected. It will be moved to the connected queue
|
|
||||||
of its parent socket.
|
of its parent socket.
|
||||||
*/
|
*/
|
||||||
status_t
|
status_t
|
||||||
socket_connected(net_socket *socket)
|
socket_connected(net_socket* socket)
|
||||||
{
|
{
|
||||||
net_socket_private *parent = (net_socket_private *)socket->parent;
|
net_socket_private* parent = (net_socket_private*)socket->parent;
|
||||||
if (parent == NULL)
|
if (parent == NULL)
|
||||||
return B_BAD_VALUE;
|
return B_BAD_VALUE;
|
||||||
|
|
||||||
mutex_lock(&parent->lock);
|
MutexLocker _(&parent->lock);
|
||||||
|
|
||||||
list_remove_item(&parent->pending_children, socket);
|
parent->pending_children.Remove((net_socket_private*)socket);
|
||||||
list_add_item(&parent->connected_children, socket);
|
parent->connected_children.Add((net_socket_private*)socket);
|
||||||
|
|
||||||
// notify parent
|
// notify parent
|
||||||
if (parent->select_pool)
|
if (parent->select_pool)
|
||||||
notify_select_event_pool(parent->select_pool, B_SELECT_READ);
|
notify_select_event_pool(parent->select_pool, B_SELECT_READ);
|
||||||
|
|
||||||
mutex_unlock(&parent->lock);
|
|
||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -619,9 +600,9 @@ socket_connected(net_socket *socket)
|
|||||||
|
|
||||||
|
|
||||||
status_t
|
status_t
|
||||||
socket_request_notification(net_socket *_socket, uint8 event, selectsync *sync)
|
socket_request_notification(net_socket* _socket, uint8 event, selectsync* sync)
|
||||||
{
|
{
|
||||||
net_socket_private *socket = (net_socket_private *)_socket;
|
net_socket_private* socket = (net_socket_private*)_socket;
|
||||||
|
|
||||||
mutex_lock(&socket->lock);
|
mutex_lock(&socket->lock);
|
||||||
|
|
||||||
@@ -663,36 +644,29 @@ socket_request_notification(net_socket *_socket, uint8 event, selectsync *sync)
|
|||||||
|
|
||||||
|
|
||||||
status_t
|
status_t
|
||||||
socket_cancel_notification(net_socket *_socket, uint8 event, selectsync *sync)
|
socket_cancel_notification(net_socket* _socket, uint8 event, selectsync* sync)
|
||||||
{
|
{
|
||||||
net_socket_private *socket = (net_socket_private *)_socket;
|
net_socket_private* socket = (net_socket_private*)_socket;
|
||||||
|
|
||||||
mutex_lock(&socket->lock);
|
MutexLocker _(socket->lock);
|
||||||
|
return remove_select_sync_pool_entry(&socket->select_pool, sync, event);
|
||||||
status_t status = remove_select_sync_pool_entry(&socket->select_pool,
|
|
||||||
sync, event);
|
|
||||||
|
|
||||||
mutex_unlock(&socket->lock);
|
|
||||||
return status;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
status_t
|
status_t
|
||||||
socket_notify(net_socket *_socket, uint8 event, int32 value)
|
socket_notify(net_socket* _socket, uint8 event, int32 value)
|
||||||
{
|
{
|
||||||
net_socket_private *socket = (net_socket_private *)_socket;
|
net_socket_private* socket = (net_socket_private*)_socket;
|
||||||
bool notify = true;
|
bool notify = true;
|
||||||
|
|
||||||
switch (event) {
|
switch (event) {
|
||||||
case B_SELECT_READ:
|
case B_SELECT_READ:
|
||||||
if ((ssize_t)socket->receive.low_water_mark > value
|
if ((ssize_t)socket->receive.low_water_mark > value && value >= B_OK)
|
||||||
&& value >= B_OK)
|
|
||||||
notify = false;
|
notify = false;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case B_SELECT_WRITE:
|
case B_SELECT_WRITE:
|
||||||
if ((ssize_t)socket->send.low_water_mark > value
|
if ((ssize_t)socket->send.low_water_mark > value && value >= B_OK)
|
||||||
&& value >= B_OK)
|
|
||||||
notify = false;
|
notify = false;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@@ -701,12 +675,11 @@ socket_notify(net_socket *_socket, uint8 event, int32 value)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
mutex_lock(&socket->lock);
|
MutexLocker _(socket->lock);
|
||||||
|
|
||||||
if (notify && socket->select_pool)
|
if (notify && socket->select_pool)
|
||||||
notify_select_event_pool(socket->select_pool, event);
|
notify_select_event_pool(socket->select_pool, event);
|
||||||
|
|
||||||
mutex_unlock(&socket->lock);
|
|
||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -715,13 +688,13 @@ socket_notify(net_socket *_socket, uint8 event, int32 value)
|
|||||||
|
|
||||||
|
|
||||||
int
|
int
|
||||||
socket_accept(net_socket *socket, struct sockaddr *address,
|
socket_accept(net_socket* socket, struct sockaddr* address,
|
||||||
socklen_t *_addressLength, net_socket **_acceptedSocket)
|
socklen_t* _addressLength, net_socket** _acceptedSocket)
|
||||||
{
|
{
|
||||||
if ((socket->options & SO_ACCEPTCONN) == 0)
|
if ((socket->options & SO_ACCEPTCONN) == 0)
|
||||||
return B_BAD_VALUE;
|
return B_BAD_VALUE;
|
||||||
|
|
||||||
net_socket *accepted;
|
net_socket* accepted;
|
||||||
status_t status = socket->first_info->accept(socket->first_protocol,
|
status_t status = socket->first_info->accept(socket->first_protocol,
|
||||||
&accepted);
|
&accepted);
|
||||||
if (status < B_OK)
|
if (status < B_OK)
|
||||||
@@ -739,7 +712,7 @@ socket_accept(net_socket *socket, struct sockaddr *address,
|
|||||||
|
|
||||||
|
|
||||||
int
|
int
|
||||||
socket_bind(net_socket *socket, const struct sockaddr *address,
|
socket_bind(net_socket* socket, const struct sockaddr* address,
|
||||||
socklen_t addressLength)
|
socklen_t addressLength)
|
||||||
{
|
{
|
||||||
sockaddr empty;
|
sockaddr empty;
|
||||||
@@ -755,7 +728,7 @@ socket_bind(net_socket *socket, const struct sockaddr *address,
|
|||||||
|
|
||||||
if (socket->address.ss_len != 0) {
|
if (socket->address.ss_len != 0) {
|
||||||
status_t status = socket->first_info->unbind(socket->first_protocol,
|
status_t status = socket->first_info->unbind(socket->first_protocol,
|
||||||
(sockaddr *)&socket->address);
|
(sockaddr*)&socket->address);
|
||||||
if (status < B_OK)
|
if (status < B_OK)
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
@@ -763,7 +736,7 @@ socket_bind(net_socket *socket, const struct sockaddr *address,
|
|||||||
memcpy(&socket->address, address, sizeof(sockaddr));
|
memcpy(&socket->address, address, sizeof(sockaddr));
|
||||||
|
|
||||||
status_t status = socket->first_info->bind(socket->first_protocol,
|
status_t status = socket->first_info->bind(socket->first_protocol,
|
||||||
(sockaddr *)address);
|
(sockaddr*)address);
|
||||||
if (status < B_OK) {
|
if (status < B_OK) {
|
||||||
// clear address again, as binding failed
|
// clear address again, as binding failed
|
||||||
socket->address.ss_len = 0;
|
socket->address.ss_len = 0;
|
||||||
@@ -774,7 +747,7 @@ socket_bind(net_socket *socket, const struct sockaddr *address,
|
|||||||
|
|
||||||
|
|
||||||
int
|
int
|
||||||
socket_connect(net_socket *socket, const struct sockaddr *address,
|
socket_connect(net_socket* socket, const struct sockaddr* address,
|
||||||
socklen_t addressLength)
|
socklen_t addressLength)
|
||||||
{
|
{
|
||||||
if (address == NULL || addressLength == 0)
|
if (address == NULL || addressLength == 0)
|
||||||
@@ -792,8 +765,8 @@ socket_connect(net_socket *socket, const struct sockaddr *address,
|
|||||||
|
|
||||||
|
|
||||||
int
|
int
|
||||||
socket_getpeername(net_socket *socket, struct sockaddr *address,
|
socket_getpeername(net_socket* socket, struct sockaddr* address,
|
||||||
socklen_t *_addressLength)
|
socklen_t* _addressLength)
|
||||||
{
|
{
|
||||||
if (socket->peer.ss_len == 0)
|
if (socket->peer.ss_len == 0)
|
||||||
return ENOTCONN;
|
return ENOTCONN;
|
||||||
@@ -805,8 +778,8 @@ socket_getpeername(net_socket *socket, struct sockaddr *address,
|
|||||||
|
|
||||||
|
|
||||||
int
|
int
|
||||||
socket_getsockname(net_socket *socket, struct sockaddr *address,
|
socket_getsockname(net_socket* socket, struct sockaddr* address,
|
||||||
socklen_t *_addressLength)
|
socklen_t* _addressLength)
|
||||||
{
|
{
|
||||||
if (socket->address.ss_len == 0)
|
if (socket->address.ss_len == 0)
|
||||||
return ENOTCONN;
|
return ENOTCONN;
|
||||||
@@ -819,8 +792,8 @@ socket_getsockname(net_socket *socket, struct sockaddr *address,
|
|||||||
|
|
||||||
|
|
||||||
status_t
|
status_t
|
||||||
socket_get_option(net_socket *socket, int level, int option, void *value,
|
socket_get_option(net_socket* socket, int level, int option, void* value,
|
||||||
int *_length)
|
int* _length)
|
||||||
{
|
{
|
||||||
if (level != SOL_SOCKET)
|
if (level != SOL_SOCKET)
|
||||||
return ENOPROTOOPT;
|
return ENOPROTOOPT;
|
||||||
@@ -828,7 +801,7 @@ socket_get_option(net_socket *socket, int level, int option, void *value,
|
|||||||
switch (option) {
|
switch (option) {
|
||||||
case SO_SNDBUF:
|
case SO_SNDBUF:
|
||||||
{
|
{
|
||||||
uint32 *size = (uint32 *)value;
|
uint32* size = (uint32*)value;
|
||||||
*size = socket->send.buffer_size;
|
*size = socket->send.buffer_size;
|
||||||
*_length = sizeof(uint32);
|
*_length = sizeof(uint32);
|
||||||
return B_OK;
|
return B_OK;
|
||||||
@@ -836,7 +809,7 @@ socket_get_option(net_socket *socket, int level, int option, void *value,
|
|||||||
|
|
||||||
case SO_RCVBUF:
|
case SO_RCVBUF:
|
||||||
{
|
{
|
||||||
uint32 *size = (uint32 *)value;
|
uint32* size = (uint32*)value;
|
||||||
*size = socket->receive.buffer_size;
|
*size = socket->receive.buffer_size;
|
||||||
*_length = sizeof(uint32);
|
*_length = sizeof(uint32);
|
||||||
return B_OK;
|
return B_OK;
|
||||||
@@ -844,7 +817,7 @@ socket_get_option(net_socket *socket, int level, int option, void *value,
|
|||||||
|
|
||||||
case SO_SNDLOWAT:
|
case SO_SNDLOWAT:
|
||||||
{
|
{
|
||||||
uint32 *size = (uint32 *)value;
|
uint32* size = (uint32*)value;
|
||||||
*size = socket->send.low_water_mark;
|
*size = socket->send.low_water_mark;
|
||||||
*_length = sizeof(uint32);
|
*_length = sizeof(uint32);
|
||||||
return B_OK;
|
return B_OK;
|
||||||
@@ -852,7 +825,7 @@ socket_get_option(net_socket *socket, int level, int option, void *value,
|
|||||||
|
|
||||||
case SO_RCVLOWAT:
|
case SO_RCVLOWAT:
|
||||||
{
|
{
|
||||||
uint32 *size = (uint32 *)value;
|
uint32* size = (uint32*)value;
|
||||||
*size = socket->receive.low_water_mark;
|
*size = socket->receive.low_water_mark;
|
||||||
*_length = sizeof(uint32);
|
*_length = sizeof(uint32);
|
||||||
return B_OK;
|
return B_OK;
|
||||||
@@ -872,7 +845,7 @@ socket_get_option(net_socket *socket, int level, int option, void *value,
|
|||||||
if (timeout == B_INFINITE_TIMEOUT)
|
if (timeout == B_INFINITE_TIMEOUT)
|
||||||
timeout = 0;
|
timeout = 0;
|
||||||
|
|
||||||
struct timeval *timeval = (struct timeval *)value;
|
struct timeval* timeval = (struct timeval*)value;
|
||||||
timeval->tv_sec = timeout / 1000000LL;
|
timeval->tv_sec = timeout / 1000000LL;
|
||||||
timeval->tv_usec = timeout % 1000000LL;
|
timeval->tv_usec = timeout % 1000000LL;
|
||||||
|
|
||||||
@@ -882,7 +855,7 @@ socket_get_option(net_socket *socket, int level, int option, void *value,
|
|||||||
|
|
||||||
case SO_NONBLOCK:
|
case SO_NONBLOCK:
|
||||||
{
|
{
|
||||||
int32 *_set = (int32 *)value;
|
int32* _set = (int32*)value;
|
||||||
*_set = socket->receive.timeout == 0 && socket->send.timeout == 0;
|
*_set = socket->receive.timeout == 0 && socket->send.timeout == 0;
|
||||||
*_length = sizeof(int32);
|
*_length = sizeof(int32);
|
||||||
return B_OK;
|
return B_OK;
|
||||||
@@ -898,7 +871,7 @@ socket_get_option(net_socket *socket, int level, int option, void *value,
|
|||||||
case SO_REUSEPORT:
|
case SO_REUSEPORT:
|
||||||
case SO_USELOOPBACK:
|
case SO_USELOOPBACK:
|
||||||
{
|
{
|
||||||
int32 *_set = (int32 *)value;
|
int32* _set = (int32*)value;
|
||||||
*_set = (socket->options & option) != 0;
|
*_set = (socket->options & option) != 0;
|
||||||
*_length = sizeof(int32);
|
*_length = sizeof(int32);
|
||||||
return B_OK;
|
return B_OK;
|
||||||
@@ -906,7 +879,7 @@ socket_get_option(net_socket *socket, int level, int option, void *value,
|
|||||||
|
|
||||||
case SO_ERROR:
|
case SO_ERROR:
|
||||||
{
|
{
|
||||||
int32 *_set = (int32 *)value;
|
int32* _set = (int32*)value;
|
||||||
*_set = socket->error;
|
*_set = socket->error;
|
||||||
*_length = sizeof(int32);
|
*_length = sizeof(int32);
|
||||||
|
|
||||||
@@ -925,8 +898,8 @@ socket_get_option(net_socket *socket, int level, int option, void *value,
|
|||||||
|
|
||||||
|
|
||||||
int
|
int
|
||||||
socket_getsockopt(net_socket *socket, int level, int option, void *value,
|
socket_getsockopt(net_socket* socket, int level, int option, void* value,
|
||||||
int *_length)
|
int* _length)
|
||||||
{
|
{
|
||||||
return socket->first_protocol->module->getsockopt(socket->first_protocol,
|
return socket->first_protocol->module->getsockopt(socket->first_protocol,
|
||||||
level, option, value, _length);
|
level, option, value, _length);
|
||||||
@@ -934,7 +907,7 @@ socket_getsockopt(net_socket *socket, int level, int option, void *value,
|
|||||||
|
|
||||||
|
|
||||||
int
|
int
|
||||||
socket_listen(net_socket *socket, int backlog)
|
socket_listen(net_socket* socket, int backlog)
|
||||||
{
|
{
|
||||||
status_t status = socket->first_info->listen(socket->first_protocol,
|
status_t status = socket->first_info->listen(socket->first_protocol,
|
||||||
backlog);
|
backlog);
|
||||||
@@ -946,7 +919,7 @@ socket_listen(net_socket *socket, int backlog)
|
|||||||
|
|
||||||
|
|
||||||
ssize_t
|
ssize_t
|
||||||
socket_receive(net_socket *socket, msghdr *header, void *data, size_t length,
|
socket_receive(net_socket* socket, msghdr* header, void* data, size_t length,
|
||||||
int flags)
|
int flags)
|
||||||
{
|
{
|
||||||
// If the protocol sports read_data_no_buffer() we use it.
|
// If the protocol sports read_data_no_buffer() we use it.
|
||||||
@@ -954,7 +927,7 @@ socket_receive(net_socket *socket, msghdr *header, void *data, size_t length,
|
|||||||
return socket_receive_no_buffer(socket, header, data, length, flags);
|
return socket_receive_no_buffer(socket, header, data, length, flags);
|
||||||
|
|
||||||
size_t totalLength = length;
|
size_t totalLength = length;
|
||||||
net_buffer *buffer;
|
net_buffer* buffer;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
// the convention to this function is that have header been
|
// the convention to this function is that have header been
|
||||||
@@ -1048,22 +1021,22 @@ socket_receive(net_socket *socket, msghdr *header, void *data, size_t length,
|
|||||||
|
|
||||||
|
|
||||||
ssize_t
|
ssize_t
|
||||||
socket_send(net_socket *socket, msghdr *header, const void *data, size_t length,
|
socket_send(net_socket* socket, msghdr* header, const void* data, size_t length,
|
||||||
int flags)
|
int flags)
|
||||||
{
|
{
|
||||||
const sockaddr *address = NULL;
|
const sockaddr* address = NULL;
|
||||||
socklen_t addressLength = 0;
|
socklen_t addressLength = 0;
|
||||||
size_t bytesLeft = length;
|
size_t bytesLeft = length;
|
||||||
|
|
||||||
if (length > SSIZE_MAX)
|
if (length > SSIZE_MAX)
|
||||||
return B_BAD_VALUE;
|
return B_BAD_VALUE;
|
||||||
|
|
||||||
ancillary_data_container *ancillaryData = NULL;
|
ancillary_data_container* ancillaryData = NULL;
|
||||||
CObjectDeleter<ancillary_data_container> ancillaryDataDeleter(NULL,
|
CObjectDeleter<ancillary_data_container> ancillaryDataDeleter(NULL,
|
||||||
&delete_ancillary_data_container);
|
&delete_ancillary_data_container);
|
||||||
|
|
||||||
if (header != NULL) {
|
if (header != NULL) {
|
||||||
address = (const sockaddr *)header->msg_name;
|
address = (const sockaddr*)header->msg_name;
|
||||||
addressLength = header->msg_namelen;
|
addressLength = header->msg_namelen;
|
||||||
|
|
||||||
// get the ancillary data
|
// get the ancillary data
|
||||||
@@ -1074,7 +1047,7 @@ socket_send(net_socket *socket, msghdr *header, const void *data, size_t length,
|
|||||||
ancillaryDataDeleter.SetTo(ancillaryData);
|
ancillaryDataDeleter.SetTo(ancillaryData);
|
||||||
|
|
||||||
status_t status = add_ancillary_data(socket, ancillaryData,
|
status_t status = add_ancillary_data(socket, ancillaryData,
|
||||||
(cmsghdr *)header->msg_control, header->msg_controllen);
|
(cmsghdr*)header->msg_control, header->msg_controllen);
|
||||||
if (status != B_OK)
|
if (status != B_OK)
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
@@ -1090,7 +1063,7 @@ socket_send(net_socket *socket, msghdr *header, const void *data, size_t length,
|
|||||||
return EISCONN;
|
return EISCONN;
|
||||||
|
|
||||||
// socket is connected, we use that address
|
// socket is connected, we use that address
|
||||||
address = (struct sockaddr *)&socket->peer;
|
address = (struct sockaddr*)&socket->peer;
|
||||||
addressLength = socket->peer.ss_len;
|
addressLength = socket->peer.ss_len;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1143,7 +1116,7 @@ socket_send(net_socket *socket, msghdr *header, const void *data, size_t length,
|
|||||||
|
|
||||||
while (bytesLeft > 0) {
|
while (bytesLeft > 0) {
|
||||||
// TODO: useful, maybe even computed header space!
|
// TODO: useful, maybe even computed header space!
|
||||||
net_buffer *buffer = gNetBufferModule.create(256);
|
net_buffer* buffer = gNetBufferModule.create(256);
|
||||||
if (buffer == NULL)
|
if (buffer == NULL)
|
||||||
return ENOBUFS;
|
return ENOBUFS;
|
||||||
|
|
||||||
@@ -1175,7 +1148,7 @@ socket_send(net_socket *socket, msghdr *header, const void *data, size_t length,
|
|||||||
// partial send
|
// partial send
|
||||||
vecOffset = bytes;
|
vecOffset = bytes;
|
||||||
length -= vecOffset;
|
length -= vecOffset;
|
||||||
data = (uint8 *)data + vecOffset;
|
data = (uint8*)data + vecOffset;
|
||||||
} else if (header != NULL) {
|
} else if (header != NULL) {
|
||||||
// proceed with next buffer, if any
|
// proceed with next buffer, if any
|
||||||
vecOffset = 0;
|
vecOffset = 0;
|
||||||
@@ -1224,7 +1197,7 @@ socket_send(net_socket *socket, msghdr *header, const void *data, size_t length,
|
|||||||
|
|
||||||
|
|
||||||
status_t
|
status_t
|
||||||
socket_set_option(net_socket *socket, int level, int option, const void *value,
|
socket_set_option(net_socket* socket, int level, int option, const void* value,
|
||||||
int length)
|
int length)
|
||||||
{
|
{
|
||||||
if (level != SOL_SOCKET)
|
if (level != SOL_SOCKET)
|
||||||
@@ -1237,7 +1210,7 @@ socket_set_option(net_socket *socket, int level, int option, const void *value,
|
|||||||
if (length < (int)sizeof(struct linger))
|
if (length < (int)sizeof(struct linger))
|
||||||
return B_BAD_VALUE;
|
return B_BAD_VALUE;
|
||||||
|
|
||||||
struct linger *linger = (struct linger *)value;
|
struct linger* linger = (struct linger*)value;
|
||||||
if (linger->l_onoff) {
|
if (linger->l_onoff) {
|
||||||
socket->options |= SO_LINGER;
|
socket->options |= SO_LINGER;
|
||||||
socket->linger = linger->l_linger;
|
socket->linger = linger->l_linger;
|
||||||
@@ -1252,28 +1225,28 @@ socket_set_option(net_socket *socket, int level, int option, const void *value,
|
|||||||
if (length != sizeof(uint32))
|
if (length != sizeof(uint32))
|
||||||
return B_BAD_VALUE;
|
return B_BAD_VALUE;
|
||||||
|
|
||||||
socket->send.buffer_size = *(const uint32 *)value;
|
socket->send.buffer_size = *(const uint32*)value;
|
||||||
return B_OK;
|
return B_OK;
|
||||||
|
|
||||||
case SO_RCVBUF:
|
case SO_RCVBUF:
|
||||||
if (length != sizeof(uint32))
|
if (length != sizeof(uint32))
|
||||||
return B_BAD_VALUE;
|
return B_BAD_VALUE;
|
||||||
|
|
||||||
socket->receive.buffer_size = *(const uint32 *)value;
|
socket->receive.buffer_size = *(const uint32*)value;
|
||||||
return B_OK;
|
return B_OK;
|
||||||
|
|
||||||
case SO_SNDLOWAT:
|
case SO_SNDLOWAT:
|
||||||
if (length != sizeof(uint32))
|
if (length != sizeof(uint32))
|
||||||
return B_BAD_VALUE;
|
return B_BAD_VALUE;
|
||||||
|
|
||||||
socket->send.low_water_mark = *(const uint32 *)value;
|
socket->send.low_water_mark = *(const uint32*)value;
|
||||||
return B_OK;
|
return B_OK;
|
||||||
|
|
||||||
case SO_RCVLOWAT:
|
case SO_RCVLOWAT:
|
||||||
if (length != sizeof(uint32))
|
if (length != sizeof(uint32))
|
||||||
return B_BAD_VALUE;
|
return B_BAD_VALUE;
|
||||||
|
|
||||||
socket->receive.low_water_mark = *(const uint32 *)value;
|
socket->receive.low_water_mark = *(const uint32*)value;
|
||||||
return B_OK;
|
return B_OK;
|
||||||
|
|
||||||
case SO_RCVTIMEO:
|
case SO_RCVTIMEO:
|
||||||
@@ -1282,7 +1255,7 @@ socket_set_option(net_socket *socket, int level, int option, const void *value,
|
|||||||
if (length != sizeof(struct timeval))
|
if (length != sizeof(struct timeval))
|
||||||
return B_BAD_VALUE;
|
return B_BAD_VALUE;
|
||||||
|
|
||||||
const struct timeval *timeval = (const struct timeval *)value;
|
const struct timeval* timeval = (const struct timeval*)value;
|
||||||
bigtime_t timeout = timeval->tv_sec * 1000000LL + timeval->tv_usec;
|
bigtime_t timeout = timeval->tv_sec * 1000000LL + timeval->tv_usec;
|
||||||
if (timeout == 0)
|
if (timeout == 0)
|
||||||
timeout = B_INFINITE_TIMEOUT;
|
timeout = B_INFINITE_TIMEOUT;
|
||||||
@@ -1298,7 +1271,7 @@ socket_set_option(net_socket *socket, int level, int option, const void *value,
|
|||||||
if (length != sizeof(int32))
|
if (length != sizeof(int32))
|
||||||
return B_BAD_VALUE;
|
return B_BAD_VALUE;
|
||||||
|
|
||||||
if (*(const int32 *)value) {
|
if (*(const int32*)value) {
|
||||||
socket->send.timeout = 0;
|
socket->send.timeout = 0;
|
||||||
socket->receive.timeout = 0;
|
socket->receive.timeout = 0;
|
||||||
} else {
|
} else {
|
||||||
@@ -1318,7 +1291,7 @@ socket_set_option(net_socket *socket, int level, int option, const void *value,
|
|||||||
if (length != sizeof(int32))
|
if (length != sizeof(int32))
|
||||||
return B_BAD_VALUE;
|
return B_BAD_VALUE;
|
||||||
|
|
||||||
if (*(const int32 *)value)
|
if (*(const int32*)value)
|
||||||
socket->options |= option;
|
socket->options |= option;
|
||||||
else
|
else
|
||||||
socket->options &= ~option;
|
socket->options &= ~option;
|
||||||
@@ -1329,7 +1302,7 @@ socket_set_option(net_socket *socket, int level, int option, const void *value,
|
|||||||
if (length != sizeof(int32))
|
if (length != sizeof(int32))
|
||||||
return B_BAD_VALUE;
|
return B_BAD_VALUE;
|
||||||
|
|
||||||
int index = *(const int32 *)value;
|
int index = *(const int32*)value;
|
||||||
if (index < 0)
|
if (index < 0)
|
||||||
return B_BAD_VALUE;
|
return B_BAD_VALUE;
|
||||||
|
|
||||||
@@ -1349,7 +1322,7 @@ socket_set_option(net_socket *socket, int level, int option, const void *value,
|
|||||||
|
|
||||||
|
|
||||||
int
|
int
|
||||||
socket_setsockopt(net_socket *socket, int level, int option, const void *value,
|
socket_setsockopt(net_socket* socket, int level, int option, const void* value,
|
||||||
int length)
|
int length)
|
||||||
{
|
{
|
||||||
return socket->first_protocol->module->setsockopt(socket->first_protocol,
|
return socket->first_protocol->module->setsockopt(socket->first_protocol,
|
||||||
@@ -1358,7 +1331,7 @@ socket_setsockopt(net_socket *socket, int level, int option, const void *value,
|
|||||||
|
|
||||||
|
|
||||||
int
|
int
|
||||||
socket_shutdown(net_socket *socket, int direction)
|
socket_shutdown(net_socket* socket, int direction)
|
||||||
{
|
{
|
||||||
return socket->first_info->shutdown(socket->first_protocol, direction);
|
return socket->first_info->shutdown(socket->first_protocol, direction);
|
||||||
}
|
}
|
||||||
@@ -1426,16 +1399,11 @@ socket_std_ops(int32 op, ...)
|
|||||||
switch (op) {
|
switch (op) {
|
||||||
case B_MODULE_INIT:
|
case B_MODULE_INIT:
|
||||||
{
|
{
|
||||||
// TODO: this is currently done in the net_stack driver
|
new (&sSocketList) SocketList;
|
||||||
// initialize the main stack if not done so already
|
|
||||||
//module_info *module;
|
|
||||||
//return get_module(NET_STARTER_MODULE_NAME, &module);
|
|
||||||
list_init_etc(&sSocketList, offsetof(net_socket_private, link));
|
|
||||||
mutex_init(&sSocketLock, "socket list");
|
mutex_init(&sSocketLock, "socket list");
|
||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
case B_MODULE_UNINIT:
|
case B_MODULE_UNINIT:
|
||||||
//return put_module(NET_STARTER_MODULE_NAME);
|
|
||||||
mutex_destroy(&sSocketLock);
|
mutex_destroy(&sSocketLock);
|
||||||
return B_OK;
|
return B_OK;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user