Dragonfly 4.21
A text-based game engine
|
Public Member Functions | |
int | startUp () override |
void | shutDown () override |
bool | isValid (std::string event_type) const override |
int | setServer (bool server=true, std::string port=DRAGONFLY_PORT) |
bool | isServer () const |
int | accept () |
int | connect (std::string host, std::string port=DRAGONFLY_PORT) |
void | setMaxConnections (int new_max_sock) |
int | getMaxConnections () const |
int | getNumConnections () const |
int | send (const void *buffer, int bytes, int sock=-1) |
int | receive (void *buffer, int bytes, bool leave, int sock=0) |
int | close (int sock=-1) |
int | getSocket (int index=0) const |
bool | isConnected (int sock=-1) const |
int | isData (int sock=0) const |
int | setDelay (int new_delay, int sock=0) |
int | sendDelayed () |
int | sendNow (const void *buffer, int bytes, int sock=0) |
Public Member Functions inherited from df::Manager | |
std::string | getType () const |
virtual int | startUp () |
virtual void | shutDown () |
bool | isStarted () const |
int | onEvent (const Event *p_event) const |
int | registerInterest (Object *p_o, std::string event_type) |
int | unregisterInterest (Object *p_o, std::string event_type) |
Static Public Member Functions | |
static NetworkManager & | getInstance () |
Private Member Functions | |
NetworkManager (NetworkManager const &) | |
void | operator= (NetworkManager const &) |
Private Attributes | |
int | m_accept_sock |
int | m_max_sock |
std::vector< int > | m_sock |
std::vector< int > | m_delay |
std::vector< delayQueue > | m_delay_q |
Additional Inherited Members | |
Protected Member Functions inherited from df::Manager | |
void | setType (std::string new_type) |
int df::NetworkManager::accept | ( | ) |
Accept network connection.
If successful, generate EventNetwork (accept). Return socket if new connection. Return -1 if no new connection, but no error. Return -2 if error.
int df::NetworkManager::close | ( | int | sock = -1 | ) |
Close network connection on indicated socket (-1 for all).
If successful, generate EventNetwork (close). Return 0 if success, else -1.
int df::NetworkManager::connect | ( | std::string | host, |
std::string | port = DRAGONFLY_PORT |
||
) |
Make network connection to host at port.
If successful, generate EventNetwork (connect). Return return socket if success, -1 if error.
|
static |
Get the one and only instance of the NetworkManager.
int df::NetworkManager::getMaxConnections | ( | ) | const |
Get maximum number of connections.
int df::NetworkManager::getNumConnections | ( | ) | const |
Get number of connected sockets.
int df::NetworkManager::getSocket | ( | int | index = 0 | ) | const |
Return socket at indicated index. -1 if out of range.
bool df::NetworkManager::isConnected | ( | int | sock = -1 | ) | const |
Check if socket is connected.
Default (-1) checks if any socket is connected. Return true if (any) socket is connected, else false.
int df::NetworkManager::isData | ( | int | sock = 0 | ) | const |
Check if network data on indicated socket.
Return amount of data (0 if no data), -1 if not connected or error.
bool df::NetworkManager::isServer | ( | ) | const |
Return true if successufully setup as server, else false.
|
overridevirtual |
Return true only for network events.
Return false for other engine events.
Reimplemented from df::Manager.
int df::NetworkManager::receive | ( | void * | buffer, |
int | bytes, | ||
bool | leave, | ||
int | sock = 0 |
||
) |
Receive from connected network socket (no more than bytes).
If leave is true, don't remove data from socket (peek). Return number of bytes received, -1 if error.
int df::NetworkManager::send | ( | const void * | buffer, |
int | bytes, | ||
int | sock = -1 |
||
) |
Send bytes from buffer to connected network socket (-1 for all).
Return 0 if success, -1 if error.
int df::NetworkManager::setDelay | ( | int | new_delay, |
int | sock = 0 |
||
) |
Set delay amount added to outgoing messages (in ticks).
Return 0 if ok, else -1.
void df::NetworkManager::setMaxConnections | ( | int | new_max_sock | ) |
Set maximum number of connections.
int df::NetworkManager::setServer | ( | bool | server = true , |
std::string | port = DRAGONFLY_PORT |
||
) |
Setup NetworkManager as server (if false, reset to client).
Return 0 if ok, else -1.
|
overridevirtual |
Shut down NetworkManager.
Reimplemented from df::Manager.
|
overridevirtual |
Start up NetworkManager.
Reimplemented from df::Manager.