merged a bit more of functionality into DatagramSocket so we don't require a custom ReadData in the link protocol.
git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@20765 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
parent
2445c00e64
commit
74b0e85845
@ -45,7 +45,7 @@ template<typename LockingBase = BenaphoreLocking,
|
||||
class DatagramSocket {
|
||||
public:
|
||||
DatagramSocket(const char *name, net_socket *socket);
|
||||
~DatagramSocket();
|
||||
virtual ~DatagramSocket();
|
||||
|
||||
status_t InitCheck() const;
|
||||
|
||||
@ -58,13 +58,15 @@ public:
|
||||
status_t SocketEnqueue(net_buffer *buffer);
|
||||
status_t SocketDequeue(uint32 flags, net_buffer **_buffer);
|
||||
|
||||
size_t AvailableData() const;
|
||||
ssize_t AvailableData() const;
|
||||
|
||||
void WakeAll();
|
||||
|
||||
net_socket *Socket() const { return fSocket; }
|
||||
|
||||
protected:
|
||||
virtual status_t _SocketStatus() const;
|
||||
|
||||
status_t _Enqueue(net_buffer *buffer);
|
||||
status_t _SocketEnqueue(net_buffer *buffer);
|
||||
net_buffer *_Dequeue(bool clone);
|
||||
@ -198,11 +200,13 @@ DECL_DATAGRAM_SOCKET(inline status_t)::BlockingDequeue(bool clone,
|
||||
AutoLocker _(fLock);
|
||||
|
||||
bool waited = false;
|
||||
|
||||
while (fBuffers.IsEmpty()) {
|
||||
status_t status = _Wait(timeout);
|
||||
status_t status = _SocketStatus();
|
||||
if (status < B_OK)
|
||||
return status;
|
||||
|
||||
if ((status = _Wait(timeout)) < B_OK)
|
||||
return status;
|
||||
waited = true;
|
||||
}
|
||||
|
||||
@ -244,13 +248,23 @@ DECL_DATAGRAM_SOCKET(inline void)::_Clear()
|
||||
}
|
||||
|
||||
|
||||
DECL_DATAGRAM_SOCKET(inline size_t)::AvailableData() const
|
||||
DECL_DATAGRAM_SOCKET(inline ssize_t)::AvailableData() const
|
||||
{
|
||||
AutoLocker _(fLock);
|
||||
status_t status = _SocketStatus();
|
||||
if (status < B_OK)
|
||||
return status;
|
||||
|
||||
return fCurrentBytes;
|
||||
}
|
||||
|
||||
|
||||
DECL_DATAGRAM_SOCKET(inline status_t)::_SocketStatus() const
|
||||
{
|
||||
return B_OK;
|
||||
}
|
||||
|
||||
|
||||
DECL_DATAGRAM_SOCKET(inline status_t)::_Wait(bigtime_t timeout)
|
||||
{
|
||||
LockingBase::Unlock(&fLock);
|
||||
|
@ -45,10 +45,8 @@ public:
|
||||
status_t StartMonitoring(const char *);
|
||||
status_t StopMonitoring();
|
||||
|
||||
ssize_t ReadData(size_t numBytes, uint32 flags, net_buffer **_buffer);
|
||||
ssize_t ReadAvail() const;
|
||||
|
||||
private:
|
||||
status_t _SocketStatus() const;
|
||||
status_t _Unregister();
|
||||
|
||||
net_device_monitor fMonitor;
|
||||
@ -114,43 +112,14 @@ LinkProtocol::StopMonitoring()
|
||||
}
|
||||
|
||||
|
||||
ssize_t
|
||||
LinkProtocol::ReadData(size_t numBytes, uint32 flags, net_buffer **_buffer)
|
||||
status_t
|
||||
LinkProtocol::_SocketStatus() const
|
||||
{
|
||||
BenaphoreLocker _(fLock);
|
||||
|
||||
bool clone = flags & MSG_PEEK;
|
||||
bigtime_t timeout = _SocketTimeout(flags);
|
||||
|
||||
bool waited = false;
|
||||
while (_IsEmpty()) {
|
||||
if (fMonitoredDevice == NULL)
|
||||
return ENODEV;
|
||||
|
||||
status_t status = _Wait(timeout);
|
||||
if (status < B_OK)
|
||||
return status;
|
||||
waited = true;
|
||||
}
|
||||
|
||||
*_buffer = _Dequeue(clone);
|
||||
if (clone && waited)
|
||||
_NotifyOneReader(false);
|
||||
|
||||
return *_buffer ? B_OK : B_NO_MEMORY;
|
||||
}
|
||||
|
||||
|
||||
ssize_t
|
||||
LinkProtocol::ReadAvail() const
|
||||
{
|
||||
BenaphoreLocker _(fLock);
|
||||
if (fMonitoredDevice == NULL)
|
||||
return ENODEV;
|
||||
return fCurrentBytes;
|
||||
return LocalDatagramSocket::_SocketStatus();
|
||||
}
|
||||
|
||||
|
||||
status_t
|
||||
LinkProtocol::_Unregister()
|
||||
{
|
||||
@ -405,14 +374,14 @@ status_t
|
||||
link_read_data(net_protocol *protocol, size_t numBytes, uint32 flags,
|
||||
net_buffer **_buffer)
|
||||
{
|
||||
return ((LinkProtocol *)protocol)->ReadData(numBytes, flags, _buffer);
|
||||
return ((LinkProtocol *)protocol)->SocketDequeue(flags, _buffer);
|
||||
}
|
||||
|
||||
|
||||
ssize_t
|
||||
link_read_avail(net_protocol *protocol)
|
||||
{
|
||||
return ((LinkProtocol *)protocol)->ReadAvail();
|
||||
return ((LinkProtocol *)protocol)->AvailableData();
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user