adapted UDP to use ProtocolSocket which it already derived through DatagramSocket.
git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@20849 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -84,17 +84,7 @@ public:
|
|||||||
status_t StoreData(net_buffer *buffer);
|
status_t StoreData(net_buffer *buffer);
|
||||||
status_t DeliverData(net_buffer *buffer);
|
status_t DeliverData(net_buffer *buffer);
|
||||||
|
|
||||||
net_domain * Domain() const
|
UdpDomainSupport *DomainSupport() const { return fManager; }
|
||||||
{
|
|
||||||
return socket->first_protocol->module->get_domain(socket->first_protocol);
|
|
||||||
}
|
|
||||||
|
|
||||||
net_address_module_info *AddressModule() const
|
|
||||||
{
|
|
||||||
return Domain()->address_module;
|
|
||||||
}
|
|
||||||
|
|
||||||
UdpDomainSupport *DomainSupport() const { return fDomain; }
|
|
||||||
|
|
||||||
UdpEndpoint *hash_link;
|
UdpEndpoint *hash_link;
|
||||||
// link required by hash_table (see khash.h)
|
// link required by hash_table (see khash.h)
|
||||||
@@ -102,7 +92,7 @@ private:
|
|||||||
status_t _Activate();
|
status_t _Activate();
|
||||||
status_t _Deactivate();
|
status_t _Deactivate();
|
||||||
|
|
||||||
UdpDomainSupport *fDomain;
|
UdpDomainSupport *fManager;
|
||||||
bool fActive;
|
bool fActive;
|
||||||
// an active UdpEndpoint is part of the endpoint
|
// an active UdpEndpoint is part of the endpoint
|
||||||
// hash (and it is bound and optionally connected)
|
// hash (and it is bound and optionally connected)
|
||||||
@@ -699,12 +689,7 @@ UdpEndpointManager::_GetDomain(net_domain *domain, bool create)
|
|||||||
|
|
||||||
|
|
||||||
UdpEndpoint::UdpEndpoint(net_socket *socket)
|
UdpEndpoint::UdpEndpoint(net_socket *socket)
|
||||||
:
|
: DatagramSocket<>("udp endpoint", socket), fActive(false) {}
|
||||||
DatagramSocket<>("udp endpoint", socket),
|
|
||||||
fDomain(NULL),
|
|
||||||
fActive(false)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// #pragma mark - activation
|
// #pragma mark - activation
|
||||||
@@ -729,13 +714,13 @@ UdpEndpoint::Bind(const sockaddr *address)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (AddressModule()->get_port(address) == 0) {
|
if (AddressModule()->get_port(address) == 0) {
|
||||||
uint16 port = htons(fDomain->GetEphemeralPort());
|
uint16 port = htons(fManager->GetEphemeralPort());
|
||||||
if (port == 0)
|
if (port == 0)
|
||||||
return ENOBUFS;
|
return ENOBUFS;
|
||||||
// whoa, no more ephemeral port available!?!
|
// whoa, no more ephemeral port available!?!
|
||||||
AddressModule()->set_port((sockaddr *)&socket->address, port);
|
AddressModule()->set_port((sockaddr *)&socket->address, port);
|
||||||
} else {
|
} else {
|
||||||
status = fDomain->CheckBindRequest((sockaddr *)&socket->address,
|
status = fManager->CheckBindRequest((sockaddr *)&socket->address,
|
||||||
socket->options);
|
socket->options);
|
||||||
if (status < B_OK)
|
if (status < B_OK)
|
||||||
return status;
|
return status;
|
||||||
@@ -786,17 +771,12 @@ UdpEndpoint::Open()
|
|||||||
{
|
{
|
||||||
TRACE_EP("Open()");
|
TRACE_EP("Open()");
|
||||||
|
|
||||||
// we can't be the first protocol, there must an underlying
|
status_t status = ProtocolSocket::Open();
|
||||||
// network protocol that supplies us with an address module.
|
if (status < B_OK)
|
||||||
if (socket->first_protocol == NULL)
|
return status;
|
||||||
return EAFNOSUPPORT;
|
|
||||||
|
|
||||||
if (Domain() == NULL || Domain()->address_module == NULL)
|
fManager = sUdpEndpointManager->OpenEndpoint(this);
|
||||||
return EAFNOSUPPORT;
|
if (fManager == NULL)
|
||||||
|
|
||||||
fDomain = sUdpEndpointManager->OpenEndpoint(this);
|
|
||||||
|
|
||||||
if (fDomain == NULL)
|
|
||||||
return EAFNOSUPPORT;
|
return EAFNOSUPPORT;
|
||||||
|
|
||||||
return B_OK;
|
return B_OK;
|
||||||
@@ -821,7 +801,7 @@ UdpEndpoint::Free()
|
|||||||
{
|
{
|
||||||
TRACE_EP("Free()");
|
TRACE_EP("Free()");
|
||||||
|
|
||||||
return sUdpEndpointManager->FreeEndpoint(fDomain);
|
return sUdpEndpointManager->FreeEndpoint(fManager);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -830,7 +810,7 @@ UdpEndpoint::_Activate()
|
|||||||
{
|
{
|
||||||
if (fActive)
|
if (fActive)
|
||||||
return B_ERROR;
|
return B_ERROR;
|
||||||
status_t status = fDomain->ActivateEndpoint(this);
|
status_t status = fManager->ActivateEndpoint(this);
|
||||||
fActive = (status == B_OK);
|
fActive = (status == B_OK);
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
@@ -842,7 +822,7 @@ UdpEndpoint::_Deactivate()
|
|||||||
if (!fActive)
|
if (!fActive)
|
||||||
return B_ERROR;
|
return B_ERROR;
|
||||||
fActive = false;
|
fActive = false;
|
||||||
return fDomain->DeactivateEndpoint(this);
|
return fManager->DeactivateEndpoint(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user