#include <NQclass.h>
Public Member Functions | |
CNetworkQueue () | |
constructor of the NetworkQueue object | |
~CNetworkQueue () | |
destructor of the NetworkQueue object | |
CNQMessage * | createMsg () |
create a valid CNQMessage object reference | |
bool | freeMsg (CNQMessage *ref) |
free a CNQMessage reference which has previously been created or returned this CNQMessage instance might be returned at CNetworkQueue::createMsg, CNetworkQueue::recvMsg() and CNetworkQueue::sendRecvMsg() | |
bool | addPeer (UINT32 ip_hostorder, UINT32 port_hostorder) |
Add a new NetworkQueue endpoint to the accept list. | |
bool | removePeer (UINT32 ip_hostorder, UINT32 port_hostorder) |
Remove a NetworkQueue endpoint from the accept list. | |
bool | create (const ONECHAR *ip_remote_peer, UINT16 portnumber_remote, UINT16 portnumber_local) |
create and connect the Networkqueue to a remote peer | |
bool | close () |
closes the Networkqueue and deinitializes peer connection | |
UINT32 | getLastError () |
get the last error code | |
bool | getLastErrorString (ONECHAR *buffer, UINT32 buflength) |
Get the error string of the last occured error code. | |
void | SendProcessTask () |
public only by software design reason | |
void | ReceiveProcessTask () |
public only by software design reason | |
send and receive API | |
bool | sendMsgTo (CNQMessage *msg, UINT32 ip_hostorder, UINT16 port_hostorder) |
Send a message from local Networkqueue immediately to remote peer. | |
bool | sendMsgTo (CNQMessage *msg, UINT32 ip_hostorder, UINT16 port_hostorder, const NQ_TIMEVAL &timeout) |
Send a message from Networkqueue with timeout. | |
bool | recvMsg (CNQMessage **newmsg) |
Receive/wait for next message from Networkqueue. | |
bool | recvMsg (CNQMessage **newmsg, const NQ_TIMEVAL &timeout) |
Receive next message from Networkqueue and give wait timeout. | |
bool | sendRecvMsg (CNQMessage **response, CNQMessage *request, UINT32 ip_hostorder, UINT16 port_hostorder, const NQ_TIMEVAL &timeout) |
Send and receive a message from Networkqueue with timeout (rpc-like call). | |
bool | getStatistics (NQ_STATISTICS &stats) |
get statistical information about the NetworkQueue | |
Private Member Functions | |
bool | sendMsgToInternal (UINT32 ip_hostorder, UINT16 port_hostorder, CNQMessage *msg, HANDLE recv_notify_sem) |
Internal message validation check. | |
CNQMessage * | obtainReference () |
bool | incrementReferenceCount (CNQMessage *ref) |
bool | putbackReference (CNQMessage *ref) |
Private Attributes | |
CNQMessagePool | bufs |
NQ_STATISTICS | m_stats |
socktype | m_socket |
UINT32 | m_iLastError |
INT32 | m_iLastSystemError |
HANDLE | m_sendSemaphore |
HANDLE | m_receiveSemaphore |
CNQPacketQueue | m_SendPacketQueue |
CNQPacketQueue | m_ReceivePacketQueue |
CNQPacketQueue | m_AckPacketWaitingQueue |
CNQPacketQueue | m_ReceiveResponseSemaphorePacketQueue |
CNQResponseWaitQueue | m_ResponseWaitQueue |
CNQPeerList | m_PeerList |
bool | m_bSuccessfulInitialized |
HANDLE | m_hSendThread |
HANDLE | m_hReceiveThread |
volatile bool | m_bShutdownSendThread |
volatile bool | m_bSendThreadRunning |
volatile bool | m_bShutdownReceiveThread |
volatile bool | m_bReceiveThreadRunning |
UINT16 | m_iNextRequestId |
Friends | |
class | CNQMessage |
class | CNQMessageBuffers |
creates a Networkqueue endpoint for communication with a nother Networkqueue endpoint.
Definition at line 8 of file NQclass.h.
CNetworkQueue::CNetworkQueue | ( | ) |
constructor of the NetworkQueue object
Definition at line 56 of file NQclass.cpp.
CNetworkQueue::~CNetworkQueue | ( | ) |
destructor of the NetworkQueue object
Definition at line 73 of file NQclass.cpp.
CNQMessage * CNetworkQueue::createMsg | ( | ) |
create a valid CNQMessage object reference
The CNQMessage object reference must be freed by CNetworkQueue::freeMsg. You must use only this function, to create valid CNQMessage objects, because CNQMessage object references are handled internaly in a dedicated memory area, accessable by the asynchronous thread operations.
NULL
Definition at line 94 of file NQclass.cpp.
Referenced by SimulateLocalPeer().
bool CNetworkQueue::freeMsg | ( | CNQMessage * | ref | ) |
free a CNQMessage reference which has previously been created or returned this CNQMessage instance might be returned at CNetworkQueue::createMsg, CNetworkQueue::recvMsg() and CNetworkQueue::sendRecvMsg()
Definition at line 99 of file NQclass.cpp.
Referenced by SimulateLocalPeer(), and SimulateRemotePeer().
Add a new NetworkQueue endpoint to the accept list.
add a new NetworkQueue endpoint to the accept list.
ip_hostorder | The IP address (in host byte order) | |
port_hostorder | The Port number (in host byte order) |
ip_hostorder | ip address of the peer in host byte order | |
port_hostorder | port of the peer in host byte order |
true | peer is added or was already in list | |
false | peer was not added to list (reason: list full) OR mutex locking error (synchronized access); in debug mode an assert is thrown there |
Definition at line 144 of file NQclass.cpp.
Referenced by SimulateRemotePeer().
Remove a NetworkQueue endpoint from the accept list.
remove a NetworkQueue endpoint from the accept list.
ip_hostorder | The IP address (in host byte order) | |
port_hostorder | The Port number (in host byte order) |
ip_hostorder | ip address of the peer in host byte order | |
port_hostorder | port of the peer in host byte order |
true | peer was removed from the list | |
false | peer was not removed from the list (reason: peer is not in list) OR mutex locking error (synchronized access); in debug mode an assert is thrown there |
Definition at line 169 of file NQclass.cpp.
Referenced by SimulateRemotePeer().
bool CNetworkQueue::create | ( | const ONECHAR * | ip_remote_peer, | |
UINT16 | portnumber_remote, | |||
UINT16 | portnumber_local | |||
) |
create and connect the Networkqueue to a remote peer
create and connect the Networkqueue to a remote peer
ip_remote_peer | The remote peer IP address as a string | |
portnumber_remote | The remote peer port number to send to (in host byte order) | |
portnumber_local | The local port to send from (in host byte order) |
ip_remote_peer | string dotted IP address of the remote peer (e.g. "192.168.1.11") RegisterPeer will be done internally NULL, "": no peer by default, peers have to be added by hand by calling bool RegisterPeer(ip, port) | |
portnumber_remote | UDP port number of the remote, will be ignored in case of ip_remote_peer==NULL || "" | |
portnumber_local | UDP port number of the local peer side |
true | successfully initialized local queue part, communication may take place now | |
false | something happened during initialization, extended error information can be obtained by CNetworkQueue::getLastError() |
Definition at line 213 of file NQclass.cpp.
Referenced by SimulateLocalPeer(), and SimulateRemotePeer().
bool CNetworkQueue::close | ( | ) |
closes the Networkqueue and deinitializes peer connection
The method is mandatory to call before exiting the user application. Internal structures (socket, queues, task/threads, semaphores) are shut down, closed and freed.
Preconditions: This
method assumes that there will be no more sending/receiving, all loops, events, functions which might be triggered by the send and receive semaphores must have been ended / cancelled.
true | successfully deinitialized local queue part | |
false | something happened during deinitialization, extended error information can be obtained by CNetworkQueue::getLastError() |
Definition at line 371 of file NQclass.cpp.
Referenced by SimulateLocalPeer(), SimulateRemotePeer(), and ~CNetworkQueue().
bool CNetworkQueue::sendMsgTo | ( | CNQMessage * | msg, | |
UINT32 | ip_hostorder, | |||
UINT16 | port_hostorder | |||
) |
Send a message from local Networkqueue immediately to remote peer.
Definition at line 482 of file NQclass.cpp.
Referenced by SimulateLocalPeer(), and SimulateRemotePeer().
bool CNetworkQueue::sendMsgTo | ( | CNQMessage * | msg, | |
UINT32 | ip_hostorder, | |||
UINT16 | port_hostorder, | |||
const NQ_TIMEVAL & | timeout | |||
) |
Send a message from Networkqueue with timeout.
Send a message from Networkqueue.
msg | reference to the CNQMessage object to send | |
ip_hostorder | the destination peer IP address (in host byte order) | |
port_hostorder | the destination peer port address (in host byte order) | |
timeout | timeout to wait max. for the next message |
The
message is checked for validity and after that injected in the send queue. The send thread/task is notified by the help of a semaphore that a new message is waiting to be send out. On
successful reception inside user part at the remote peer an 'ACK' packet is send there. This function will return true in case the sent ack packet was received at local peer.
msg | pointer reference to an already set up CNQMessage buffer | |
ip_hostorder | ip address of remote peer to send packet to | |
port_hostorder | port of remote peer to send packet to | |
timeout | timeout to wait until ack packet must have been arrived |
true | message was successfully received at remote side! (and ack packet successfully travelled back to local peer) | |
false | timeout or something bad happened On false return, extended error information can be obtained by getLastError() and getLastErrorString(). |
Definition at line 531 of file NQclass.cpp.
bool CNetworkQueue::recvMsg | ( | CNQMessage ** | newmsg | ) |
Receive/wait for next message from Networkqueue.
newmsg | pointer variable to get the CNQMessage reference of the next received message |
In
case of true return, a new message was waiting in the receive queue and was put to newmsg reference pointer. In case of false return, there was no new message waiting or an error happened during extraction. In
case of true return and a CNQMessage that wants to be acknowledged, an ack message is sent back to remote peer internally and automatically.
newmsg | A pointer reference to a (CNQMessage *) variable, which can be uninitialized. The pointer reference will be overwritten! |
true | message was successfully extracted and put into the (CNQMessage *) reference. | |
false | something happened, no message was put into the input/output parameter. Most probably simply no new message was waiting to be received. On false return, extended error information can be obtained by getLastError() and getLastErrorString(). |
true
, the user must not forget to put the borrowed CNQMessage buffer, that was given to the user in newmsg, back to the CNQMessage buffer pool via freeMsg() when the buffer is not accessed/used any more.Definition at line 735 of file NQclass.cpp.
Referenced by SimulateLocalPeer(), and SimulateRemotePeer().
bool CNetworkQueue::recvMsg | ( | CNQMessage ** | newmsg, | |
const NQ_TIMEVAL & | timeout | |||
) |
Receive next message from Networkqueue and give wait timeout.
Receive/wait for next message from Networkqueue.
newmsg | pointer variable to get the CNQMessage reference of the next received message | |
timeout | timeout to wait max. for the next message |
In
case of true return, a new message was waiting in the receive queue and was put to newmsg reference pointer inside the timeout period. In case of false return, there was no new message waiting until the timeout elapsed or an error happened during extraction out of the receive queue. In
case of true return and a CNQMessage that wants to be acknowledged, an ack message is sent back to remote peer internally and automatically.
newmsg | A pointer reference to a (CNQMessage *) variable, which can be uninitialized. The pointer reference will be overwritten! | |
timeout | platform-independent version of a usual "timeval" structure passing a timeout of 0 (0 seconds, 0 microseconds) means INFINITE timeout |
true | message was successfully extracted and put into the (CNQMessage *) reference. | |
false | Some error occured or no message was put into the input/output parameter. Most probably simply no new message was waiting to be received during the timeout period. On false return, extended error information can be obtained by getLastError() and getLastErrorString(). |
true
return, the user must not forget to put the borrowed CNQMessage buffer, that was given to the user in newmsg, back to the CNQMessage buffer pool via freeMsg() when the buffer is not accessed/used any more.Definition at line 827 of file NQclass.cpp.
bool CNetworkQueue::sendRecvMsg | ( | CNQMessage ** | response, | |
CNQMessage * | request, | |||
UINT32 | ip_hostorder, | |||
UINT16 | port_hostorder, | |||
const NQ_TIMEVAL & | timeout | |||
) |
Send and receive a message from Networkqueue with timeout (rpc-like call).
response | pointer variable to get the response CNQMessage reference | |
request | reference reference to the CNQMessage object to send for the request | |
ip_hostorder | the destination peer IP address (in host byte order) | |
port_hostorder | the destination peer port address (in host byte order) | |
timeout | timeout to wait max. for the next message |
A
request is send out to the remote peer and the method blocks, until either an appropriate answer arrives or a timeout period expires. In
case of true return, a proper response was waiting in the receive queue and was put to response reference pointer inside the timeout period. In case of false return, there was no appropriate answer message waiting until the timeout elapsed. It might be also an error happened during sending / receiving.
response | A pointer reference to a (CNQMessage *) variable, which can be uninitialized. The pointer reference will be overwritten! | |
request | A pointer reference to a CNQMessage that contains a request. The request CNQMessage will be altered during transaction (adding/altering of semaphore). | |
ip_hostorder | IP address where to send the packet to in host byte order | |
port_hostorder | UDP port where to send the packet to (at ip) in host byte order | |
timeout | platform-independent version of a usual "timeval" timeout structure passing a timeout of 0 (0 seconds, 0 microseconds) means INFINITE timeout |
true | message was successfully extracted and put into the (CNQMessage *) reference. | |
false | something happened, no message was put into the input/output parameter. Most probably simply no new message was waiting to be received during the timeout period. On false return, extended error information can be obtained by getLastError() and getLastErrorString(). |
Definition at line 932 of file NQclass.cpp.
Referenced by SimulateLocalPeer().
bool CNetworkQueue::getStatistics | ( | NQ_STATISTICS & | stats | ) |
get statistical information about the NetworkQueue
stats | pointer to a STATISTICS structure to retrieve the stastical information |
stats | pointer to a STATISTICS structure to retrieve the stastical information |
true | statistical information was retrieved successfully | |
false | error occured, extended error information can be obtained by getLastError() and getLastErrorString(). |
Definition at line 1039 of file NQclass.cpp.
Referenced by SimulateLocalPeer(), and SimulateRemotePeer().
UINT32 CNetworkQueue::getLastError | ( | ) |
get the last error code
This public method can be used to get to know the last extended error code that happened inside.
Definition at line 1053 of file NQclass.cpp.
Referenced by SimulateLocalPeer(), and SimulateRemotePeer().
Get the error string of the last occured error code.
This function is a translator. It converts the abstract error code into a descriptive string that is aimed to give human readable output what error happened (and maybe why). The last error that happened (as returned by getLastError()) is used for translation.
buffer | pointer to a ONECHAR array to hold the resulting string | |
buflength | number of characters in the ONECHAR array buffer |
true | successfully translated, encoded and returned | |
false | error happened during translation or encoding (i.e. bad lasterror, buffer too small) |
In case the translation failed, the returned string will be "No error or unknown error?!".
Definition at line 1075 of file NQclass.cpp.
void CNetworkQueue::SendProcessTask | ( | ) |
public only by software design reason
This member function is called internally by the sender thread/task and performs NetworkQueue send logic:
Definition at line 1160 of file NQclass.cpp.
void CNetworkQueue::ReceiveProcessTask | ( | ) |
public only by software design reason
This member function is called internally by the receiver thread/task and performs NetworkQueue receive logic.
Definition at line 1308 of file NQclass.cpp.
bool CNetworkQueue::sendMsgToInternal | ( | UINT32 | ip_hostorder, | |
UINT16 | port_hostorder, | |||
CNQMessage * | msg, | |||
HANDLE | recv_notify_sem | |||
) | [private] |
Internal message validation check.
The message is checked for validity and after that injected in the send queue. The send thread/task is notified by the help of a semaphore that a new message is waiting to be send out.
msg | pointer reference to an already set up CNQMessage buffer | |
ip_hostorder | ip address of remote peer to send packet to | |
port_hostorder | port of remote peer to send packet to | |
recv_notify_sem | semaphore to notify in case an "answer" message is received to that packet this parameter should be NO_SEMAPHORE in any other case |
true | message was successfully injected and marked for sending (does not mean that is was successfully send out!) | |
false | something bad happened, message will not be sent out at all On false return, extended error information can be obtained by getLastError() and getLastErrorString(). |
Definition at line 659 of file NQclass.cpp.
Referenced by recvMsg(), sendMsgTo(), and sendRecvMsg().
CNQMessage * CNetworkQueue::obtainReference | ( | ) | [private] |
Definition at line 106 of file NQclass.cpp.
Referenced by createMsg(), ReceiveProcessTask(), and recvMsg().
bool CNetworkQueue::incrementReferenceCount | ( | CNQMessage * | ref | ) | [private] |
Definition at line 113 of file NQclass.cpp.
Referenced by ReceiveProcessTask(), sendMsgTo(), and sendMsgToInternal().
bool CNetworkQueue::putbackReference | ( | CNQMessage * | ref | ) | [private] |
Definition at line 121 of file NQclass.cpp.
Referenced by close(), freeMsg(), ReceiveProcessTask(), recvMsg(), sendMsgTo(), sendMsgToInternal(), and SendProcessTask().
friend class CNQMessage [friend] |
CNQMessagePool CNetworkQueue::bufs [private] |
Definition at line 147 of file NQclass.h.
Referenced by close(), create(), incrementReferenceCount(), obtainReference(), and putbackReference().
NQ_STATISTICS CNetworkQueue::m_stats [private] |
Definition at line 150 of file NQclass.h.
Referenced by create(), getStatistics(), ReceiveProcessTask(), sendMsgTo(), sendMsgToInternal(), SendProcessTask(), and sendRecvMsg().
socktype CNetworkQueue::m_socket [private] |
Definition at line 152 of file NQclass.h.
Referenced by close(), CNetworkQueue(), create(), ReceiveProcessTask(), and SendProcessTask().
UINT32 CNetworkQueue::m_iLastError [private] |
Definition at line 153 of file NQclass.h.
Referenced by close(), CNetworkQueue(), create(), getLastError(), getLastErrorString(), recvMsg(), sendMsgTo(), sendMsgToInternal(), and sendRecvMsg().
INT32 CNetworkQueue::m_iLastSystemError [private] |
Definition at line 154 of file NQclass.h.
Referenced by close(), CNetworkQueue(), create(), and getLastErrorString().
HANDLE CNetworkQueue::m_sendSemaphore [private] |
Definition at line 157 of file NQclass.h.
Referenced by close(), create(), sendMsgTo(), sendMsgToInternal(), and SendProcessTask().
HANDLE CNetworkQueue::m_receiveSemaphore [private] |
Definition at line 161 of file NQclass.h.
Referenced by close(), CNetworkQueue(), sendMsgTo(), sendMsgToInternal(), and SendProcessTask().
Definition at line 162 of file NQclass.h.
Referenced by close(), CNetworkQueue(), ReceiveProcessTask(), and recvMsg().
Definition at line 165 of file NQclass.h.
Referenced by CNetworkQueue(), ReceiveProcessTask(), and sendMsgTo().
Definition at line 167 of file NQclass.h.
Referenced by close(), ReceiveProcessTask(), and sendRecvMsg().
CNQPeerList CNetworkQueue::m_PeerList [private] |
Definition at line 171 of file NQclass.h.
Referenced by addPeer(), create(), ReceiveProcessTask(), removePeer(), sendMsgTo(), sendMsgToInternal(), and SendProcessTask().
bool CNetworkQueue::m_bSuccessfulInitialized [private] |
Definition at line 173 of file NQclass.h.
Referenced by addPeer(), close(), CNetworkQueue(), create(), incrementReferenceCount(), obtainReference(), putbackReference(), recvMsg(), removePeer(), sendMsgTo(), sendMsgToInternal(), sendRecvMsg(), and ~CNetworkQueue().
HANDLE CNetworkQueue::m_hSendThread [private] |
HANDLE CNetworkQueue::m_hReceiveThread [private] |
volatile bool CNetworkQueue::m_bShutdownSendThread [private] |
volatile bool CNetworkQueue::m_bSendThreadRunning [private] |
volatile bool CNetworkQueue::m_bShutdownReceiveThread [private] |
Definition at line 182 of file NQclass.h.
Referenced by close(), create(), and ReceiveProcessTask().
volatile bool CNetworkQueue::m_bReceiveThreadRunning [private] |
Definition at line 183 of file NQclass.h.
Referenced by close(), create(), and ReceiveProcessTask().
UINT16 CNetworkQueue::m_iNextRequestId [private] |