* DatagramSocket::InitCheck() returned the sem_id instead of a status_t, causing

pings to fail (raw socket initialization) after r31079.
* Further cleanup.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@31238 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Axel Dörfler
2009-06-25 16:01:11 +00:00
parent dc59ebe78b
commit 65b5dd5064
2 changed files with 232 additions and 225 deletions
+16 -9
View File
@@ -1,5 +1,5 @@
/* /*
* Copyright 2007, Haiku, Inc. All Rights Reserved. * Copyright 2007-2009, Haiku, Inc. All Rights Reserved.
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
* *
* Authors: * Authors:
@@ -53,7 +53,8 @@ public:
SocketAddress LocalAddress() SocketAddress LocalAddress()
{ return SocketAddress(fDomain->address_module, &fSocket->address); } { return SocketAddress(fDomain->address_module, &fSocket->address); }
ConstSocketAddress LocalAddress() const ConstSocketAddress LocalAddress() const
{ return ConstSocketAddress(fDomain->address_module, &fSocket->address); } { return ConstSocketAddress(fDomain->address_module,
&fSocket->address); }
SocketAddress PeerAddress() SocketAddress PeerAddress()
{ return SocketAddress(fDomain->address_module, &fSocket->peer); } { return SocketAddress(fDomain->address_module, &fSocket->peer); }
@@ -70,8 +71,13 @@ protected:
}; };
inline ProtocolSocket::ProtocolSocket(net_socket *socket) inline
: fSocket(socket), fDomain(NULL) {} ProtocolSocket::ProtocolSocket(net_socket* socket)
:
fSocket(socket),
fDomain(NULL)
{
}
inline status_t inline status_t
@@ -147,7 +153,7 @@ DECL_DATAGRAM_SOCKET(inline)::DatagramSocket(const char *name,
: ProtocolSocket(socket), fCurrentBytes(0) : ProtocolSocket(socket), fCurrentBytes(0)
{ {
status_t status = LockingBase::Init(&fLock, name); status_t status = LockingBase::Init(&fLock, name);
if (status < B_OK) if (status != B_OK)
fNotify = status; fNotify = status;
else else
fNotify = create_sem(0, name); fNotify = create_sem(0, name);
@@ -164,7 +170,7 @@ DECL_DATAGRAM_SOCKET(inline)::~DatagramSocket()
DECL_DATAGRAM_SOCKET(inline status_t)::InitCheck() const DECL_DATAGRAM_SOCKET(inline status_t)::InitCheck() const
{ {
return fNotify; return fNotify >= 0 ? B_OK : fNotify;
} }
@@ -267,7 +273,8 @@ DECL_DATAGRAM_SOCKET(inline status_t)::BlockingDequeue(bool clone,
DECL_DATAGRAM_SOCKET(inline status_t)::SocketDequeue(uint32 flags, DECL_DATAGRAM_SOCKET(inline status_t)::SocketDequeue(uint32 flags,
net_buffer** _buffer) net_buffer** _buffer)
{ {
return BlockingDequeue(flags & MSG_PEEK, _SocketTimeout(flags), _buffer); return BlockingDequeue((flags & MSG_PEEK) != 0, _SocketTimeout(flags),
_buffer);
} }
@@ -336,7 +343,7 @@ DECL_DATAGRAM_SOCKET(inline bigtime_t)::_SocketTimeout(uint32 flags) const
{ {
bigtime_t timeout = fSocket->receive.timeout; bigtime_t timeout = fSocket->receive.timeout;
if (flags & MSG_DONTWAIT) if ((flags & MSG_DONTWAIT) != 0)
timeout = 0; timeout = 0;
else if (timeout != 0 && timeout != B_INFINITE_TIMEOUT) else if (timeout != 0 && timeout != B_INFINITE_TIMEOUT)
timeout += system_time(); timeout += system_time();
@@ -349,4 +356,4 @@ DECL_DATAGRAM_SOCKET(inline bigtime_t)::_SocketTimeout(uint32 flags) const
return timeout; return timeout;
} }
#endif #endif // PROTOCOL_UTILITIES_H
@@ -492,7 +492,7 @@ dump_ipv4_header(ipv4_header &header)
static int static int
dump_ipv4_multicast(int argc, char *argv[]) dump_ipv4_multicast(int argc, char** argv)
{ {
MulticastState::Iterator it = sMulticastState->GetIterator(); MulticastState::Iterator it = sMulticastState->GetIterator();
@@ -761,9 +761,10 @@ IPv4Multicast::JoinGroup(IPv4GroupInterface *state)
MutexLocker _(sMulticastGroupsLock); MutexLocker _(sMulticastGroupsLock);
sockaddr_in groupAddr; sockaddr_in groupAddr;
net_interface *intf = state->Interface(); net_interface* interface = state->Interface();
status_t status = intf->first_info->join_multicast(intf->first_protocol, status_t status = interface->first_info->join_multicast(
interface->first_protocol,
fill_sockaddr_in(&groupAddr, state->Address())); fill_sockaddr_in(&groupAddr, state->Address()));
if (status != B_OK) if (status != B_OK)
return status; return status;
@@ -781,9 +782,10 @@ IPv4Multicast::LeaveGroup(IPv4GroupInterface *state)
sMulticastState->Remove(state); sMulticastState->Remove(state);
sockaddr_in groupAddr; sockaddr_in groupAddr;
net_interface *intf = state->Interface(); net_interface* interface = state->Interface();
return intf->first_protocol->module->join_multicast(intf->first_protocol, return interface->first_protocol->module->join_multicast(
interface->first_protocol,
fill_sockaddr_in(&groupAddr, state->Address())); fill_sockaddr_in(&groupAddr, state->Address()));
} }
@@ -945,16 +947,14 @@ ipv4_generic_delta_membership(ipv4_protocol *protocol, int option,
const sockaddr_storage* _sourceAddr) const sockaddr_storage* _sourceAddr)
{ {
if (_groupAddr->ss_family != AF_INET) if (_groupAddr->ss_family != AF_INET)
return EINVAL; return B_BAD_VALUE;
if (_sourceAddr && _sourceAddr->ss_family != AF_INET) if (_sourceAddr && _sourceAddr->ss_family != AF_INET)
return EINVAL; return B_BAD_VALUE;
const in_addr* groupAddr = &((const sockaddr_in*)_groupAddr)->sin_addr;
net_interface* interface; net_interface* interface;
const in_addr *groupAddr, *sourceAddr = NULL;
groupAddr = &((const sockaddr_in *)_groupAddr)->sin_addr;
if (index == 0) if (index == 0)
interface = get_multicast_interface(protocol, groupAddr); interface = get_multicast_interface(protocol, groupAddr);
else else
@@ -963,6 +963,7 @@ ipv4_generic_delta_membership(ipv4_protocol *protocol, int option,
if (interface == NULL) if (interface == NULL)
return ENODEV; return ENODEV;
const in_addr* sourceAddr = NULL;
if (_sourceAddr) if (_sourceAddr)
sourceAddr = &((const sockaddr_in*)_sourceAddr)->sin_addr; sourceAddr = &((const sockaddr_in*)_sourceAddr)->sin_addr;
@@ -1332,10 +1333,10 @@ ipv4_send_routed_data(net_protocol *_protocol, struct net_route *route,
header->id = htons(atomic_add(&sPacketID, 1)); header->id = htons(atomic_add(&sPacketID, 1));
header->fragment_offset = 0; header->fragment_offset = 0;
if (protocol) { if (protocol) {
header->time_to_live = (buffer->flags & MSG_MCAST) header->time_to_live = (buffer->flags & MSG_MCAST) != 0
? protocol->multicast_time_to_live : protocol->time_to_live; ? protocol->multicast_time_to_live : protocol->time_to_live;
} else { } else {
header->time_to_live = (buffer->flags & MSG_MCAST) header->time_to_live = (buffer->flags & MSG_MCAST) != 0
? kDefaultMulticastTTL : kDefaultTTL; ? kDefaultMulticastTTL : kDefaultTTL;
} }
header->protocol = protocol header->protocol = protocol
@@ -1493,8 +1494,7 @@ ipv4_receive_data(net_buffer *buffer)
return B_BAD_DATA; return B_BAD_DATA;
struct sockaddr_in& source = *(struct sockaddr_in*)buffer->source; struct sockaddr_in& source = *(struct sockaddr_in*)buffer->source;
struct sockaddr_in &destination struct sockaddr_in& destination = *(struct sockaddr_in*)buffer->destination;
= *(struct sockaddr_in *)buffer->destination;
fill_sockaddr_in(&source, header.source); fill_sockaddr_in(&source, header.source);
fill_sockaddr_in(&destination, header.destination); fill_sockaddr_in(&destination, header.destination);