TrinityCore
|
Abstraction of network (socket) functionality. More...
#include <NetworkDevice.h>
Classes | |
class | EthernetAdapter |
Description of an ethernet or wireless ethernet adapter. More... | |
Public Member Functions | |
~NetworkDevice () | |
const Array< EthernetAdapter > & | adapterArray () const |
const Array< uint32 > & | broadcastAddressArray () const |
void | describeSystem (TextOutput &t) |
void | describeSystem (std::string &s) |
std::string | localHostName () const |
void | localHostAddresses (Array< NetAddress > &array) const |
Static Public Member Functions | |
static std::string | formatIP (uint32 ip) |
static std::string | formatMAC (const uint8 mac[6]) |
static NetworkDevice * | instance () |
static void | cleanup () |
Private Member Functions | |
void | closesocket (SOCKET &sock) const |
bool | bind (SOCKET sock, const NetAddress &addr) const |
NetworkDevice () | |
bool | init () |
void | _cleanup () |
void | addAdapter (const EthernetAdapter &a) |
Private Attributes | |
bool | initialized |
Array< EthernetAdapter > | m_adapterArray |
Array< uint32 > | m_broadcastAddresses |
Static Private Attributes | |
static NetworkDevice * | s_instance = NULL |
Friends | |
class | Conduit |
class | LightweightConduit |
class | ReliableConduit |
class | NetListener |
Abstraction of network (socket) functionality.
An abstraction over sockets that provides a message-based network infrastructure optimized for sending many small (~500 bytes) messages. All functions always return immediately.
Create only one NetworkDevice per process (a WinSock restriction).
NetworkDevice is technically not thread safe. However, as long as you use different conduits on different threads (or lock conduits before sending), you will encounter no problems sharing the single NetworkDevice across multiple threads. That is, do not invoke the same Conduit's send or receive method on two threads at once.
This assumes that the underlying WinSock/BSD sockets implementation is thread safe. That is not guaranteed, but in practice seems to always be true (see http://tangentsoft.net/wskfaq/intermediate.html#threadsafety)
IP networks use "network byte order" (big-endian) for communicating integers. "Host byte order" is the endian-ness of the local machine (typically little-endian; see System::endian). The C functions htonl() and ntohl() convert 32-bit values between these formats. G3D only ever exposes host byte order, so programmers rarely need to be aware of the distinction.
|
private |
|
private |
|
inline |
Returns the available ethernet adapters for the current machine that are online. Does not include the loopback adapter for localhost.
|
private |
Called from init to update m_adapterArray and m_broadcastAddresses.
|
private |
Utility method. Returns true on success.
Returns the (unique) IP addresses for UDP broadcasting extracted from adapterArray(). All are in host byte order.
|
static |
Shuts down the network device (destroying the global instance).
|
private |
Utility method.
void G3D::NetworkDevice::describeSystem | ( | TextOutput & | t | ) |
Prints a human-readable description of this machine to the text output stream.
void G3D::NetworkDevice::describeSystem | ( | std::string & | s | ) |
|
static |
Prints an IP address to a string.
ip | In host byte order. |
Prints a MAC address to a string.
|
private |
|
static |
Returns NULL if there was a problem initializing the network.
void G3D::NetworkDevice::localHostAddresses | ( | Array< NetAddress > & | array | ) | const |
There is often more than one address for the local host. This returns all of them.
std::string G3D::NetworkDevice::localHostName | ( | ) | const |
Returns the name (or one of the names) of this computer
|
friend |
|
friend |
|
friend |
|
friend |
|
private |
|
private |
Broadcast addresses available on this machine, extracted from m_adapterArray.
|
staticprivate |
The global instance