Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages  

asyncclientconnector.h

Go to the documentation of this file.
00001 /********************************************************************
00002         Copyright (c) 2001, Lee Patterson & Ant Works Software
00003         http://ssobjects.sourceforge.net
00004 
00005         created  :  
00006         filename :  asyncclientconnector.h
00007         author   :  Lee Patterson (workerant@users.sourceforge.net)
00008         
00009         purpose  :  
00010 *********************************************************************/
00011 
00012 #ifndef ASYNCCLIENTCONNECTOR_H
00013 #define ASYNCCLIENTCONNECTOR_H
00014 
00015 #include "ssobjects.h"
00016 #include "serversocket.h"
00017 #include "packetmessageque.h"
00018 
00019 namespace ssobjects
00020 {
00021 
00022 #define throwAsyncClientConnectorException(m) (throw AsyncClientConnectorException(m,__FILE__,__LINE__))
00023 
00028 class AsyncClientConnectorException : public GeneralException
00029 {
00030   public: // Constructor/destructor
00031     AsyncClientConnectorException(char* pchMessage,const char* pFname,const int iLine) 
00032                         : GeneralException(pchMessage,pFname,iLine){};
00033 };
00034 
00048 class AsyncClientConnector
00049 {
00050 
00051   protected:  //attributes
00052     unsigned16      m_wPort;      
00053     CStr            m_strHost;    
00054     ServerSocket*   m_pSocket;    
00055     PacketMessageQue        m_que;        
00056 #ifdef _WIN32
00057     WSADATA         m_wsd;        
00058 #endif
00059 
00060   protected:
00061     void        cleanup();        
00062     void        setNonBlocking(SOCKET sockfd);  
00063 
00064   private:    //construction
00065     AsyncClientConnector();
00066 
00067   public:     //overridables
00068     void handleException(GeneralException& e);
00069     void sendPacket(PacketBuffer* pPkt);          
00070     void sendPacket(PacketBuffer& pPkt);          
00071     void operator << (PacketBuffer&);             
00072     void operator << (PacketBuffer*);             
00073     PacketMessage* getMsg();                          
00074 
00075 //TODO: add setTimeout() method
00076 
00077   public:     //construction
00078     AsyncClientConnector(const char* pszHost,word wPort);    
00079     ~AsyncClientConnector();                                 
00080 
00081   public:     //methods
00082     const char* getServer()     {return m_strHost;}                   
00083     const word  getPort()       {return m_wPort;}                     
00084     bool        isConnected()   {return m_pSocket ? true:false;}      
00085     ServerSocket* getSocket();                                        
00086 
00087     void        reconnect();                                          
00088     void        connect(const char* pszHost,const unsigned16 wPort);  
00089     void        connect();                                            
00090     void        close();                                              
00091     bool        idle();                                               
00092 
00093   private:
00094     //unused overloads
00095     AsyncClientConnector(const AsyncClientConnector&);
00096     AsyncClientConnector& operator=(const AsyncClientConnector&);
00097 };
00098 
00099 };
00100 
00101 #endif  //ASYNCCLIENTCONNECTOR_H

Generated on Thu Nov 8 12:39:25 2001 for SimpleServerObjects by doxygen1.2.11 written by Dimitri van Heesch, © 1997-2001