CArchNetworkWinsock.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 CARCHNETWORKWINSOCK_H
00016 #define CARCHNETWORKWINSOCK_H
00017 
00018 #define WIN32_LEAN_AND_MEAN
00019 
00020 // declare no functions in winsock2
00021 #define INCL_WINSOCK_API_PROTOTYPES 0
00022 #define INCL_WINSOCK_API_TYPEDEFS 0
00023 
00024 #include "IArchNetwork.h"
00025 #include "IArchMultithread.h"
00026 #include <windows.h>
00027 #include <winsock2.h>
00028 
00029 #define ARCH_NETWORK CArchNetworkWinsock
00030 
00031 class CArchSocketImpl {
00032 public:
00033     SOCKET              m_socket;
00034     int                 m_refCount;
00035     WSAEVENT            m_event;
00036     bool                m_pollWrite;
00037 };
00038 
00039 class CArchNetAddressImpl {
00040 public:
00041     static CArchNetAddressImpl* alloc(size_t);
00042 
00043 public:
00044     int                 m_len;
00045     struct sockaddr     m_addr;
00046 };
00047 #define ADDR_HDR_SIZE   offsetof(CArchNetAddressImpl, m_addr)
00048 #define TYPED_ADDR(type_, addr_) (reinterpret_cast<type_*>(&addr_->m_addr))
00049 
00051 class CArchNetworkWinsock : public IArchNetwork {
00052 public:
00053     CArchNetworkWinsock();
00054     virtual ~CArchNetworkWinsock();
00055 
00056     // IArchNetwork overrides
00057     virtual CArchSocket newSocket(EAddressFamily, ESocketType);
00058     virtual CArchSocket copySocket(CArchSocket s);
00059     virtual void        closeSocket(CArchSocket s);
00060     virtual void        closeSocketForRead(CArchSocket s);
00061     virtual void        closeSocketForWrite(CArchSocket s);
00062     virtual void        bindSocket(CArchSocket s, CArchNetAddress addr);
00063     virtual void        listenOnSocket(CArchSocket s);
00064     virtual CArchSocket acceptSocket(CArchSocket s, CArchNetAddress* addr);
00065     virtual bool        connectSocket(CArchSocket s, CArchNetAddress name);
00066     virtual int         pollSocket(CPollEntry[], int num, double timeout);
00067     virtual void        unblockPollSocket(CArchThread thread);
00068     virtual size_t      readSocket(CArchSocket s, void* buf, size_t len);
00069     virtual size_t      writeSocket(CArchSocket s,
00070                             const void* buf, size_t len);
00071     virtual void        throwErrorOnSocket(CArchSocket);
00072     virtual bool        setNoDelayOnSocket(CArchSocket, bool noDelay);
00073     virtual bool        setReuseAddrOnSocket(CArchSocket, bool reuse);
00074     virtual std::string     getHostName();
00075     virtual CArchNetAddress newAnyAddr(EAddressFamily);
00076     virtual CArchNetAddress copyAddr(CArchNetAddress);
00077     virtual CArchNetAddress nameToAddr(const std::string&);
00078     virtual void            closeAddr(CArchNetAddress);
00079     virtual std::string     addrToName(CArchNetAddress);
00080     virtual std::string     addrToString(CArchNetAddress);
00081     virtual EAddressFamily  getAddrFamily(CArchNetAddress);
00082     virtual void            setAddrPort(CArchNetAddress, int port);
00083     virtual int             getAddrPort(CArchNetAddress);
00084     virtual bool            isAnyAddr(CArchNetAddress);
00085     virtual bool            isEqualAddr(CArchNetAddress, CArchNetAddress);
00086 
00087 private:
00088     void                init(HMODULE);
00089 
00090     void                setBlockingOnSocket(SOCKET, bool blocking);
00091 
00092     void                throwError(int);
00093     void                throwNameError(int);
00094 
00095 private:
00096     CArchMutex          m_mutex;
00097 };
00098 
00099 #endif

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