lliosocket.h

Go to the documentation of this file.
00001 
00034 #ifndef LL_LLIOSOCKET_H
00035 #define LL_LLIOSOCKET_H
00036 
00045 #include "lliopipe.h"
00046 #include "apr-1/apr_pools.h"
00047 #include "apr-1/apr_network_io.h"
00048 #include "llchainio.h"
00049 
00050 class LLHost;
00051 
00063 class LLSocket
00064 {
00065 public:
00069         typedef boost::shared_ptr<LLSocket> ptr_t;
00070 
00074         enum EType
00075         {
00076                 STREAM_TCP,
00077                 DATAGRAM_UDP,
00078         };
00079 
00083         enum
00084         {
00085                 PORT_INVALID = (U16)-1,
00086                 PORT_EPHEMERAL = 0,
00087         };
00088 
00102         static ptr_t create(
00103                 apr_pool_t* pool,
00104                 EType type,
00105                 U16 port = PORT_EPHEMERAL);
00106 
00123         static ptr_t create(apr_socket_t* socket, apr_pool_t* pool);
00124 
00131         bool blockingConnect(const LLHost& host);
00132 
00136         //EType getType() const { return mType; }
00137 
00144         U16 getPort() const { return mPort; }
00145 
00151         apr_socket_t* getSocket() const { return mSocket; }
00152 
00153 protected:
00158         LLSocket(apr_socket_t* socket, apr_pool_t* pool);
00159 
00163         void setOptions();
00164 
00165 public:
00169         ~LLSocket();
00170 
00171 protected:
00172         // The apr socket.
00173         apr_socket_t* mSocket;
00174 
00175         // our memory pool
00176         apr_pool_t* mPool;
00177 
00178         // The port if we know it.
00179         U16 mPort;
00180 
00181         //EType mType;
00182 };
00183 
00193 class LLIOSocketReader : public LLIOPipe
00194 {
00195 public:
00196         LLIOSocketReader(LLSocket::ptr_t socket);
00197         ~LLIOSocketReader();
00198 
00199 protected:
00200         /* @name LLIOPipe virtual implementations
00201          */
00203 
00219         virtual EStatus process_impl(
00220                 const LLChannelDescriptors& channels,
00221                 buffer_ptr_t& buffer,
00222                 bool& eos,
00223                 LLSD& context,
00224                 LLPumpIO* pump);
00226 
00227 protected:
00228         LLSocket::ptr_t mSource;
00229         std::vector<U8> mBuffer;
00230         bool mInitialized;
00231 };
00232 
00241 class LLIOSocketWriter : public LLIOPipe
00242 {
00243 public:
00244         LLIOSocketWriter(LLSocket::ptr_t socket);
00245         ~LLIOSocketWriter();
00246 
00247 protected:
00248         /* @name LLIOPipe virtual implementations
00249          */
00251 
00265         virtual EStatus process_impl(
00266                 const LLChannelDescriptors& channels,
00267                 buffer_ptr_t& buffer,
00268                 bool& eos,
00269                 LLSD& context,
00270                 LLPumpIO* pump);
00272 
00273 protected:
00274         LLSocket::ptr_t mDestination;
00275         U8* mLastWritten;
00276         bool mInitialized;
00277 };
00278 
00296 class LLIOServerSocket : public LLIOPipe
00297 {
00298 public:
00299         typedef LLSocket::ptr_t socket_t;
00300         typedef boost::shared_ptr<LLChainIOFactory> factory_t;
00301         LLIOServerSocket(apr_pool_t* pool, socket_t listener, factory_t reactor);
00302         virtual ~LLIOServerSocket();
00303 
00315         void setResponseTimeout(F32 timeout_secs);
00316 
00317         /* @name LLIOPipe virtual implementations
00318          */
00320 protected:
00324         virtual EStatus process_impl(
00325                 const LLChannelDescriptors& channels,
00326                 buffer_ptr_t& buffer,
00327                 bool& eos,
00328                 LLSD& context,
00329                 LLPumpIO* pump);
00331 
00332 protected:
00333         apr_pool_t* mPool;
00334         socket_t mListenSocket;
00335         factory_t mReactor;
00336         bool mInitialized;
00337         F32 mResponseTimeout;
00338 };
00339 
00340 #if 0
00341 
00347 class LLIODataSocket : public LLIOSocket
00348 {
00349 public:
00365         LLIODataSocket(
00366                 U16 suggested_port,
00367                 U16 start_discovery_port,
00368                 apr_pool_t* pool);
00369         virtual ~LLIODataSocket();
00370 
00371 protected:
00372 
00373 private:
00374         apr_socket_t* mSocket;
00375 };
00376 #endif
00377 
00378 #endif // LL_LLIOSOCKET_H

Generated on Thu Jul 1 06:08:47 2010 for Second Life Viewer by  doxygen 1.4.7