From 9ab87f39d7fc37e52d742d38b191eed9128d4b5b Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Thu, 7 Feb 2008 19:01:12 +0000 Subject: Wowee, I think all this new stuff works, Conduit I don't need now, so it's not done yet. The Client class now supports a function called getLink() which returns a ClientLink object. This object may then be passed off to any other class and called to send messages to that client object. It is threadsafe if ItoServer is being used, and not for Server. Sending a message via a ClientLink calls the onMessage function on the assosiated protocol. Note that sending messages from within protocol event handlers or functions they call, while safe, may be slow and it's reccomended that you avoid this. --- src/itoserver.h | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) (limited to 'src/itoserver.h') diff --git a/src/itoserver.h b/src/itoserver.h index f11960c..09ed1cd 100644 --- a/src/itoserver.h +++ b/src/itoserver.h @@ -17,6 +17,9 @@ #include "bu/itoqueue.h" #include "bu/set.h" +#include "bu/clientlink.h" +#include "bu/clientlinkfactory.h" + namespace Bu { class ServerSocket; @@ -47,6 +50,7 @@ namespace Bu class ItoServer : public Ito { friend class ItoClient; + friend class SrvClientLinkFactory; public: ItoServer(); virtual ~ItoServer(); @@ -65,8 +69,10 @@ namespace Bu virtual void *run(); private: + class SrvClientLink; class ItoClient : public Ito { + friend class Bu::ItoServer::SrvClientLink; public: ItoClient( ItoServer &rSrv, int nSocket, int nPort, int nTimeoutSec, int nTimeoutUSec ); @@ -74,6 +80,9 @@ namespace Bu virtual void *run(); + typedef ItoQueue StringQueue; + StringQueue qMsg; + private: ItoServer &rSrv; Client *pClient; @@ -82,6 +91,31 @@ namespace Bu int iPort; int nTimeoutSec; int nTimeoutUSec; + ItoMutex imProto; + }; + + class SrvClientLink : public Bu::ClientLink + { + public: + SrvClientLink( ItoClient *pClient ); + virtual ~SrvClientLink(); + + virtual void sendMsg( const Bu::FString &sMsg ); + + private: + ItoClient *pClient; + }; + + class SrvClientLinkFactory : public Bu::ClientLinkFactory + { + public: + SrvClientLinkFactory( ItoServer &rSrv ); + virtual ~SrvClientLinkFactory(); + + virtual Bu::ClientLink *createLink( Bu::Client *pClient ); + + private: + ItoServer &rSrv; }; int nTimeoutSec; -- cgit v1.2.3