00001 #ifndef __NETWORKQUEUE_H_INCLUDED__
00002 #define __NETWORKQUEUE_H_INCLUDED__
00003
00004
00006
00008 class CNetworkQueue
00009 {
00010 friend class CNQMessage;
00011 friend class CNQMessageBuffers;
00012 public:
00014 CNetworkQueue();
00015
00017 ~CNetworkQueue();
00018
00019
00029 CNQMessage *createMsg();
00030
00035 bool freeMsg( CNQMessage *ref);
00036
00042 bool addPeer(UINT32 ip_hostorder, UINT32 port_hostorder);
00043
00049 bool removePeer(UINT32 ip_hostorder, UINT32 port_hostorder);
00050
00056 bool create( const ONECHAR *ip_remote_peer, UINT16 portnumber_remote, UINT16 portnumber_local );
00057
00058 bool close();
00059
00062
00065 bool sendMsgTo( CNQMessage *msg, UINT32 ip_hostorder, UINT16 port_hostorder);
00066
00074 bool sendMsgTo( CNQMessage *msg, UINT32 ip_hostorder, UINT16 port_hostorder, const NQ_TIMEVAL &timeout);
00075
00081 bool recvMsg( CNQMessage **newmsg );
00082
00089 bool recvMsg( CNQMessage **newmsg, const NQ_TIMEVAL &timeout );
00090
00100 bool sendRecvMsg(CNQMessage **response, CNQMessage *request, UINT32 ip_hostorder, UINT16 port_hostorder, const NQ_TIMEVAL &timeout);
00101
00106 bool getStatistics( NQ_STATISTICS &stats );
00107
00109
00110
00111 UINT32 getLastError();
00112
00113 bool getLastErrorString( ONECHAR *buffer, UINT32 buflength);
00114
00115
00116
00117
00118
00124 void SendProcessTask();
00125
00131 void ReceiveProcessTask();
00132
00133
00134
00135 protected:
00136
00137 private:
00138
00139 bool sendMsgToInternal( UINT32 ip_hostorder, UINT16 port_hostorder, CNQMessage *msg, HANDLE recv_notify_sem);
00140
00141 CNQMessage *obtainReference();
00142 bool incrementReferenceCount( CNQMessage *ref );
00143 bool putbackReference( CNQMessage *ref);
00144
00145
00146
00147 CNQMessagePool bufs;
00148
00149
00150 NQ_STATISTICS m_stats;
00151
00152 socktype m_socket;
00153 UINT32 m_iLastError;
00154 INT32 m_iLastSystemError;
00155
00156
00157 HANDLE m_sendSemaphore;
00158 HANDLE m_receiveSemaphore;
00159
00160
00161 CNQPacketQueue m_SendPacketQueue;
00162 CNQPacketQueue m_ReceivePacketQueue;
00163
00164
00165 CNQPacketQueue m_AckPacketWaitingQueue;
00166
00167 CNQPacketQueue m_ReceiveResponseSemaphorePacketQueue;
00168 CNQResponseWaitQueue m_ResponseWaitQueue;
00169
00170
00171 CNQPeerList m_PeerList;
00172
00173 bool m_bSuccessfulInitialized;
00174
00175
00176 HANDLE m_hSendThread;
00177 HANDLE m_hReceiveThread;
00178
00179 volatile bool m_bShutdownSendThread;
00180 volatile bool m_bSendThreadRunning;
00181
00182 volatile bool m_bShutdownReceiveThread;
00183 volatile bool m_bReceiveThreadRunning;
00184
00185
00186 UINT16 m_iNextRequestId;
00187 };
00188
00189
00190 #endif //__NETWORKQUEUE_H_INCLUDED__
00191