00001 #ifndef __NETWORKQUEUE_H_INCLUDED__
00002 #define __NETWORKQUEUE_H_INCLUDED__
00003
00004
00006
00008 class CNetworkQueue
00009 {
00010 friend class CMessage;
00011 friend class CMessageBuffers;
00012 public:
00014 CNetworkQueue();
00015
00017 ~CNetworkQueue();
00018
00019
00029 CMessage *createMsg();
00030
00035 bool freeMsg( CMessage *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( CMessage *msg, UINT32 ip_hostorder, UINT16 port_hostorder);
00066
00074 bool sendMsgTo( CMessage *msg, UINT32 ip_hostorder, UINT16 port_hostorder, const PI_TIMEVAL &timeout);
00075
00081 bool recvMsg( CMessage **newmsg );
00082
00089 bool recvMsg( CMessage **newmsg, const PI_TIMEVAL &timeout );
00090
00100 bool sendRecvMsg(CMessage **response, CMessage *request, UINT32 ip_hostorder, UINT16 port_hostorder, const PI_TIMEVAL &timeout);
00101
00106 bool getStatistics( 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, CMessage *msg, HANDLE recv_notify_sem);
00140
00141 CMessage *obtainReference();
00142 bool incrementReferenceCount( CMessage *ref );
00143 bool putbackReference( CMessage *ref);
00144
00145
00146
00147 CMessagePool bufs;
00148
00149
00150 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 CPacketQueue m_SendPacketQueue;
00162 CPacketQueue m_ReceivePacketQueue;
00163
00164
00165 CPacketQueue m_AckPacketWaitingQueue;
00166
00167 CPacketQueue m_ReceiveResponseSemaphorePacketQueue;
00168 CResponseWaitQueue m_ResponseWaitQueue;
00169
00170
00171 CPeerList 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