FreeNOS
Data Structures | Public Types | Public Member Functions | Private Member Functions | Private Attributes
NetworkClient Class Reference

Networking Client implementation. More...

#include <NetworkClient.h>

Data Structures

struct  PacketInfo
 Describes a single packet. More...
 
struct  SocketInfo
 Socket information. More...
 

Public Types

enum  SocketAction { Connect, Listen, SendSingle, SendMultiple }
 Socket actions. More...
 
enum  SocketType { ARP, ICMP, TCP, UDP }
 Socket types. More...
 
enum  Result {
  Success, IOError, NotFound, NotSupported,
  TimedOut
}
 Result codes. More...
 
typedef struct NetworkClient::SocketInfo SocketInfo
 Socket information. More...
 

Public Member Functions

 NetworkClient (const char *networkDevice)
 Constructor. More...
 
virtual ~NetworkClient ()
 Destructor. More...
 
Result initialize ()
 Perform initialization. More...
 
Result createSocket (const SocketType type, int *socket)
 Create new socket. More...
 
Result connectSocket (const int sock, const IPV4::Address addr, const u16 port=0)
 Connect socket to address/port. More...
 
Result bindSocket (const int sock, const IPV4::Address addr=0, const u16 port=0)
 Bind socket to address/port. More...
 
Result waitSocket (const NetworkClient::SocketType type, const int sock, const Size msecTimeout)
 Wait until the given socket has data to receive. More...
 
Result close (const int sock)
 Close the socket. More...
 

Private Member Functions

Result writeSocketInfo (const int sock, const IPV4::Address addr, const u16 port, const SocketAction action)
 Set socket to new state. More...
 

Private Attributes

String m_deviceName
 Network device name. More...
 

Detailed Description

Networking Client implementation.

Maintains also the network state of each TCP/UDP socket, creates the packets and posts them to ethernet. Also receives packets and extracts socket info.

Because of the client and multiplexer separation the networking stack is very parallel. It can scale very well for multicore/manycore systems as each client may run on a different (possibly dedicated using pinning) core thus running multiple network stack instances on each core in parallel.

Definition at line 44 of file NetworkClient.h.

Member Typedef Documentation

◆ SocketInfo

Socket information.

This struct is written to a socket to put it in either connect or listen state.

Member Enumeration Documentation

◆ Result

Result codes.

Enumerator
Success 
IOError 
NotFound 
NotSupported 
TimedOut 

Definition at line 99 of file NetworkClient.h.

◆ SocketAction

Socket actions.

Enumerator
Connect 
Listen 
SendSingle 
SendMultiple 

Definition at line 51 of file NetworkClient.h.

◆ SocketType

Socket types.

Enumerator
ARP 
ICMP 
TCP 
UDP 

Definition at line 88 of file NetworkClient.h.

Constructor & Destructor Documentation

◆ NetworkClient()

NetworkClient::NetworkClient ( const char *  networkDevice)

Constructor.

Parameters
networkDeviceName of the network device to use

Definition at line 26 of file NetworkClient.cpp.

References m_deviceName.

◆ ~NetworkClient()

NetworkClient::~NetworkClient ( )
virtual

Destructor.

Definition at line 31 of file NetworkClient.cpp.

Member Function Documentation

◆ bindSocket()

NetworkClient::Result NetworkClient::bindSocket ( const int  sock,
const IPV4::Address  addr = 0,
const u16  port = 0 
)

Bind socket to address/port.

Parameters
sockSocket index
addrAddress of the address to bind to
portPort to bind to
Returns
Result code

Definition at line 123 of file NetworkClient.cpp.

References DEBUG, Listen, and writeSocketInfo().

Referenced by NetCat::initialize(), NetSend::initialize(), MpiProxy::initialize(), and DhcpClient::initialize().

◆ close()

NetworkClient::Result NetworkClient::close ( const int  sock)

Close the socket.

Parameters
sockNetwork socket to close
Returns
Result code

Definition at line 239 of file NetworkClient.cpp.

References FileSystemClient::closeFile(), ERROR, IOError, FileSystem::Success, and Success.

Referenced by NetPing::arpPing().

◆ connectSocket()

NetworkClient::Result NetworkClient::connectSocket ( const int  sock,
const IPV4::Address  addr,
const u16  port = 0 
)

Connect socket to address/port.

Parameters
sockSocket index
addrAddress of the host to connect to
portPort of the host to connect to (or ZERO to ignore)
Returns
Result code

Definition at line 115 of file NetworkClient.cpp.

References Connect, DEBUG, and writeSocketInfo().

Referenced by connect(), and NetPing::icmpPing().

◆ createSocket()

NetworkClient::Result NetworkClient::createSocket ( const SocketType  type,
int *  socket 
)

Create new socket.

Parameters
typeType of the socket to create
socketOutputs a pointer to NetworkSocket
Returns
Result code

Definition at line 80 of file NetworkClient.cpp.

References ARP, ERROR, ICMP, IOError, m_deviceName, NotFound, FileSystemClient::openFile(), FileSystem::Success, Success, type, and UDP.

Referenced by NetPing::arpPing(), NetPing::icmpPing(), NetCat::initialize(), NetSend::initialize(), MpiProxy::initialize(), and DhcpClient::initialize().

◆ initialize()

NetworkClient::Result NetworkClient::initialize ( )

◆ waitSocket()

NetworkClient::Result NetworkClient::waitSocket ( const NetworkClient::SocketType  type,
const int  sock,
const Size  msecTimeout 
)

Wait until the given socket has data to receive.

Parameters
typeType of socket to wait for
sockSocket index
msecTimeoutTimeout in milliseconds to wait or ZERO for infinite wait
Returns
Result code

Definition at line 131 of file NetworkClient.cpp.

References FileSystem::WaitSet::current, DEBUG, ERROR, FileDescriptor::getEntry(), FileDescriptor::Entry::inode, FileSystem::WaitSet::inode, StrictSingleton< FileDescriptor >::instance(), IOError, m_deviceName, NotFound, NotSupported, FileDescriptor::Entry::open, FileSystem::Readable, FileSystem::WaitSet::requested, FileSystem::Success, Success, FileSystem::TimedOut, TimedOut, type, UDP, and FileSystemClient::waitFile().

Referenced by MpiProxy::udpReceive(), and DhcpClient::udpReceive().

◆ writeSocketInfo()

NetworkClient::Result NetworkClient::writeSocketInfo ( const int  sock,
const IPV4::Address  addr,
const u16  port,
const SocketAction  action 
)
private

Field Documentation

◆ m_deviceName

String NetworkClient::m_deviceName
private

Network device name.

Definition at line 201 of file NetworkClient.h.

Referenced by createSocket(), initialize(), NetworkClient(), and waitSocket().


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