FreeNOS
|
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... | |
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.
typedef struct NetworkClient::SocketInfo NetworkClient::SocketInfo |
Socket information.
This struct is written to a socket to put it in either connect or listen state.
Result codes.
Enumerator | |
---|---|
Success | |
IOError | |
NotFound | |
NotSupported | |
TimedOut |
Definition at line 99 of file NetworkClient.h.
Socket actions.
Enumerator | |
---|---|
Connect | |
Listen | |
SendSingle | |
SendMultiple |
Definition at line 51 of file NetworkClient.h.
NetworkClient::NetworkClient | ( | const char * | networkDevice | ) |
Constructor.
networkDevice | Name of the network device to use |
Definition at line 26 of file NetworkClient.cpp.
References m_deviceName.
|
virtual |
Destructor.
Definition at line 31 of file NetworkClient.cpp.
NetworkClient::Result NetworkClient::bindSocket | ( | const int | sock, |
const IPV4::Address | addr = 0 , |
||
const u16 | port = 0 |
||
) |
Bind socket to address/port.
sock | Socket index |
addr | Address of the address to bind to |
port | Port to bind to |
Definition at line 123 of file NetworkClient.cpp.
References DEBUG, Listen, and writeSocketInfo().
Referenced by NetCat::initialize(), NetSend::initialize(), MpiProxy::initialize(), and DhcpClient::initialize().
NetworkClient::Result NetworkClient::close | ( | const int | sock | ) |
Close the socket.
sock | Network socket to close |
Definition at line 239 of file NetworkClient.cpp.
References FileSystemClient::closeFile(), ERROR, IOError, FileSystem::Success, and Success.
Referenced by NetPing::arpPing().
NetworkClient::Result NetworkClient::connectSocket | ( | const int | sock, |
const IPV4::Address | addr, | ||
const u16 | port = 0 |
||
) |
Connect socket to address/port.
sock | Socket index |
addr | Address of the host to connect to |
port | Port of the host to connect to (or ZERO to ignore) |
Definition at line 115 of file NetworkClient.cpp.
References Connect, DEBUG, and writeSocketInfo().
Referenced by connect(), and NetPing::icmpPing().
NetworkClient::Result NetworkClient::createSocket | ( | const SocketType | type, |
int * | socket | ||
) |
Create new socket.
type | Type of the socket to create |
socket | Outputs a pointer to NetworkSocket |
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().
NetworkClient::Result NetworkClient::initialize | ( | ) |
Perform initialization.
Definition at line 35 of file NetworkClient.cpp.
References String::compareTo(), ERROR, FileSystemClient::getFileSystems(), IOError, String::length(), m_deviceName, FileSystemMount::path, and Success.
Referenced by NetPing::arpPing(), connect(), NetPing::icmpPing(), NetCat::initialize(), NetSend::initialize(), MpiProxy::initialize(), and DhcpClient::initialize().
NetworkClient::Result NetworkClient::waitSocket | ( | const NetworkClient::SocketType | type, |
const int | sock, | ||
const Size | msecTimeout | ||
) |
Wait until the given socket has data to receive.
type | Type of socket to wait for |
sock | Socket index |
msecTimeout | Timeout in milliseconds to wait or ZERO for infinite wait |
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().
|
private |
Set socket to new state.
Definition at line 180 of file NetworkClient.cpp.
References NetworkClient::SocketInfo::action, NetworkClient::SocketInfo::address, DEBUG, ERROR, FileDescriptor::getEntry(), FileDescriptor::Entry::inode, FileSystem::FileStat::inode, StrictSingleton< FileDescriptor >::instance(), IOError, NotFound, FileDescriptor::Entry::open, FileDescriptor::Entry::pid, FileSystem::FileStat::pid, NetworkClient::SocketInfo::port, FileSystemClient::readFile(), FileSystemClient::statFile(), FileSystem::Success, Success, and FileSystemClient::writeFile().
Referenced by bindSocket(), and connectSocket().
|
private |
Network device name.
Definition at line 201 of file NetworkClient.h.
Referenced by createSocket(), initialize(), NetworkClient(), and waitSocket().