• Main Page
  • Classes
  • Files
  • File List

CArchNetworkBSD.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 CARCHNETWORKBSD_H
00020 #define CARCHNETWORKBSD_H
00021 
00022 #include "IArchNetwork.h"
00023 #include "IArchMultithread.h"
00024 #if HAVE_SYS_TYPES_H
00025 #   include <sys/types.h>
00026 #endif
00027 #if HAVE_SYS_SOCKET_H
00028 #   include <sys/socket.h>
00029 #endif
00030 
00031 #if !HAVE_SOCKLEN_T
00032 typedef int socklen_t;
00033 #endif
00034 
00035 // old systems may use char* for [gs]etsockopt()'s optval argument.
00036 // this should be void on modern systems but char is forwards
00037 // compatible so we always use it.
00038 typedef char optval_t;
00039 
00040 #define ARCH_NETWORK CArchNetworkBSD
00041 
00042 class CArchSocketImpl {
00043 public:
00044     int                 m_fd;
00045     int                 m_refCount;
00046 };
00047 
00048 class CArchNetAddressImpl {
00049 public:
00050     CArchNetAddressImpl() : m_len(sizeof(m_addr)) { }
00051 
00052 public:
00053     struct sockaddr     m_addr;
00054     socklen_t           m_len;
00055 };
00056 
00058 class CArchNetworkBSD : public IArchNetwork {
00059 public:
00060     CArchNetworkBSD();
00061     virtual ~CArchNetworkBSD();
00062 
00063     virtual void init();
00064 
00065     // IArchNetwork overrides
00066     virtual CArchSocket     newSocket(EAddressFamily, ESocketType);
00067     virtual CArchSocket     copySocket(CArchSocket s);  virtual void        closeSocket(CArchSocket s);
00068     virtual void        closeSocketForRead(CArchSocket s);
00069     virtual void        closeSocketForWrite(CArchSocket s);
00070     virtual void        bindSocket(CArchSocket s, CArchNetAddress addr);
00071     virtual void        listenOnSocket(CArchSocket s);
00072     virtual CArchSocket acceptSocket(CArchSocket s, CArchNetAddress* addr);
00073     virtual bool        connectSocket(CArchSocket s, CArchNetAddress name);
00074     virtual int         pollSocket(CPollEntry[], int num, double timeout);
00075     virtual void        unblockPollSocket(CArchThread thread);
00076     virtual size_t      readSocket(CArchSocket s, void* buf, size_t len);
00077     virtual size_t      writeSocket(CArchSocket s,
00078                             const void* buf, size_t len);
00079     virtual void        throwErrorOnSocket(CArchSocket);
00080     virtual bool        setNoDelayOnSocket(CArchSocket, bool noDelay);
00081     virtual bool        setReuseAddrOnSocket(CArchSocket, bool reuse);
00082     virtual std::string     getHostName();
00083     virtual CArchNetAddress newAnyAddr(EAddressFamily);
00084     virtual CArchNetAddress copyAddr(CArchNetAddress);
00085     virtual CArchNetAddress nameToAddr(const std::string&);
00086     virtual void            closeAddr(CArchNetAddress);
00087     virtual std::string     addrToName(CArchNetAddress);
00088     virtual std::string     addrToString(CArchNetAddress);
00089     virtual EAddressFamily  getAddrFamily(CArchNetAddress);
00090     virtual void            setAddrPort(CArchNetAddress, int port);
00091     virtual int             getAddrPort(CArchNetAddress);
00092     virtual bool            isAnyAddr(CArchNetAddress);
00093     virtual bool            isEqualAddr(CArchNetAddress, CArchNetAddress);
00094 
00095 private:
00096     const int*          getUnblockPipe();
00097     const int*          getUnblockPipeForThread(CArchThread);
00098     void                setBlockingOnSocket(int fd, bool blocking);
00099     void                throwError(int);
00100     void                throwNameError(int);
00101 
00102 private:
00103     CArchMutex          m_mutex;
00104 };
00105 
00106 #endif

Generated on Wed Jun 19 2013 00:00:04 for Synergy by  doxygen 1.7.1