00001
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #ifndef NL_CALLBACK_SERVER_H
00027 #define NL_CALLBACK_SERVER_H
00028
00029 #include "nel/misc/types_nl.h"
00030
00031 #include "nel/net/callback_net_base.h"
00032 #include "nel/net/buf_server.h"
00033
00034
00035 namespace NLNET {
00036
00037
00044 class CCallbackServer : public CCallbackNetBase, public CBufServer
00045 {
00046 public:
00047
00049 CCallbackServer( TRecordingState rec=Off, const std::string& recfilename="", bool recordall=true );
00050
00052 void send (const CMessage &buffer, TSockId hostid, bool log = true);
00053
00055 bool flush (TSockId destid) { checkThreadId (); nlassert( destid != InvalidSockId ); return CBufServer::flush(destid); }
00056
00058 void update (sint32 timeout=0);
00059
00061 void setConnectionCallback (TNetCallback cb, void *arg) { checkThreadId (); _ConnectionCallback = cb; _ConnectionCbArg = arg; }
00062
00064 void setDisconnectionCallback (TNetCallback cb, void *arg) { checkThreadId (); CCallbackNetBase::setDisconnectionCallback (cb, arg); }
00065
00067 bool connected () const { checkThreadId (); return true; }
00068
00074 void disconnect (TSockId hostid);
00075
00077 const CInetAddress& hostAddress (TSockId hostid) { nlassert(hostid!=InvalidSockId); checkThreadId(); return CBufServer::hostAddress (hostid); }
00078
00080 virtual TSockId getSockId (TSockId hostid = InvalidSockId);
00081
00082 uint64 getReceiveQueueSize () { return CBufServer::getReceiveQueueSize(); }
00083 uint64 getSendQueueSize () { return CBufServer::getSendQueueSize(0); }
00084
00085 private:
00086
00088 void send (const NLMISC::CMemStream &buffer, TSockId hostid) { nlstop; }
00089
00090 bool dataAvailable ();
00091 void receive (CMessage &buffer, TSockId *hostid);
00092
00093 void sendAllMyAssociations (TSockId to);
00094
00095 TNetCallback _ConnectionCallback;
00096 void *_ConnectionCbArg;
00097
00098 friend void cbsNewConnection (TSockId from, void *data);
00099
00100
00101 #ifdef USE_MESSAGE_RECORDER
00102 void noticeConnection( TSockId hostid );
00103 virtual bool replaySystemCallbacks();
00104 std::vector<CBufSock*> _MR_Connections;
00105 std::map<TSockId,TSockId> _MR_SockIds;
00106 #endif
00107
00108
00109 };
00110
00111
00112 }
00113
00114
00115 #endif // NL_CALLBACK_SERVER_H
00116
00117