Dragonfly 4.20
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_index=0) |
int | receive (void *buffer, int bytes, bool leave, int sock_index=0) |
int | close (int sock_index=0) |
int | closeAll () |
int | genDataEvents (int sock_index=0) const |
bool | isConnected (int sock_index=0) const |
int | isData (int sock_index=0) const |
int | isAnyData () const |
int | getSocket (int sock_index=0) const |
int | setDelay (int new_delay, int sock_index) |
int | sendDelayed () |
int | sendNow (const void *buffer, int bytes, int sock_index=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 |
std::vector< int > | m_sock |
int | m_max_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 sock index if new connection (note, 0 for first). Return -1 if no new connection, but no error. Return -2 if error.
int df::NetworkManager::close | ( | int | sock_index = 0 | ) |
Close network connection on indicated socket.
If successful, generate EventNetwork (close). Return 0 if success, else -1.
int df::NetworkManager::closeAll | ( | ) |
Close all network connections.
If successful, generate EventNetwork (close), for each. Return 0 if success, else negative number.
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 socket index if success, -1 if error.
int df::NetworkManager::genDataEvents | ( | int | sock_index = 0 | ) | const |
If complete network message on indicated socket, (first int is message size, in bytes) generate EventNetwork (data).
Return 1 if generated event, 0 if no message, -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 | sock_index = 0 | ) | const |
Return system socket from socket index, -1 if error.
int df::NetworkManager::isAnyData | ( | ) | const |
Check if data on any connected socket.
Return index of first socket with data. Return -1 if no socket has data.
bool df::NetworkManager::isConnected | ( | int | sock_index = 0 | ) | const |
Return true if socket is connected, else false.
int df::NetworkManager::isData | ( | int | sock_index = 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_index = 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_index = 0 |
||
) |
Send bytes from buffer to connected network socket.
Return 0 if success, -1 if error.
int df::NetworkManager::setDelay | ( | int | new_delay, |
int | sock_index | ||
) |
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.