• Main Page
  • Classes
  • Files
  • File List

CArchNetworkWinsock.h

00001 /*
00002  * synergy -- mouse and keyboard sharing utility
00003  * Copyright (C) 2012 Bolton Software Ltd.
00004  * Copyright (C) 2002 Chris Schoeneman
00005  * 
00006  * This package is free software; you can redistribute it and/or
00007  * modify it under the terms of the GNU General Public License
00008  * found in the file COPYING that should have accompanied this file.
00009  * 
00010  * This package is distributed in the hope that it will be useful,
00011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  * GNU General Public License for more details.
00014  *
00015  * You should have received a copy of the GNU General Public License
00016  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
00017  */
00018 
00019 #ifndef CARCHNETWORKWINSOCK_H
00020 #define CARCHNETWORKWINSOCK_H
00021 
00022 #define WIN32_LEAN_AND_MEAN
00023 
00024 // declare no functions in winsock2
00025 #define INCL_WINSOCK_API_PROTOTYPES 0
00026 #define INCL_WINSOCK_API_TYPEDEFS 0
00027 
00028 #include "IArchNetwork.h"
00029 #include "IArchMultithread.h"
00030 #include <windows.h>
00031 #include <winsock2.h>
00032 #include <list>
00033 
00034 #define ARCH_NETWORK CArchNetworkWinsock
00035 
00036 class CArchSocketImpl {
00037 public:
00038     SOCKET              m_socket;
00039     int                 m_refCount;
00040     WSAEVENT            m_event;
00041     bool                m_pollWrite;
00042 };
00043 
00044 class CArchNetAddressImpl {
00045 public:
00046     static CArchNetAddressImpl* alloc(size_t);
00047 
00048 public:
00049     int                 m_len;
00050     struct sockaddr     m_addr;
00051 };
00052 #define ADDR_HDR_SIZE   offsetof(CArchNetAddressImpl, m_addr)
00053 #define TYPED_ADDR(type_, addr_) (reinterpret_cast<type_*>(&addr_->m_addr))
00054 
00056 class CArchNetworkWinsock : public IArchNetwork {
00057 public:
00058     CArchNetworkWinsock();
00059     virtual ~CArchNetworkWinsock();
00060 
00061     virtual void init();
00062 
00063     // IArchNetwork overrides
00064     virtual CArchSocket newSocket(EAddressFamily, ESocketType);
00065     virtual CArchSocket copySocket(CArchSocket s);
00066     virtual void        closeSocket(CArchSocket s);
00067     virtual void        closeSocketForRead(CArchSocket s);
00068     virtual void        closeSocketForWrite(CArchSocket s);
00069     virtual void        bindSocket(CArchSocket s, CArchNetAddress addr);
00070     virtual void        listenOnSocket(CArchSocket s);
00071     virtual CArchSocket acceptSocket(CArchSocket s, CArchNetAddress* addr);
00072     virtual bool        connectSocket(CArchSocket s, CArchNetAddress name);
00073     virtual int         pollSocket(CPollEntry[], int num, double timeout);
00074     virtual void        unblockPollSocket(CArchThread thread);
00075     virtual size_t      readSocket(CArchSocket s, void* buf, size_t len);
00076     virtual size_t      writeSocket(CArchSocket s,
00077                             const void* buf, size_t len);
00078     virtual void        throwErrorOnSocket(CArchSocket);
00079     virtual bool        setNoDelayOnSocket(CArchSocket, bool noDelay);
00080     virtual bool        setReuseAddrOnSocket(CArchSocket, bool reuse);
00081     virtual std::string     getHostName();
00082     virtual CArchNetAddress newAnyAddr(EAddressFamily);
00083     virtual CArchNetAddress copyAddr(CArchNetAddress);
00084     virtual CArchNetAddress nameToAddr(const std::string&);
00085     virtual void            closeAddr(CArchNetAddress);
00086     virtual std::string     addrToName(CArchNetAddress);
00087     virtual std::string     addrToString(CArchNetAddress);
00088     virtual EAddressFamily  getAddrFamily(CArchNetAddress);
00089     virtual void            setAddrPort(CArchNetAddress, int port);
00090     virtual int             getAddrPort(CArchNetAddress);
00091     virtual bool            isAnyAddr(CArchNetAddress);
00092     virtual bool            isEqualAddr(CArchNetAddress, CArchNetAddress);
00093 
00094 private:
00095     void                initModule(HMODULE);
00096 
00097     void                setBlockingOnSocket(SOCKET, bool blocking);
00098 
00099     void                throwError(int);
00100     void                throwNameError(int);
00101 
00102 private:
00103     typedef std::list<WSAEVENT> CEventList;
00104 
00105     CArchMutex          m_mutex;
00106     CEventList          m_unblockEvents;
00107 };
00108 
00109 #endif

Generated on Fri May 24 2013 00:00:03 for Synergy by  doxygen 1.7.1