CTCPSocket.h

00001 /*
00002  * synergy -- mouse and keyboard sharing utility
00003  * Copyright (C) 2002 Chris Schoeneman
00004  * 
00005  * This package is free software; you can redistribute it and/or
00006  * modify it under the terms of the GNU General Public License
00007  * found in the file COPYING that should have accompanied this file.
00008  * 
00009  * This package 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 
00015 #ifndef CTCPSOCKET_H
00016 #define CTCPSOCKET_H
00017 
00018 #include "IDataSocket.h"
00019 #include "CStreamBuffer.h"
00020 #include "CCondVar.h"
00021 #include "CMutex.h"
00022 #include "IArchNetwork.h"
00023 
00024 class CMutex;
00025 class CThread;
00026 class ISocketMultiplexerJob;
00027 
00029 
00032 class CTCPSocket : public IDataSocket {
00033 public:
00034     CTCPSocket();
00035     CTCPSocket(CArchSocket);
00036     ~CTCPSocket();
00037 
00038     // ISocket overrides
00039     virtual void        bind(const CNetworkAddress&);
00040     virtual void        close();
00041     virtual void*       getEventTarget() const;
00042 
00043     // IStream overrides
00044     virtual UInt32      read(void* buffer, UInt32 n);
00045     virtual void        write(const void* buffer, UInt32 n);
00046     virtual void        flush();
00047     virtual void        shutdownInput();
00048     virtual void        shutdownOutput();
00049     virtual bool        isReady() const;
00050     virtual UInt32      getSize() const;
00051 
00052     // IDataSocket overrides
00053     virtual void        connect(const CNetworkAddress&);
00054 
00055 private:
00056     void                init();
00057 
00058     void                setJob(ISocketMultiplexerJob*);
00059     ISocketMultiplexerJob*  newJob();
00060     void                sendConnectionFailedEvent(const char*);
00061     void                sendEvent(CEvent::Type);
00062 
00063     void                onConnected();
00064     void                onInputShutdown();
00065     void                onOutputShutdown();
00066     void                onDisconnected();
00067 
00068     ISocketMultiplexerJob*
00069                         serviceConnecting(ISocketMultiplexerJob*,
00070                             bool, bool, bool);
00071     ISocketMultiplexerJob*
00072                         serviceConnected(ISocketMultiplexerJob*,
00073                             bool, bool, bool);
00074 
00075 private:
00076     CMutex              m_mutex;
00077     CArchSocket         m_socket;
00078     CStreamBuffer       m_inputBuffer;
00079     CStreamBuffer       m_outputBuffer;
00080     CCondVar<bool>      m_flushed;
00081     bool                m_connected;
00082     bool                m_readable;
00083     bool                m_writable;
00084 };
00085 
00086 #endif

Generated on Fri Nov 6 00:18:45 2009 for synergy-plus by  doxygen 1.4.7