* net_buffer is a module, so it shouldn't have its initializers called

indirectly by the stack - they are now again usable separately as well.
* Minor cleanup.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@22673 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Axel Dörfler
2007-10-23 00:04:41 +00:00
parent 8c5602829e
commit 157da1cd6e
4 changed files with 45 additions and 67 deletions
@@ -47,13 +47,16 @@ device_reader_thread(void *_interface)
net_device *device = interface->device;
status_t status = B_OK;
RecursiveLocker rx_lock(interface->rx_lock);
RecursiveLocker locker(interface->rx_lock);
while (device->flags & IFF_UP) {
locker.Unlock();
net_buffer *buffer;
rx_lock.Unlock();
status = device->module->receive_data(device, &buffer);
rx_lock.Lock();
locker.Lock();
if (status == B_OK) {
// feed device monitors
DeviceMonitorList::Iterator iterator =
+37 -50
View File
@@ -309,7 +309,24 @@ get_node_at_offset(net_buffer_private *buffer, size_t offset)
}
// #pragma mark -
static void
copy_metadata(net_buffer *destination, const net_buffer *source)
{
memcpy(destination->source, source->source,
min_c(source->source->sa_len, sizeof(sockaddr_storage)));
memcpy(destination->destination, source->destination,
min_c(source->destination->sa_len, sizeof(sockaddr_storage)));
destination->flags = source->flags;
destination->interface = source->interface;
destination->offset = source->offset;
destination->size = source->size;
destination->protocol = source->protocol;
destination->type = source->type;
}
// #pragma mark - module API
static net_buffer *
@@ -367,23 +384,6 @@ free_buffer(net_buffer *_buffer)
}
static void
copy_metadata(net_buffer *destination, const net_buffer *source)
{
memcpy(destination->source, source->source,
min_c(source->source->sa_len, sizeof(sockaddr_storage)));
memcpy(destination->destination, source->destination,
min_c(source->destination->sa_len, sizeof(sockaddr_storage)));
destination->flags = source->flags;
destination->interface = source->interface;
destination->offset = source->offset;
destination->size = source->size;
destination->protocol = source->protocol;
destination->type = source->type;
}
/*! Creates a duplicate of the \a buffer. The new buffer does not share internal
storage; they are completely independent from each other.
*/
@@ -1185,44 +1185,31 @@ swap_addresses(net_buffer *buffer)
}
status_t
init_net_buffers()
{
// TODO improve our code a bit so we can add constructors
// and keep around half-constructed buffers in the slab
sNetBufferCache = create_object_cache("net buffer cache",
sizeof(net_buffer_private), 8, NULL, NULL, NULL);
if (sNetBufferCache == NULL)
return B_NO_MEMORY;
sDataNodeCache = create_object_cache("data node cache", BUFFER_SIZE, 0,
NULL, NULL, NULL);
if (sDataNodeCache == NULL) {
delete_object_cache(sNetBufferCache);
return B_NO_MEMORY;
}
return B_OK;
}
status_t
uninit_net_buffers()
{
delete_object_cache(sNetBufferCache);
delete_object_cache(sDataNodeCache);
return B_OK;
}
static status_t
std_ops(int32 op, ...)
{
switch (op) {
case B_MODULE_INIT:
// TODO: improve our code a bit so we can add constructors
// and keep around half-constructed buffers in the slab
sNetBufferCache = create_object_cache("net buffer cache",
sizeof(net_buffer_private), 8, NULL, NULL, NULL);
if (sNetBufferCache == NULL)
return B_NO_MEMORY;
sDataNodeCache = create_object_cache("data node cache", BUFFER_SIZE,
0, NULL, NULL, NULL);
if (sDataNodeCache == NULL) {
delete_object_cache(sNetBufferCache);
return B_NO_MEMORY;
}
return B_OK;
case B_MODULE_UNINIT:
delete_object_cache(sNetBufferCache);
delete_object_cache(sDataNodeCache);
return B_OK;
default:
+1 -9
View File
@@ -1,5 +1,5 @@
/*
* Copyright 2006, Haiku, Inc. All Rights Reserved.
* Copyright 2006-2007, Haiku, Inc. All Rights Reserved.
* Distributed under the terms of the MIT License.
*
* Authors:
@@ -785,10 +785,6 @@ init_stack()
goto err8;
}
status = init_net_buffers();
if (status < B_OK)
goto err9;
sInitialized = true;
link_init();
@@ -806,8 +802,6 @@ init_stack()
return B_OK;
err9:
hash_uninit(sReceivingProtocolChains);
err8:
hash_uninit(sDatalinkProtocolChains);
err7:
@@ -837,8 +831,6 @@ uninit_stack()
uninit_interfaces();
uninit_domains();
uninit_net_buffers();
benaphore_destroy(&sChainLock);
benaphore_destroy(&sInitializeChainLock);
@@ -1,5 +1,5 @@
/*
* Copyright 2006, Haiku, Inc. All Rights Reserved.
* Copyright 2006-2007, Haiku, Inc. All Rights Reserved.
* Distributed under the terms of the MIT License.
*
* Authors:
@@ -33,8 +33,4 @@ status_t put_domain_protocols(net_socket *socket);
status_t get_domain_datalink_protocols(net_interface *interface);
status_t put_domain_datalink_protocols(net_interface *interface);
// net_buffer.cpp
status_t init_net_buffers();
status_t uninit_net_buffers();
#endif // STACK_PRIVATE_H