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

serversocket.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  :  November 21, 2000
00006        filename :  serversocket.h
00007        author   :  Lee Patterson (lee@antws.com)
00008 
00009        purpose  :  Handles buffered socket operations.
00010 
00011 *********************************************************************/
00012 
00013 #ifndef SERVERSOCKET_H
00014 #define SERVERSOCKET_H
00015 
00016 #ifdef _WIN32
00017 #   include <time.h>
00018 #else
00019 #   include <sys/time.h>
00020 #   include <unistd.h>
00021 #endif
00022 
00023 #include "packetbuffer.h"
00024 #include "flags.h"
00025 #include "linkedlist.h"
00026 #include "bufferedsocket.h"
00027 #include "threadutils.h"
00028 #include "packetmessageque.h"
00029 
00030 namespace ssobjects
00031 {
00032 
00033 #define throwServerSocketException(m) (throw ServerSocketException(m,__FILE__,__LINE__))
00034 
00038 class ServerSocketException : public GeneralException
00039 {
00040   public: // Constructor/destructor
00041     ServerSocketException(char* pchMessage,const char* pFname,const int iLine) 
00042       : GeneralException(pchMessage,pFname,iLine){};
00043 };
00044 
00045 class ServerHandler;
00046 
00059 class ServerSocket : public SocketInstance
00060 {
00061   public:   //enums
00063     enum
00064       {
00065       modeInvalid         = 0,
00066 
00067       modeWriteOkay = 1,    //it is okay for the write thread to write to this socket
00068       modeSendOkay  = 2,    //it is okay to send more packets to this socket (send
00069       modeReadOkay  = 4,    //it is okay to read data from this socket
00070       modeClosing   = 8,    //socket should be closed next call to CleanSockets 
00071       modeNotified  = 16,   //a message to have this socket removed has been sent to server
00072       modeClosed    = 32,   //this socket has been closed, and is now free
00073 
00074       modeValid=modeSendOkay|modeWriteOkay|modeReadOkay,        //socket is connected, and everything is okay
00075 
00076       modeAll=0xFFFFFFFF
00077       };
00078 
00079   public:
00080     ServerSocket(const unsigned32 nBufferSize=18000,const int iTimeout=DEFAULT_SOCKET_TIMEOUT);
00081     ServerSocket(const SocketInstance& socket,const SockAddr& sa,const unsigned32 nBuffSize,const int iTimeout);
00082     virtual ~ServerSocket();
00083 
00084     void            sendPacket(const PacketBuffer& packet);             
00085     void            sendPacket(const PacketBuffer* const ppacket);      
00086     void            sendBuffer();                                   
00087     int             readData();                                     
00088     PacketBuffer*       extractPacket();                                
00089     const Flags&    flags() const {return m_flags;}                         
00090     unsigned32      getOutBufferSize() const {return m_nBytesOut;}          
00091     unsigned32      getOutBufferSizeMax() const {return m_nBufferSizeMax;}  
00092     unsigned32      getInBufferSize() const  {return m_nBytesIn;}           
00093     unsigned32      getBufferSizeMax() const {return m_nBufferSizeMax;}     
00094     SockAddr        getAddr() const {return m_socketAddr;}                  
00095     int             socketTimeout() const {return m_iTimeout;}              
00096     ServerHandler* serverHandler() const {return m_pserverHandler;}             
00097     void            setServerHandler(ServerHandler* s) {m_pserverHandler = s;}  
00098 
00099   protected:
00100     char*           getOutBuffer() const {return m_pOutBuff;}
00101     char*           getInBuffer() const {return m_pInBuff;}
00102     void            rotateBuffer(char* pbuffer,unsigned32 nBuffSize,unsigned32 nBytesRotatingOut);
00103     void            addPacketBuffer(const PacketBuffer* const ppacket);
00104 
00105   protected:
00106     ServerHandler*  m_pserverHandler;
00107     SockAddr        m_socketAddr;
00108     unsigned32      m_nID;
00109     int             m_iTimeout;
00110     Flags           m_flags;
00111     char*           m_pInBuff;      //buffer that contains data that was read from socket
00112     char*           m_pOutBuff;     //buffer that contains data that will be sent to socket
00113     char*           m_pOutPtr;      //pointer to first free byte in outgoing buffer
00114     char*           m_pInPtr;       //pointer to first free byte in incoming buffer
00115     unsigned32      m_nBytesIn;     //#bytes in the incoming buffer
00116     unsigned32      m_nBytesOut;    //#bytes in the outgoing buffer
00117     unsigned32      m_nBufferSizeMax;       //how big the in/out buffer is
00118 
00119   protected:
00120     //unused overloads
00121     ServerSocket(const ServerSocket&);
00122     ServerSocket& operator=(const ServerSocket&);
00123 };
00124 
00125 };
00126 
00127 #endif  //SERVERSOCKET_H

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