Home | nevrax.com |
|
buf_client.hGo to the documentation of this file.00001 00007 /* Copyright, 2001 Nevrax Ltd. 00008 * 00009 * This file is part of NEVRAX NEL. 00010 * NEVRAX NEL is free software; you can redistribute it and/or modify 00011 * it under the terms of the GNU General Public License as published by 00012 * the Free Software Foundation; either version 2, or (at your option) 00013 * any later version. 00014 00015 * NEVRAX NEL is distributed in the hope that it will be useful, but 00016 * WITHOUT ANY WARRANTY; without even the implied warranty of 00017 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00018 * General Public License for more details. 00019 00020 * You should have received a copy of the GNU General Public License 00021 * along with NEVRAX NEL; see the file COPYING. If not, write to the 00022 * Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, 00023 * MA 02111-1307, USA. 00024 */ 00025 00026 #ifndef NL_BUF_CLIENT_H 00027 #define NL_BUF_CLIENT_H 00028 00029 #include "nel/misc/types_nl.h" 00030 #include "nel/net/buf_net_base.h" 00031 #include "nel/net/tcp_sock.h" 00032 #include "nel/net/buf_sock.h" 00033 00034 00035 namespace NLNET { 00036 00037 00038 class CInetAddress; 00039 class CBufClient; 00040 00041 00045 class CClientReceiveTask : public NLMISC::IRunnable 00046 { 00047 public: 00048 00050 CClientReceiveTask( CBufClient *client, TSockId sockid ) : _Client(client), _SockId(sockid) {} 00051 00053 virtual void run(); 00054 00056 CTcpSock *sock() { return _SockId->Sock; } 00057 00059 TSockId sockId() { return _SockId; } 00060 00061 private: 00062 00063 CBufClient *_Client; 00064 00065 TSockId _SockId; 00066 }; 00067 00068 00069 00091 class CBufClient : public CBufNetBase 00092 { 00093 public: 00094 00096 CBufClient( bool nodelay=true, bool replaymode=false ); 00097 00099 virtual ~CBufClient(); 00100 00102 void connect( const CInetAddress& addr ); 00103 00109 void disconnect( bool quick=false ); 00110 00113 //void send( const std::vector<uint8>& buffer ); 00114 void send( const NLMISC::CMemStream& buffer ); 00115 00119 bool dataAvailable(); 00120 00124 //void receive( std::vector<uint8>& buffer ); 00125 void receive( NLMISC::CMemStream& buffer ); 00126 00128 void update(); 00129 00130 00131 00132 // Returns the size in bytes of the data stored in the send queue. 00133 uint32 getSendQueueSize() const { return _BufSock->SendFifo.size(); } 00134 00138 void setTimeFlushTrigger( sint32 ms ) { _BufSock->setTimeFlushTrigger( ms ); } 00139 00143 void setSizeFlushTrigger( sint32 size ) { _BufSock->setSizeFlushTrigger( size ); } 00144 00149 bool flush() { return _BufSock->flush(); } 00150 00151 00152 00157 bool connected() const { return _BufSock->connectedState(); } 00158 00160 const CInetAddress& remoteAddress() const { return _BufSock->Sock->remoteAddr(); } 00161 00163 uint64 bytesDownloaded() const { return _BufSock->Sock->bytesReceived(); } 00164 00166 uint64 bytesUploaded() const { return _BufSock->Sock->bytesSent(); } 00167 00169 uint64 newBytesDownloaded(); 00170 00172 uint64 newBytesUploaded(); 00173 00174 /*//Not right because we add callbacks in the receive queue 00176 uint64 bytesReceived() { } 00177 00179 uint64 bytesSent() { return bytesUploaded() + getSendQueueSize(); } 00180 00182 uint64 newBytesReceived(); 00183 00185 uint64 newBytesSent(); 00186 */ 00187 00189 TSockId id() const { return _BufSock; /*_RecvTask->sockId();*/ } 00190 00191 00192 protected: 00193 00194 friend class CClientReceiveTask; 00195 00197 CBufSock *_BufSock; 00198 00200 bool _NoDelay; 00201 00203 uint64 _PrevBytesDownloaded; 00204 00206 uint64 _PrevBytesUploaded; 00207 00208 /* 00210 uint32 _PrevBytesReceived; 00211 00213 uint32 _PrevBytesSent; 00214 */ 00215 00216 private: 00217 00219 CClientReceiveTask *_RecvTask; 00220 00222 NLMISC::IThread *_RecvThread; 00223 00224 }; 00225 00226 00227 00228 } // NLNET 00229 00230 00231 #endif // NL_BUF_CLIENT_H 00232 00233 /* End of buf_client.h */ |