Main Page | Class Hierarchy | Alphabetical List | Class List | File List | Class Members

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

Generated on Fri Nov 6 00:21:13 2009 for synergy-plus by  doxygen 1.3.9.1