📄 wy_sockaddr.h
字号:
/* Copyright is licensed under GNU LGPL. by I.J.Wang 2003 Base protocol class of socket address.*/#ifndef WY_SOCKADDR_H__#define WY_SOCKADDR_H__#define WY_SOCKADDR_VERSION 31#include "wyret.h"#include <sys/types.h>#include <sys/socket.h>#include <string.h> // for memcpyclass WyStr;/* note: Wy::wrd(const Wy_SockAddr&) is reserved(use notation member) Because wrd for each socket address is defined and a question in mind that wrd(const Wy_SockAddr&) might need to output the address type .caller has enough info. to convert back*/class Wy_SockAddr { friend class WySockFile; public: virtual ~Wy_SockAddr() {}; int family(void) const WY__TSPC() { return this->c_sockaddr().sa_family; }; virtual WyRet notation(WyStr& str) const=0; // [Syn] // std::memcpy(&this->c_sockaddr(),&src.c_sockaddr(),src.c_addrlen()); // *this->c_addrlen=*src.c_addrlen(); // // Note: Application ensure that this->c_sockaddr_size()>=src.c_addrlen, // or address structure is overwritten. // // Note: This member may be called in constructor // This member is to avoid exposure c_sockadddr().. in public // interface /* void _copy_sockaddr(const Wy_SockAddr& src) WY__TSPC() { std::memcpy(&this->c_sockaddr(),&src.c_sockaddr(),src.c_addrlen()); this->c_addrlen()=src.c_addrlen(); };*/ protected: // [Internal] Reset the address // // Note: sockaddr.sa_family is setup by the derived class and should // be constant throughout object life time. // // [Throw] No Reply is thrown // virtual void reset(void) WY__TSPC()=0; // [Syn] Interchange object state of *this with saddr // // [Ret] Ok // Wym_EBADTYPE // virtual WyRet _swap(Wy_SockAddr& saddr) WY__TSPC()=0; // [Internal] Allocate an default object (use delete to destroy) // and reset ptr to point to it. // // [Throw] No Reply is thrown // // [Ret] Ok // Wym_ENOMEM // Wym_ENOSYS Not overridden // ... (From constructing the default object) // virtual Wy_SockAddr* _alloc(WyRet& r) const=0; // [Internal] Get address of the underlying sockaddr structure // // Note: Derived class should always setup sockaddr.sa_family data member. // Codes in WySockFile depends on this to identify the data structure. // // struct ::sockaddr& c_sockaddr(void) // size_t c_sockaddr_size(void) const // socklen_t& c_addrlen(void) // // Note: These membesr may be called in constructor of this object // Function behavior can not depend on *this object state // // [Ret] address of struct sockaddr // virtual struct ::sockaddr& c_sockaddr(void) WY__TSPC()=0; virtual const struct ::sockaddr& c_sockaddr(void) const WY__TSPC()=0; // [Internal] Get the size that c_sockaddr() pointed to // (the maximumal char size pointed by c_sockaddr) // This value is normally written to *c_addrlen when // calling accept/getsockname/getpeername // .sizeof the structure pointed by c_sockaddr // [Ret] The buffer size c_sockaddr() pointed to // virtual size_t c_sockaddr_size(void) const WY__TSPC()=0; // [Internal] Get/Set the effective length of the address structure // pointed by c_sockaddr (<=c_sockaddr_size) // // [Ret] Address of the variable that specifies the valid data // length c_sockaddr() pointed. // virtual socklen_t& c_addrlen(void) WY__TSPC()=0; virtual const socklen_t& c_addrlen(void) const WY__TSPC()=0;};#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -