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:
00031 AsyncClientConnectorException(char* pchMessage,const char* pFname,const int iLine)
00032 : GeneralException(pchMessage,pFname,iLine){};
00033 };
00034
00048 class AsyncClientConnector
00049 {
00050
00051 protected:
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:
00065 AsyncClientConnector();
00066
00067 public:
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
00076
00077 public:
00078 AsyncClientConnector(const char* pszHost,word wPort);
00079 ~AsyncClientConnector();
00080
00081 public:
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
00095 AsyncClientConnector(const AsyncClientConnector&);
00096 AsyncClientConnector& operator=(const AsyncClientConnector&);
00097 };
00098
00099 };
00100
00101 #endif //ASYNCCLIENTCONNECTOR_H