⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 wysockaddrlocal.h

📁 一个不错
💻 H
字号:
/* Copyright is licensed under GNU LGPL.                 by I.J.Wang 2003  WySockAddrLocal deals with the local address (AF_LOCAL)  Warning: Implementation might not work properly. See the .cpp file.  Note: Class is not decided to be inherited  [Converted] struct sockaddr/socklen_t/inet_ntop                  inet_ntop*/#ifndef WYSOCKADDRLOCAL_H__#define WYSOCKADDRLOCAL_H__#define WYSOCKADDRLOCAL_VERSION 31#include "wyret.h"#include "wy_sockaddr.h"#include "wystr.h"#include <sys/un.h>class WySockAddrLocal : public Wy_SockAddr {    static const socklen_t SunPathZeroSize;  // size of _saddr contains no data    static const socklen_t DefaultSockLen;   // ==SunPathZeroSize  public:    static const char class_name[];    static const size_t PathMaxLen=                      sizeof(((struct ::sockaddr_un*)0)->sun_path);    WY_THROW_REPLY;    static int family(void) WY__TSPC()              { return AF_LOCAL; };    WySockAddrLocal() WY__TSPC();    WySockAddrLocal(const WySockAddrLocal &src) WY__TSPC();    WySockAddrLocal(const struct ::sockaddr_un&,size_t) WY__TSPC(WyRet);    explicit  // no implicit conversion    WySockAddrLocal(const char* path) WY__TSPC(WyRet);    explicit  // no implicit conversion    WySockAddrLocal(const WyStr& path) WY__TSPC(WyRet);    explicit  // no implicit conversion    WySockAddrLocal(const WyCSeg& path) WY__TSPC(WyRet);    // [Move Constructor]    //    // Note: src must be whole object except in initialization list    //    WySockAddrLocal(WySockAddrLocal &src, Wy::ByMove_t) WY__TSPC();    bool is_default(void) const WY__TSPC();    WyCSeg _path(void) const WY__TSPC();    // [Override]    virtual WyRet notation(WyStr& str) const;    // [Override]    virtual void reset(void) WY__TSPC();    // [Added]    virtual void reset(const WySockAddrLocal& src) WY__TSPC();    virtual WyRet reset(const struct ::sockaddr_un&,size_t) WY__TSPC();    virtual WyRet reset(const char* path) WY__TSPC();    virtual WyRet reset(const WyStr& path) WY__TSPC();    virtual WyRet reset(const WyCSeg& path) WY__TSPC();    // [Override]    virtual WyRet _swap(Wy_SockAddr& laddr) WY__TSPC();    virtual WySockAddrLocal* _alloc(WyRet&) const;    // [Added]    virtual const WySockAddrLocal& operator=(const WySockAddrLocal& rhs) WY__TSPC();    virtual const WySockAddrLocal& operator=(const char* rhs) WY__TSPC(WyRet);    virtual const WySockAddrLocal& operator=(const WyStr& rhs) WY__TSPC(WyRet);    virtual const WySockAddrLocal& operator=(const WyCSeg& rhs) WY__TSPC(WyRet);    bool operator==(const WySockAddrLocal &rhs) const WY__TSPC();    bool operator!=(const WySockAddrLocal &rhs) const WY__TSPC()              { return !operator==(rhs); };    bool operator==(const char* rhs) const WY__TSPC(Reply);    bool operator!=(const char* rhs) const WY__TSPC(Reply)              { return !operator==(rhs); };    bool operator==(const WyStr& rhs) const WY__TSPC();    bool operator!=(const WyStr& rhs) const WY__TSPC()              { return !operator==(rhs); };    bool operator==(const WyCSeg& rhs) const WY__TSPC();    bool operator!=(const WyCSeg& rhs) const WY__TSPC()              { return !operator==(rhs); };    void wy_adj_slen(void);  private:    // [Override]    virtual struct sockaddr& c_sockaddr(void) WY__TSPC()              { return (struct sockaddr&)(_saddr); };    virtual const struct sockaddr& c_sockaddr(void) const WY__TSPC()              { return (const struct sockaddr&)(_saddr); };    virtual size_t c_sockaddr_size(void) const WY__TSPC()              { return sizeof(_saddr); };    virtual  socklen_t& c_addrlen(void) WY__TSPC()              { return _slen; };    virtual const socklen_t& c_addrlen(void) const WY__TSPC()              { return _slen; };    // [Internal] Initialize object to contain the arguments indicated    //            pathname (zero terminated)    //    // [Ret] Ok    //       Wym_EFAULT       zero pointer    //       Wym_ENAMETOOLONG path too long    //    WyRet _init_pathname(const char* pdata) WY__NOTHROW__;    // [Internal] Initialize object to contain the arguments indicated    //            pathname    //    // [Ret] Ok    //       Wym_EFAULT       zero pointer    //       Wym_ENAMETOOLONG path too long    //    WyRet _init_pathname(const char* pdata, size_t plen) WY__NOTHROW__;    // [Internal] Initialize object to contain the arguments indicated    //            Linux absolute namespace    //    // [Ret] Ok    //       Wym_EFAULT       zero pointer    //       Wym_ENAMETOOLONG path too long    //       Wym_EINVAL       pdata not pointing to a Linux-absolute-namespace    //    WyRet _init_lans(const char* pdata,size_t plen) WY__NOTHROW__;    // [Internal] Initialize object from ::sockaddr_un    //            len specifies the actual length of addr    //    // Note: addr.sun_family is ignored    //    // [Ret] Ok    //       Wym_EINVAL      len in not valid    //    WyRet _init_sockaddr(const struct ::sockaddr_un& addr, size_t len) WY__NOTHROW__;  private:    class Wy__Assert_Check__;    // [Internal] Get the data length in sun_path (derived from the effective    //            size of _slen)    //    // [Ret] Length of data in sun_path (equ. to SUN_LEN)    //    socklen_t _sun_path_dlen(void) const WY__NOTHROW__         { return(_slen-SunPathZeroSize); };    struct ::sockaddr_un _saddr;    socklen_t _slen;         // effective length of _saddr (>=SunPathZeroSize)};inline bool operator==(const char* lhs,const WySockAddrLocal& rhs) WY__TSPC(WySockAddrLocal::Reply)              { return rhs.operator==(lhs); };inline bool operator!=(const char* lhs,const WySockAddrLocal& rhs) WY__TSPC(WySockAddrLocal::Reply)              { return rhs.operator!=(lhs); };inline bool operator==(const WyStr& lhs,const WySockAddrLocal& rhs) WY__TSPC()              { return rhs.operator==(lhs); };inline bool operator!=(const WyStr& lhs,const WySockAddrLocal& rhs) WY__TSPC()              { return rhs.operator!=(lhs); };inline bool operator==(const WyCSeg& lhs,const WySockAddrLocal& rhs) WY__TSPC()              { return rhs.operator==(lhs); };inline bool operator!=(const WyCSeg& lhs,const WySockAddrLocal& rhs) WY__TSPC()              { return rhs.operator!=(lhs); };namespace Wy { inline WyStr wrd(const WySockAddrLocal& addr) WY__TSPC(WyStr::Reply)   { return WyStr(addr._path()); };};/*// Wy_Array specilization to support struct sockaddr_un//#include "wy_array.h"template<>struct Wy_Array< struct sockaddr_un > : Wy__ArrayValue< struct sockaddr_un > {  Wy_Array() : Wy__ArrayValue< struct sockaddr_un >() {};  Wy_Array(size_t s,const struct sockaddr_un& elem) : Wy__ArrayValue< struct sockaddr_un >(s,elem) {};  Wy_Array(const Wy_Array& s) : Wy__ArrayValue< struct sockaddr_un >(s) {};  Wy_Array(Wy_Array& p, Wy::ByMove_t t) : Wy__ArrayValue< struct sockaddr_un >(p,t) {};};*/#endif

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -