00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
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
00036
00037
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
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