FreeNOS
Public Member Functions | Private Attributes
UDPSocket Class Reference

User Datagram Protocol (UDP) socket. More...

#include <UDPSocket.h>

Inheritance diagram for UDPSocket:
NetworkSocket File

Public Member Functions

 UDPSocket (const u32 inode, UDP *udp, const ProcessID pid)
 Constructor. More...
 
virtual ~UDPSocket ()
 Destructor. More...
 
const u16 getPort () const
 Get associated local port. More...
 
virtual FileSystem::Result read (IOBuffer &buffer, Size &size, const Size offset)
 Receive UDP data. More...
 
virtual FileSystem::Result write (IOBuffer &buffer, Size &size, const Size offset)
 Send UDP data. More...
 
virtual bool canRead () const
 Check if the File has data ready for reading. More...
 
virtual FileSystem::Result process (const NetworkQueue::Packet *pkt)
 Process incoming network packet. More...
 
- Public Member Functions inherited from NetworkSocket
 NetworkSocket (const u32 inode, const Size packetSize, const ProcessID pid)
 Constructor. More...
 
virtual ~NetworkSocket ()
 Destructor. More...
 
ProcessID getProcessID () const
 Get owner ProcessID. More...
 
- Public Member Functions inherited from File
 File (const u32 inode, const FileSystem::FileType type=FileSystem::RegularFile, const UserID uid=ZERO, const GroupID gid=ZERO)
 Constructor function. More...
 
virtual ~File ()
 Destructor function. More...
 
u32 getInode () const
 Get inode number. More...
 
FileSystem::FileType getType () const
 Retrieve our filetype. More...
 
virtual FileSystem::Result status (FileSystem::FileStat &st)
 Retrieve file statistics. More...
 
virtual bool canWrite () const
 Check if the File can be written to. More...
 

Private Attributes

UDPm_udp
 UDP protocol instance. More...
 
u16 m_port
 Local port. More...
 
NetworkQueue m_queue
 Incoming packet queue. More...
 

Additional Inherited Members

- Protected Attributes inherited from NetworkSocket
const ProcessID m_pid
 ProcessID which owns this socket. More...
 
NetworkQueue m_receive
 Receive queue. More...
 
NetworkQueue m_transmit
 Transmit queue. More...
 
NetworkClient::SocketInfo m_info
 Socket connection. More...
 
- Protected Attributes inherited from File
const u32 m_inode
 Inode number. More...
 
const FileSystem::FileType m_type
 Type of this file. More...
 
UserID m_uid
 Owner of the file. More...
 
GroupID m_gid
 Group of the file. More...
 
FileSystem::FileModes m_access
 Access permissions. More...
 
Size m_size
 Size of the file, in bytes. More...
 

Detailed Description

User Datagram Protocol (UDP) socket.

UDP sockets accept payloads to send when writing and read payloads when receiving payloads.

Definition at line 42 of file UDPSocket.h.

Constructor & Destructor Documentation

◆ UDPSocket()

UDPSocket::UDPSocket ( const u32  inode,
UDP udp,
const ProcessID  pid 
)

Constructor.

Definition at line 25 of file UDPSocket.cpp.

◆ ~UDPSocket()

UDPSocket::~UDPSocket ( )
virtual

Destructor.

Definition at line 35 of file UDPSocket.cpp.

Member Function Documentation

◆ canRead()

bool UDPSocket::canRead ( ) const
virtual

Check if the File has data ready for reading.

When this function returns true, it can be read without blocking.

Returns
Boolean

Reimplemented from File.

Definition at line 154 of file UDPSocket.cpp.

References NetworkQueue::hasData(), and m_queue.

◆ getPort()

const u16 UDPSocket::getPort ( ) const

Get associated local port.

Returns
Local port

Definition at line 39 of file UDPSocket.cpp.

References m_port.

◆ process()

FileSystem::Result UDPSocket::process ( const NetworkQueue::Packet pkt)
virtual

Process incoming network packet.

Parameters
pktIncoming packet pointer
Returns
Result code

Implements NetworkSocket.

Definition at line 159 of file UDPSocket.cpp.

References MemoryBlock::copy(), NetworkQueue::Packet::data, DEBUG, ERROR, NetworkQueue::get(), FileSystem::IOError, m_queue, NetworkQueue::push(), NetworkQueue::Packet::size, and FileSystem::Success.

◆ read()

FileSystem::Result UDPSocket::read ( IOBuffer buffer,
Size size,
const Size  offset 
)
virtual

Receive UDP data.

Parameters
bufferInput/Output buffer to output bytes to.
sizeMaximum number of bytes to read on input. On output, the actual number of bytes read.
offsetOffset inside the file to start reading.
Returns
Result code

Reimplemented from File.

Definition at line 44 of file UDPSocket.cpp.

References NetworkClient::SocketInfo::address, NetworkQueue::Packet::data, DEBUG, m_queue, NetworkQueue::pop(), NetworkClient::SocketInfo::port, readBe16(), readBe32(), NetworkQueue::release(), FileSystem::RetryAgain, NetworkQueue::Packet::size, IPV4::Header::source, UDP::Header::sourcePort, FileSystem::Success, and IOBuffer::write().

◆ write()

FileSystem::Result UDPSocket::write ( IOBuffer buffer,
Size size,
const Size  offset 
)
virtual

Field Documentation

◆ m_port

u16 UDPSocket::m_port
private

Local port.

Definition at line 117 of file UDPSocket.h.

Referenced by getPort().

◆ m_queue

NetworkQueue UDPSocket::m_queue
private

Incoming packet queue.

Definition at line 120 of file UDPSocket.h.

Referenced by canRead(), process(), and read().

◆ m_udp

UDP* UDPSocket::m_udp
private

UDP protocol instance.

Definition at line 114 of file UDPSocket.h.

Referenced by write().


The documentation for this class was generated from the following files: