NewNet/nnsocket.h

00001 /*  NewNet - A networking framework in C++
00002     Copyright (C) 2006 Ingmar K. Steen (iksteen@gmail.com)
00003 
00004     This program is free software; you can redistribute it and/or modify
00005     it under the terms of the GNU General Public License as published by
00006     the Free Software Foundation; either version 2 of the License, or
00007     (at your option) any later version.
00008 
00009     This program is distributed in the hope that it will be useful,
00010     but WITHOUT ANY WARRANTY; without even the implied warranty of
00011     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012     GNU General Public License for more details.
00013 
00014     You should have received a copy of the GNU General Public License
00015     along with this program; if not, write to the Free Software
00016     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00017 
00018  */
00019 
00020 #ifndef NEWNET_SOCKET_H
00021 #define NEWNET_SOCKET_H
00022 
00023 #include "nnobject.h"
00024 #include "nnrefptr.h"
00025 #include "nnweakrefptr.h"
00026 #include "nnratelimiter.h"
00027 
00028 namespace NewNet
00029 {
00030   class Reactor;
00031 
00033 
00036   class Socket : public Object
00037   {
00038   public:
00040 
00042     typedef enum
00043     {
00044       SocketUninitialized, 
00045       SocketListening,     
00046       SocketConnecting,    
00047       SocketConnected,     
00048       SocketDisconnecting, 
00049       SocketDisconnected,  
00050       SocketException      
00051     } SocketState;
00052 
00054 
00057     typedef enum
00058     {
00059       StateSend = 1,       
00060       StateReceive = 2,    
00061       StateException = 4   
00062     } ReadyState;
00063 
00065 
00068     typedef enum
00069     {
00070       ErrorNoError,        
00071       ErrorCannotResolve,  
00072       ErrorInvalidPath,    
00073       ErrorCannotConnect,  
00074       ErrorCannotBind,     
00075       ErrorCannotListen,   
00076       ErrorUnknown         
00077     } SocketError;
00078 
00080 
00082     Socket() : m_Reactor(0), m_FD(-1), m_SocketState(SocketUninitialized),
00083               m_ReadyState(0), m_SocketError(ErrorNoError),
00084               m_DataWaiting(false)
00085     {
00086     }
00087 
00089 
00090     Reactor * reactor() const
00091     {
00092       return m_Reactor;
00093     }
00094 
00096 
00098     void setReactor(Reactor * reactor)
00099     {
00100       m_Reactor = reactor;
00101     }
00102 
00104 
00105     int descriptor() const
00106     {
00107       return m_FD;
00108     }
00109 
00111 
00114     void setDescriptor(int fd)
00115     {
00116       m_FD = fd;
00117     }
00118 
00120 
00121     SocketState socketState() const
00122     {
00123       return m_SocketState;
00124     }
00125 
00127 
00128     void setSocketState(SocketState socketState)
00129     {
00130       m_SocketState = socketState;
00131     }
00132 
00134 
00135     int readyState() const
00136     {
00137       return m_ReadyState;
00138     }
00139 
00141 
00143     void setReadyState(int readyState)
00144     {
00145       m_ReadyState = readyState;
00146     }
00147 
00149 
00150     SocketError socketError() const
00151     {
00152       return m_SocketError;
00153     }
00154 
00156 
00158     void setSocketError(SocketError socketError)
00159     {
00160       m_SocketError = socketError;
00161       setSocketState(SocketException);
00162     }
00163 
00165 
00167     bool dataWaiting() const
00168     {
00169       return m_DataWaiting;
00170     }
00171 
00173 
00174     void setDataWaiting(bool dataWaiting)
00175     {
00176       m_DataWaiting = dataWaiting;
00177     }
00178 
00180 
00181     RateLimiter * downRateLimiter()
00182     {
00183       return m_DownRateLimiter;
00184     }
00185 
00187 
00189     void setDownRateLimiter(RateLimiter * limiter)
00190     {
00191       m_DownRateLimiter = limiter;
00192     }
00193 
00195 
00196     RateLimiter * upRateLimiter()
00197     {
00198       return m_UpRateLimiter;
00199     }
00200 
00202 
00204     void setUpRateLimiter(RateLimiter * limiter)
00205     {
00206       m_DownRateLimiter = limiter;
00207     }
00208 
00210 
00211     virtual void process()
00212     {
00213     }
00214 
00215   private:
00216     Reactor * m_Reactor;
00217     int m_FD;
00218     SocketState m_SocketState;
00219     int m_ReadyState;
00220     SocketError m_SocketError;
00221     bool m_DataWaiting;
00222     RefPtr<RateLimiter> m_DownRateLimiter, m_UpRateLimiter;
00223   };
00224 }
00225 
00226 #endif // NEWNET_SOCKET_H

Generated on Sun Jan 7 14:00:01 2007 for NewNet by  doxygen 1.5.1