fastdo  0.5.12
eiennet::ip::udp::Socket类 参考

UDP/IP套接字 更多...

#include <eiennet_socket.hpp>

类 eiennet::ip::udp::Socket 继承关系图:
eiennet::ip::udp::Socket 的协作图:

Public 类型

typedef eiennet::Socket BaseClass
 
- Public 类型 继承自 eiennet::Socket
enum  AddrFamily {
  afUnspec = 0, afLocal = 1, afUnix = afLocal, afFile = afLocal,
  afInet = 2, afAx25 = 3, afIpx = 4, afAppletalk = 5,
  afNetrom = 6, afBridge = 7, afAtmpvc = 8, afX25 = 9,
  afInet6 = 10, afRose = 11, afDecnet = 12, afNetbeui = 13,
  afSecurity = 14, afKey = 15, afNetlink = 16, afRoute = afNetlink,
  afPacket = 17, afAsh = 18, afEconet = 19, afAtmsvc = 20,
  afRds = 21, afSna = 22, afIrda = 23, afPppox = 24,
  afWanpipe = 25, afLlc = 26, afUnknown27 = 27, afUnknown28 = 28,
  afCan = 29, afTipc = 30, afBluetooth = 31, afIucv = 32,
  afRxrpc = 33, afIsdn = 34, afPhonet = 35, afIeee802154 = 36,
  afMax = 37
}
 
enum  SockType {
  sockUnknown, sockStream, sockDatagram, sockRaw,
  sockRdm, sockSeqPacket, sockDccp, sockPacket,
  sockCloexec, sockNonblock
}
 
enum  Protocol {
  protoIp = 0, protoIcmp, protoIgmp, protoIpip,
  protoIpv4 = protoIpip, protoTcp, protoEgp, protoPup,
  protoUdp, protoIdp, protoTp, protoDccp,
  protoIpv6, protoRsvp, protoGre, protoEsp,
  protoAh, protoMtp, protoBeetph, protoEncap,
  protoPim, protoComp, protoSctp, protoUdplite,
  protoRaw, protoMax
}
 
typedef std::function< void(int hadBytes, void *param) > FunctionSuccessCallback
 

Public 成员函数

 Socket (int sock, bool isNewSock=false)
 构造函数1,包装现有socket描述符 更多...
 
 Socket ()
 构造函数2,新建一个udp socket. 更多...
 
 Socket (Socket &&other)
 移动构造函数 更多...
 
Socketoperator= (Socket &&other)
 移动赋值操作 更多...
 
int sendTo (winux::String const &ipAddr, winux::ushort port, void const *data, int size, int msgFlags=MsgDefault)
 
int recvFrom (winux::String *ipAddr, winux::ushort *port, void *buf, int size, int msgFlags=MsgDefault)
 
- Public 成员函数 继承自 eiennet::Socket
 Socket (int sock=-1, bool isNewSock=false)
 构造函数1,包装现有socket描述符 更多...
 
 Socket (AddrFamily af, SockType sockType, Protocol proto)
 构造函数2,根据'地址簇','类型','协议'新建一个socket. 更多...
 
 Socket (Socket &&other)
 移动构造函数 更多...
 
Socketoperator= (Socket &&other)
 移动赋值操作 更多...
 
virtual ~Socket ()
 
bool create (AddrFamily af, SockType sockType, Protocol proto)
 根据'地址簇','类型','协议'创建一个socket 更多...
 
int close ()
 关闭socket描述符 更多...
 
int shutdown (int how=SdReceive)
 关掉socket的相应操作,但并不会close套接字。 更多...
 
int send (void const *data, int size, int msgFlags=MsgDefault)
 发送数据 更多...
 
int send (winux::AnsiString const &data, int msgFlags=MsgDefault)
 发送数据 更多...
 
int send (winux::Buffer const &data, int msgFlags=MsgDefault)
 发送数据 更多...
 
bool sendUntil (int targetSize, void const *data, int msgFlags=MsgDefault)
 发送数据,直到发送完指定大小的数据。 更多...
 
bool sendUntil (winux::AnsiString const &data, int msgFlags=MsgDefault)
 
bool sendUntil (winux::Buffer const &data, int msgFlags=MsgDefault)
 
int sendWaitUntil (int targetSize, void const *data, int *hadSent, double sec, int *rcWait, FunctionSuccessCallback eachSuccessCallback=FunctionSuccessCallback(), void *param=nullptr, int msgFlags=MsgDefault)
 发送数据,直到发送完指定大小的数据或超时。*hadSent表示已发送的数据请初始化为0;;sec表示超时值,sec<0则一直等待。 更多...
 
int sendWaitUntil (winux::AnsiString const &data, int *hadSent, double sec, int *rcWait, FunctionSuccessCallback eachSuccessCallback=FunctionSuccessCallback(), void *param=nullptr, int msgFlags=MsgDefault)
 
int sendWaitUntil (winux::Buffer const &data, int *hadSent, double sec, int *rcWait, FunctionSuccessCallback eachSuccessCallback=FunctionSuccessCallback(), void *param=nullptr, int msgFlags=MsgDefault)
 
template<typename _PodType >
bool sendUntilType (_PodType const &v, int msgFlags=MsgDefault)
 发送一个Plain of Data类型的变量,若成功返回true,否则返回false。 更多...
 
int recv (void *buf, int size, int msgFlags=MsgDefault)
 尝试接收size大小数据,返回实际接收的数据大小或错误。 更多...
 
winux::Buffer recv (int size, int msgFlags=MsgDefault)
 尝试接收size大小数据,返回实际收到的数据Buffer。 更多...
 
bool recvUntilTarget (winux::AnsiString const &target, winux::GrowBuffer *data, winux::GrowBuffer *extraData, int msgFlags=MsgDefault)
 接收数据,直到碰到target指定的数据。data返回接收到的数据,data里可以已有部分数据,extraData返回额外接收的数据。 更多...
 
int recvWaitUntilTarget (winux::AnsiString const &target, winux::GrowBuffer *data, winux::GrowBuffer *extraData, int *hadRead, int *startpos, int *pos, double sec, int *rcWait, FunctionSuccessCallback eachSuccessCallback=FunctionSuccessCallback(), void *param=nullptr, int msgFlags=MsgDefault)
 接收数据,直到碰到target指定的数据或者超时。*startpos表示搜索起始位置并返回下一次搜索位置;*pos返回搜到指定数据的位置,data返回接收到的数据,data里可以已有部分数据;extraData返回额外接收的数据;sec表示超时值,sec<0则一直等待。 更多...
 
bool recvUntilSize (int targetSize, winux::GrowBuffer *data, int msgFlags=MsgDefault)
 接收数据,直到收到指定大小的数据。data返回接收到的数据。 更多...
 
int recvWaitUntilSize (int targetSize, winux::GrowBuffer *data, int *hadRead, double sec, int *rcWait, FunctionSuccessCallback eachSuccessCallback=FunctionSuccessCallback(), void *param=nullptr, int msgFlags=MsgDefault)
 接收数据,直到收到指定大小的数据或者超时。*hadRead表示已读的数据请初始设为0;data返回接收到的数据;sec表示超时值,sec<0则一直等待。 更多...
 
template<typename _PodType >
bool recvUntilType (_PodType *v, int msgFlags=MsgDefault)
 接收一个Plain of Data类型的变量,若成功返回true,否则返回false。 更多...
 
winux::Buffer recvAvail (int msgFlags=MsgDefault)
 接收不用阻塞即可接收的数据,返回收到的数据Buffer。 更多...
 
winux::Buffer recvWaitAvail (double sec, int *rcWait, int msgFlags=MsgDefault)
 接收已到达的数据,如果没有到达数据则等待有数据到达或超过指定时间,返回收到的数据Buffer。 更多...
 
int sendTo (EndPoint const &ep, void const *data, int size, int msgFlags=MsgDefault)
 发送数据到 更多...
 
int recvFrom (EndPoint *ep, void *buf, int size, int msgFlags=MsgDefault)
 接收数据从 更多...
 
bool connect (EndPoint const &ep)
 连接服务器 更多...
 
bool bind (EndPoint const &ep)
 socket绑定地址 更多...
 
bool listen (int backlog)
 监听 更多...
 
bool accept (int *sock, EndPoint *ep=NULL)
 接受一个客户连接 更多...
 
winux::SharedPointer< Socketaccept (EndPoint *ep=NULL)
 接受一个客户连接 更多...
 
int getRecvBufSize () const
 获取接收缓冲区大小 更多...
 
bool setRecvBufSize (int optval)
 设置接收缓冲区大小 更多...
 
int getSendBufSize () const
 获取发送缓冲区大小 更多...
 
bool setSendBufSize (int optval)
 设置发送缓冲区大小 更多...
 
winux::uint32 getRecvTimeout () const
 获取接收超时(ms) 更多...
 
bool setRecvTimeout (winux::uint32 optval)
 设置接收超时(ms) 更多...
 
winux::uint32 getSendTimeout () const
 获取发送超时(ms) 更多...
 
bool setSendTimeout (winux::uint32 optval)
 设置发送超时(ms) 更多...
 
bool getReUseAddr () const
 获取是否开启了重用地址 更多...
 
bool setReUseAddr (bool optval)
 设置socket是否重用地址,默认false不重用 更多...
 
bool getBroadcast () const
 获取是否启用广播 更多...
 
bool setBroadcast (bool optval)
 设置socket是否广播,默认false非广播 更多...
 
int getError () const
 通过getsockopt()+SO_ERROR获取仅属于socket的错误 更多...
 
SockType getType () const
 获取socket类型 更多...
 
bool isListening () const
 socket是否为监听模式 更多...
 
int getAvailable () const
 获取可不阻塞接收的数据量 更多...
 
bool setBlocking (bool blocking)
 设置socket阻塞模式,true为阻塞,false为非阻塞。 更多...
 
int get () const
 Windows:socket句柄,或Linux:socket描述符 更多...
 
 operator bool () const
 判断Socket是否有效 更多...
 

额外继承的成员函数

- 静态 Public 成员函数 继承自 eiennet::Socket
static int ErrNo ()
 从errno获取错误码 更多...
 
- 静态 Public 属性 继承自 eiennet::Socket
static int const MsgDefault
 
static int const MsgOob
 
static int const MsgPeek
 
static int const MsgDontRoute
 
static int const MsgWaitAll
 
static int const MsgPartial
 
static int const MsgInterrupt
 
static int const MsgMaxIovLen
 
static int const SdReceive
 
static int const SdSend
 
static int const SdBoth
 
- Protected 属性 继承自 eiennet::Socket
winux::MembersWrapper< struct Socket_Data > _self
 

详细描述

UDP/IP套接字

在文件 eiennet_socket.hpp639 行定义.

成员类型定义说明

构造及析构函数说明

eiennet::ip::udp::Socket::Socket ( int  sock,
bool  isNewSock = false 
)
inlineexplicit

构造函数1,包装现有socket描述符

参数
socksocket描述符(Windows平台是socket句柄)
isNewSock指示是否为新建socket. 如果为true,则会在Socket destroy时,自动close(sock).

在文件 eiennet_socket.hpp648 行定义.

eiennet::ip::udp::Socket::Socket ( )
inline

构造函数2,新建一个udp socket.

在文件 eiennet_socket.hpp651 行定义.

eiennet::ip::udp::Socket::Socket ( Socket &&  other)
inline

移动构造函数

在文件 eiennet_socket.hpp655 行定义.

成员函数说明

Socket& eiennet::ip::udp::Socket::operator= ( Socket &&  other)
inline

移动赋值操作

在文件 eiennet_socket.hpp657 行定义.

int eiennet::ip::udp::Socket::recvFrom ( winux::String ipAddr,
winux::ushort port,
void *  buf,
int  size,
int  msgFlags = MsgDefault 
)
int eiennet::ip::udp::Socket::sendTo ( winux::String const &  ipAddr,
winux::ushort  port,
void const *  data,
int  size,
int  msgFlags = MsgDefault 
)
inline

在文件 eiennet_socket.hpp664 行定义.


该类的文档由以下文件生成: