00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
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
00032
00033
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
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