* Renamed net_datalink_module::send_data() to send_routed_data(), and

send_datagram() to send_data().
* Renamed DatagramSocket::SocketEnqueue() to EnqueueClone(), SocketDequeue()
  to Dequeue().
* Ordered the methods in ProtocolUtilities.h according to their declaration.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@37870 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Axel Dörfler 2010-08-03 12:00:06 +00:00
parent fb816644a7
commit 2651e51d92
6 changed files with 85 additions and 87 deletions

View File

@ -113,14 +113,14 @@ public:
status_t InitCheck() const;
status_t Enqueue(net_buffer* buffer);
status_t EnqueueClone(net_buffer* buffer);
status_t Dequeue(uint32 flags, net_buffer** _buffer);
net_buffer* Dequeue(bool clone);
status_t BlockingDequeue(bool peek, bigtime_t timeout,
net_buffer** _buffer);
void Clear();
status_t SocketEnqueue(net_buffer* buffer);
status_t SocketDequeue(uint32 flags,
net_buffer** _buffer);
void Clear();
bool IsEmpty() const { return fBuffers.IsEmpty(); }
ssize_t AvailableData() const;
@ -193,22 +193,7 @@ DECL_DATAGRAM_SOCKET(inline status_t)::Enqueue(net_buffer* buffer)
}
DECL_DATAGRAM_SOCKET(inline status_t)::_Enqueue(net_buffer* buffer)
{
if (fSocket->receive.buffer_size > 0
&& (fCurrentBytes + buffer->size) > fSocket->receive.buffer_size)
return ENOBUFS;
fBuffers.Add(buffer);
fCurrentBytes += buffer->size;
_NotifyOneReader(true);
return B_OK;
}
DECL_DATAGRAM_SOCKET(inline status_t)::SocketEnqueue(net_buffer* _buffer)
DECL_DATAGRAM_SOCKET(inline status_t)::EnqueueClone(net_buffer* _buffer)
{
AutoLocker _(fLock);
@ -224,6 +209,14 @@ DECL_DATAGRAM_SOCKET(inline status_t)::SocketEnqueue(net_buffer* _buffer)
}
DECL_DATAGRAM_SOCKET(inline status_t)::Dequeue(uint32 flags,
net_buffer** _buffer)
{
return BlockingDequeue((flags & MSG_PEEK) != 0, _SocketTimeout(flags),
_buffer);
}
DECL_DATAGRAM_SOCKET(inline net_buffer*)::Dequeue(bool peek)
{
AutoLocker _(fLock);
@ -231,21 +224,6 @@ DECL_DATAGRAM_SOCKET(inline net_buffer*)::Dequeue(bool peek)
}
DECL_DATAGRAM_SOCKET(inline net_buffer*)::_Dequeue(bool peek)
{
if (fBuffers.IsEmpty())
return NULL;
if (peek)
return ModuleBundle::Buffer()->clone(fBuffers.Head(), false);
net_buffer* buffer = fBuffers.RemoveHead();
fCurrentBytes -= buffer->size;
return buffer;
}
DECL_DATAGRAM_SOCKET(inline status_t)::BlockingDequeue(bool peek,
bigtime_t timeout, net_buffer** _buffer)
{
@ -281,14 +259,6 @@ DECL_DATAGRAM_SOCKET(inline status_t)::BlockingDequeue(bool peek,
}
DECL_DATAGRAM_SOCKET(inline status_t)::SocketDequeue(uint32 flags,
net_buffer** _buffer)
{
return BlockingDequeue((flags & MSG_PEEK) != 0, _SocketTimeout(flags),
_buffer);
}
DECL_DATAGRAM_SOCKET(inline void)::Clear()
{
AutoLocker _(fLock);
@ -296,15 +266,6 @@ DECL_DATAGRAM_SOCKET(inline void)::Clear()
}
DECL_DATAGRAM_SOCKET(inline void)::_Clear()
{
BufferList::Iterator it = fBuffers.GetIterator();
while (it.HasNext())
ModuleBundle::Buffer()->free(it.Next());
fCurrentBytes = 0;
}
DECL_DATAGRAM_SOCKET(inline ssize_t)::AvailableData() const
{
AutoLocker _(fLock);
@ -316,6 +277,19 @@ DECL_DATAGRAM_SOCKET(inline ssize_t)::AvailableData() const
}
DECL_DATAGRAM_SOCKET(inline void)::WakeAll()
{
release_sem_etc(fNotify, 0, B_RELEASE_ALL);
}
DECL_DATAGRAM_SOCKET(inline void)::NotifyOne()
{
release_sem_etc(fNotify, 1, B_RELEASE_IF_WAITING_ONLY
| B_DO_NOT_RESCHEDULE);
}
DECL_DATAGRAM_SOCKET(inline status_t)::SocketStatus(bool peek) const
{
if (peek)
@ -328,6 +302,45 @@ DECL_DATAGRAM_SOCKET(inline status_t)::SocketStatus(bool peek) const
}
DECL_DATAGRAM_SOCKET(inline status_t)::_Enqueue(net_buffer* buffer)
{
if (fSocket->receive.buffer_size > 0
&& (fCurrentBytes + buffer->size) > fSocket->receive.buffer_size)
return ENOBUFS;
fBuffers.Add(buffer);
fCurrentBytes += buffer->size;
_NotifyOneReader(true);
return B_OK;
}
DECL_DATAGRAM_SOCKET(inline net_buffer*)::_Dequeue(bool peek)
{
if (fBuffers.IsEmpty())
return NULL;
if (peek)
return ModuleBundle::Buffer()->clone(fBuffers.Head(), false);
net_buffer* buffer = fBuffers.RemoveHead();
fCurrentBytes -= buffer->size;
return buffer;
}
DECL_DATAGRAM_SOCKET(inline void)::_Clear()
{
BufferList::Iterator it = fBuffers.GetIterator();
while (it.HasNext())
ModuleBundle::Buffer()->free(it.Next());
fCurrentBytes = 0;
}
DECL_DATAGRAM_SOCKET(inline status_t)::_Wait(bigtime_t timeout)
{
LockingBase::Unlock(&fLock);
@ -339,19 +352,6 @@ DECL_DATAGRAM_SOCKET(inline status_t)::_Wait(bigtime_t timeout)
}
DECL_DATAGRAM_SOCKET(inline void)::WakeAll()
{
release_sem_etc(fNotify, 0, B_RELEASE_ALL);
}
DECL_DATAGRAM_SOCKET(inline void)::NotifyOne()
{
release_sem_etc(fNotify, 1, B_RELEASE_IF_WAITING_ONLY
| B_DO_NOT_RESCHEDULE);
}
DECL_DATAGRAM_SOCKET(inline void)::_NotifyOneReader(bool notifySocket)
{
release_sem_etc(fNotify, 1, B_RELEASE_IF_WAITING_ONLY

View File

@ -72,8 +72,8 @@ struct net_datalink_module_info {
status_t (*control)(net_domain* domain, int32 option, void* value,
size_t* _length);
status_t (*send_data)(net_route* route, net_buffer* buffer);
status_t (*send_datagram)(struct net_protocol* protocol,
status_t (*send_routed_data)(net_route* route, net_buffer* buffer);
status_t (*send_data)(struct net_protocol* protocol,
net_domain* domain, net_buffer* buffer);
bool (*is_local_address)(net_domain* domain,

View File

@ -645,7 +645,7 @@ send_fragments(ipv4_protocol* protocol, struct net_route* route,
// send fragment
if (status == B_OK)
status = sDatalinkModule->send_data(route, fragmentBuffer);
status = sDatalinkModule->send_routed_data(route, fragmentBuffer);
if (lastFragment) {
// we don't own the last buffer, so we don't have to free it
@ -745,7 +745,7 @@ raw_receive_data(net_buffer* buffer)
RawSocket* raw = iterator.Next();
if (raw->Socket()->protocol == buffer->protocol) {
raw->SocketEnqueue(buffer);
raw->EnqueueClone(buffer);
count++;
}
}
@ -1445,7 +1445,7 @@ ipv4_send_routed_data(net_protocol* _protocol, struct net_route* route,
return send_fragments(protocol, route, buffer, mtu);
}
return sDatalinkModule->send_data(route, buffer);
return sDatalinkModule->send_routed_data(route, buffer);
}
@ -1488,10 +1488,10 @@ ipv4_send_data(net_protocol* _protocol, net_buffer* buffer)
if (route == NULL)
return ENETUNREACH;
return sDatalinkModule->send_data(route, buffer);
return sDatalinkModule->send_routed_data(route, buffer);
}
return sDatalinkModule->send_datagram(protocol, sDomain, buffer);
return sDatalinkModule->send_data(protocol, sDomain, buffer);
}
@ -1513,7 +1513,7 @@ ipv4_read_data(net_protocol* _protocol, size_t numBytes, uint32 flags,
TRACE_SK(protocol, "ReadData(%lu, 0x%lx)", numBytes, flags);
return raw->SocketDequeue(flags, _buffer);
return raw->Dequeue(flags, _buffer);
}
@ -1685,7 +1685,7 @@ ipv4_deliver_data(net_protocol* _protocol, net_buffer* buffer)
if (protocol->raw == NULL)
return B_ERROR;
return protocol->raw->SocketEnqueue(buffer);
return protocol->raw->EnqueueClone(buffer);
}

View File

@ -994,7 +994,7 @@ UdpEndpoint::SendData(net_buffer *buffer)
{
TRACE_EP("SendData(%p [%lu bytes])", buffer, buffer->size);
return gDatalinkModule->send_datagram(this, NULL, buffer);
return gDatalinkModule->send_data(this, NULL, buffer);
}
@ -1015,9 +1015,9 @@ UdpEndpoint::FetchData(size_t numBytes, uint32 flags, net_buffer **_buffer)
{
TRACE_EP("FetchData(%ld, 0x%lx)", numBytes, flags);
status_t status = SocketDequeue(flags, _buffer);
status_t status = Dequeue(flags, _buffer);
TRACE_EP(" FetchData(): returned from fifo status=0x%lx", status);
if (status < B_OK)
if (status != B_OK)
return status;
TRACE_EP(" FetchData(): returns buffer with %ld bytes", (*_buffer)->size);
@ -1030,7 +1030,7 @@ UdpEndpoint::StoreData(net_buffer *buffer)
{
TRACE_EP("StoreData(%p [%ld bytes])", buffer, buffer->size);
return SocketEnqueue(buffer);
return EnqueueClone(buffer);
}
@ -1049,8 +1049,6 @@ UdpEndpoint::DeliverData(net_buffer *_buffer)
return status;
}
// we call Enqueue() instead of SocketEnqueue() as there is
// no need to clone the buffer again.
return Enqueue(buffer);
}

View File

@ -330,7 +330,7 @@ datalink_control(net_domain* _domain, int32 option, void* value,
static status_t
datalink_send_data(struct net_route* route, net_buffer* buffer)
datalink_send_routed_data(struct net_route* route, net_buffer* buffer)
{
TRACE("%s(route %p, buffer %p)\n", __FUNCTION__, route, buffer);
@ -379,7 +379,7 @@ datalink_send_data(struct net_route* route, net_buffer* buffer)
non-NULL), or the domain.
*/
static status_t
datalink_send_datagram(net_protocol* protocol, net_domain* domain,
datalink_send_data(net_protocol* protocol, net_domain* domain,
net_buffer* buffer)
{
TRACE("%s(%p, domain %p, buffer %p)\n", __FUNCTION__, protocol, domain,
@ -921,8 +921,8 @@ net_datalink_module_info gNetDatalinkModule = {
},
datalink_control,
datalink_send_routed_data,
datalink_send_data,
datalink_send_datagram,
datalink_is_local_address,
datalink_is_local_link_address,

View File

@ -242,7 +242,7 @@ LinkProtocol::_Unregister()
/*static*/ status_t
LinkProtocol::_MonitorData(net_device_monitor* monitor, net_buffer* packet)
{
return ((LinkProtocol*)monitor->cookie)->SocketEnqueue(packet);
return ((LinkProtocol*)monitor->cookie)->EnqueueClone(packet);
}
@ -535,7 +535,7 @@ link_shutdown(net_protocol* protocol, int direction)
static status_t
link_send_data(net_protocol* protocol, net_buffer* buffer)
{
return gNetDatalinkModule.send_datagram(protocol, sDomain, buffer);
return gNetDatalinkModule.send_data(protocol, sDomain, buffer);
}
@ -549,7 +549,7 @@ link_send_routed_data(net_protocol* protocol, struct net_route* route,
// The datalink layer will take care of the framing
return gNetDatalinkModule.send_data(route, buffer);
return gNetDatalinkModule.send_routed_data(route, buffer);
}
@ -568,7 +568,7 @@ static status_t
link_read_data(net_protocol* protocol, size_t numBytes, uint32 flags,
net_buffer** _buffer)
{
return ((LinkProtocol*)protocol)->SocketDequeue(flags, _buffer);
return ((LinkProtocol*)protocol)->Dequeue(flags, _buffer);
}