yate学习--yateclass.h--class YATE_API Socket : public Stream

请声明出处:

Socket,网络套接字的类,包括创建、绑定、监听、接受、发送、接收等操作:

/**
 * This class encapsulates a system dependent socket in a system independent abstraction
 * 这个类封装了一个依赖于系统的套接字系统独立的抽象
 * @short A generic socket class
 * @short 一般的套接字的类
 */
class YATE_API Socket : public Stream
{
    YNOCOPY(Socket); // no automatic copies please
public:
    /**
     * Types of service
     * 服务类型
     */
    enum TOS {
	Normal         = 0,
	LowDelay       = IPTOS_LOWDELAY,
	MaxThroughput  = IPTOS_THROUGHPUT,
	MaxReliability = IPTOS_RELIABILITY,
	MinCost        = IPTOS_MINCOST,
    };

    /**
     * DiffServ bits
     * 不同的服务器的位数
     */
    enum DSCP {
	DefaultPHB     = 0x00,
	// Class selectors
	CS0            = 0x00,
	CS1            = 0x20,
	CS2            = 0x40,
	CS3            = 0x60,
	CS4            = 0x80,
	CS5            = 0xa0,
	CS6            = 0xc0,
	CS7            = 0xe0,
	// Assured forwarding
	AF11           = 0x28,
	AF12           = 0x30,
	AF13           = 0x38,
	AF21           = 0x48,
	AF22           = 0x50,
	AF23           = 0x58,
	AF31           = 0x68,
	AF32           = 0x70,
	AF33           = 0x78,
	AF41           = 0x88,
	AF42           = 0x90,
	AF43           = 0x98,
	// Expedited forwarding
	ExpeditedFwd   = 0xb8,
	VoiceAdmit     = 0xb0,
    };

    /**
     * Default constructor, creates an invalid socket
     * 默认的构造函数,创建一个有效的套接字
     */
    Socket();

    /**
     * Constructor from an existing handle
     * 构造函数,从一个已经存在的句柄构造
     * @param handle Operating system handle to an existing socket
     * @参数handle,操作系统处理存在的套接字
     */
    explicit Socket(SOCKET handle);

    /**
     * Constructor that also creates the socket handle
     * 构造函数,创建套接字处理句柄
     * @param domain Communication domain for the socket (protocol family)
     * @参数domain,套接字的通信域(协议族)
     * @param type Type specification of the socket
     * @参数type,规范的套接字类型
     * @param protocol Specific protocol for the domain, 0 to use default
     * @参数protocol,域特定的协议,使用默认为0
     */
    Socket(int domain, int type, int protocol = 0);

    /**
     * Destructor - closes the handle if still open
     * 析构函数,如果句柄依旧打开状态则关闭
     */
    virtual ~Socket();

    /**
     * Creates a new socket handle,
     * 创建一个新的套接字句柄
     * @param domain Communication domain for the socket (protocol family)
     * @参数domain,套接字的通信域(协议族)
     * @param type Type specification of the socket
     * @参数type,规范的套接字类型
     * @param protocol Specific protocol for the domain, 0 to use default
     * @参数protocol,域特定的协议,使用默认为0
     * @return True if socket was created, false if an error occured
     * @返回true,如果套接字被创建,false,如果发生了错误
     */
    virtual bool create(int domain, int type, int protocol = 0);

    /**
     * Closes the socket handle, terminates the connection
     * 关闭套接字,结束连接
     * @return True if socket was (already) closed, false if an error occured
     * @返回true,如果套接字被关闭了(早已经被关闭了),false,如果发生了错误
     */
    virtual bool terminate();

    /**
     * Attach an existing handle to the socket, closes any existing first
     * 附加一个已经存在的句柄到套接字,首先关闭另一个存在的
     * @param handle Operating system handle to an existing socket
     * @参数handle,操作系统处理一个已经存在的套接字
     */
    void attach(SOCKET handle);

    /**
     * Detaches the object from the socket handle
     * 从套接字处理中分离对象
     * @return The handle previously owned by this object
     * @返回这个对象先前包含的句柄
     */
    SOCKET detach();

    /**
     * Get the operating system handle to the socket
     * 获得操作系统处理这个套接字的句柄
     * @return Socket handle
     * @返回套接字的句柄
     */
    inline SOCKET handle() const
	{ return m_handle; }

    /**
     * Check if the last error code indicates a retryable condition
     * 检查最后一个错误是否标识一个可重操作的条件
     * @return True if error was temporary and operation should be retried
     * @返回true,如果错误是临时的并且可以重新操作
     */
    virtual bool canRetry() const;

    /**
     * Check if the last error code indicates a non blocking operation in progress
     * 检查最后一个错误码是否标识一个非阻塞的操作正在进行
     * @return True if a non blocking operation is in progress
     * @返回true,如果一个非阻塞的操作正在进行
     */
    virtual bool inProgress() const;

    /**
     * Check if this socket is valid
     * 检查套接字是否有效
     * @return True if the handle is valid, false if it's invalid
     * @返回true,如果句柄有效, false,如果无效
     */
    virtual bool valid() const;

    /**
     * Get the operating system specific handle value for an invalid socket
     * 获得操作系统无效的套接字的特殊句柄
     * @return Handle value for an invalid socket
     * @返回无效套接字的句柄
     */
    static SOCKET invalidHandle();

    /**
     * Get the operating system specific return value of a failed operation
     * 获得操作系统一个失败错误的特殊返回值
     * @return Return value of a failed socket operation
     * @返回失败套接字操作的返回值
     */
    static int socketError();

    /**
     * Retrieve the keyword lookup table for TOS / DSCP values
     * 从表中检索TOS / DSCP 值的关键字
     * @return Pointer to keyword dictionary for TOS and DSCP
     * @返回TOS and DSCP 字典的关键字指针
     */
    static const TokenDict* tosValues();

    /**
     * Set socket options
     * 设置套接字的选项
     * @param level Level of the option to set
     * @参数level,要设置选项的级别
     * @param name Socket option for which the value is to be set
     * @参数name,要设置的套接字选项的值
     * @param value Pointer to a buffer holding the value for the requested option
     * @参数value,保留请求选项值的缓冲区指针
     * @param length Size of the supplied buffer
     * @参数length,提供的缓冲区大小
     * @return True if operation was successfull, false if an error occured
     * @返回true,如果操作成功,false,如果发生错误
     */
    virtual bool setOption(int level, int name, const void* value = 0, socklen_t length = 0);

    /**
     * Set or reset socket IPv6 only option.
     * 设置或者重置IPv6套接字的选项
     * This option will tell to an IPv6 socket to accept only IPv6 packets.
     * 此选项只会告诉IPv6套接字接受IPv6数据包。
     * IPv4 packets will be accepted if disabled.
     * 如果禁用IPv4数据包将被接受。
     * This method will fail for non PF_INET6 sockets
     * 对于非IF_INET6的套接字发方法将会失败
     * @param on True to set, false to reset it
     * @参数on,true,设置,false,重置
     * @return True if operation was successfull, false if an error occured
     * @返回true,操作成功, false,发生了错误
     */
    inline bool setIpv6OnlyOption(bool on) {
#if defined(IPPROTO_IPV6) && defined(IPV6_V6ONLY)
	    int value = on ? 1 : 0;
	    return setOption(IPPROTO_IPV6,IPV6_V6ONLY,&value,sizeof(value));
#else
	    return false;
#endif
	}

    /**
     * Get socket options
     * 获得套接字的选项
     * @param level Level of the option to set
     * @参数level, 要设置的选项级别
     * @param name Socket option for which the value is to be set
     * @参数name,要设置的套接字选项的值
     * @param buffer Pointer to a buffer to return the value for the requested option
     * @参数buffer, 请求选项返回值的缓冲区
     * @param length Pointer to size of the supplied buffer, will be filled on return
     * @参数length,填满缓冲区大小的指针
     * @return True if operation was successfull, false if an error occured
     * @返回true,操作成功, false,发生了错误
     */
    virtual bool getOption(int level, int name, void* buffer, socklen_t* length);

    /**
     * Set specific socket parameters.
     * 设置特定套接字参数。
     * @param params List of parameters
     * @参数params,参数链表
     */
    virtual bool setParams(const NamedList& params)
	{ return false; }

    /**
     * Get specific socket parameters.
     * 获得特定套接字参数
     * @param params Coma separated list of parameters to obtain
     * @参数parms, 要得到的参数
     * @param result List of parameters to fill
     * @参数result,存放参数的链表
     * @return True if operation was successful, false if an error occurred
     * @返回true,操作成功, false,发生了错误
     */
    virtual bool getParams(const String& params, NamedList& result)
	{ return false; }

    /**
     * Set the Type of Service or Differentiated Services Code Point on the IP level of this socket
     * 设置服务类型或者不同的服务器码指向这个套接字的IP
     * @param tos New TOS or DiffServ bits
     * @参数tos,新的TOS或者不同的服务码
     * @return True if operation was successfull, false if an error occured
     * @返回true,如果操作成功,false,如果发生错误
     */
    virtual bool setTOS(int tos);

    /**
     * Set the Type of Service or Differentiated Services Code Point on the IP level of this socket
     * 设置服务类型或者不同的服务器码指向这个套接字的IP
     * @param tos Keyword describing new TOS or DSCP value
     * @param defTos Default TOS or DiffServ value to set if the keyword is not recognized
     * @return True if operation was successfull, false if an error occured
     * @返回true,如果操作成功,false,如果发生错误
     */
    inline bool setTOS(const char* tos, int defTos = Normal)
	{ return setTOS(lookup(tos,tosValues(),defTos)); }

    /**
     * Set the blocking or non-blocking operation mode of the socket
     * 设置套接字阻塞或者非阻塞操作模式
     * @param block True if I/O operations should block, false for non-blocking
     * @参数block,true,阻塞的操作,false 非阻塞
     * @return True if operation was successfull, false if an error occured
     * @返回true,如果操作成功,false,如果发生错误
     */
    virtual bool setBlocking(bool block = true);

    /**
     * Set the local address+port reuse flag of the socket.
     * 设置本地的地址和端口复用标志
     * This method should be called before bind() or it will have no effect.
     * 这个方法必须在bind()之前被调用,否则无效
     * @param reuse True if other sockets may listen on same address+port
     * @参数reuse,true 如果有另外的套接字监听相同的地址+ 端口
     * @param exclusive Grant exclusive access to the address
     * @参数execlusive,授予独占访问地址
     * @return True if operation was successfull, false if an error occured
     * @返回true,如果操作成功,false,如果发生错误
     */
    virtual bool setReuse(bool reuse = true, bool exclusive = false);

    /**
     * Set the way closing a socket is handled
     * 设置关闭套接字句柄的方式
     * @param seconds How much to block waiting for socket to close,
     *  negative to no wait (close in background), zero to reset connection
     * @参数seconeds, 阻塞等待套接字关闭的时间,
     * 负数,不等待(后台关闭),0,重新连接
     * @return True if operation was successfull, false if an error occured
     * @返回true,如果操作成功,false,如果发生错误
     */
    virtual bool setLinger(int seconds = -1);

    /**
     * Associates the socket with a local address
     * 将套接字和本地地址绑定起来
     * @param addr Address to assign to this socket
     * @参数addr,分配到套接字的地址
     * @param addrlen Length of the address structure
     * @参数addrlen,地址套接字的长度
     * @return True if operation was successfull, false if an error occured
     * @返回true,如果操作成功,false,如果发生错误
     */
    virtual bool bind(struct sockaddr* addr, socklen_t addrlen);

    /**
     * Associates the socket with a local address
     * 将套接字和本地地址绑定起来
     * @param addr Address to assign to this socket
     * @参数addr,分配到套接字的地址
     * @return True if operation was successfull, false if an error occured
     * @返回true,如果操作成功,false,如果发生错误
     */
    inline bool bind(const SocketAddr& addr)
	{ return bind(addr.address(), addr.length()); }

    /**
     * Start listening for incoming connections on the socket
     * 开始监听连入的套接字连接
     * @param backlog Maximum length of the queue of pending connections, 0 for system maximum
     * @参数backlog, 挂起的连接队列的最多长度,0 系统最小值
     * @return True if operation was successfull, false if an error occured
     * @返回true,如果操作成功,false,如果发生错误
     */
    virtual bool listen(unsigned int backlog = 0);

    /**
     * Create a new socket for an incoming connection attempt on a listening socket
     * 创建一个新的套接字为一个尝试连接监听套接字
     * @param addr Address to fill in with the address of the incoming connection
     * @参数addr,进入连接的地址
     * @param addrlen Length of the address structure on input, length of address data on return
     * @参数addrlen,地址结构体的长度
     * @return Open socket to the new connection or NULL on failure
     * @返回新连接的套接字或者NULL ,失败
     */
    virtual Socket* accept(struct sockaddr* addr = 0, socklen_t* addrlen = 0);

    /**
     * Create a new socket for an incoming connection attempt on a listening socket
     * 创建一个新的套接字为一个尝试连接监听套接字
     * @param addr Address to fill in with the address of the incoming connection
     * @参数addr,进入连接的地址
     * @return Open socket to the new connection or NULL on failure
     * @返回新连接的套接字或者NULL ,失败
     */
    Socket* accept(SocketAddr& addr);

    /**
     * Create a new socket for an incoming connection attempt on a listening socket
     * 创建一个新的套接字为一个尝试连接监听套接字
     * @param addr Address to fill in with the address of the incoming connection
     * @参数addr,进入连接的地址
     * @param addrlen Length of the address structure on input, length of address data on return
     * @参数addrlen,地址结构体的长度
     * @return Operating system handle to the new connection or @ref invalidHandle() on failure
     * @返回新连接的操作系统句柄或者@ref invalidHandle() 或者失败
     */
    SOCKET acceptHandle(struct sockaddr* addr = 0, socklen_t* addrlen = 0);

    /**
     * Update socket error from socket options.
     * 从网路选项更新网络错误
     * This method should be called when select() indicates a non blocking operation
     *  completed.
     * 这种方法时应该调用select()表示一个非阻塞操作完成。
     * Note: if false is returned, the socket error is the reason of getOption() failure
     * 注意:如果将返回false,套接字错误getOption()失败的原因
     * @return Return true on success
     * @返回true,如果成功
     */
    bool updateError();

    /**
     * Check if select() is efficient on this platform and worth using frequently
     * 检查select()在该平台是否是有效的,并使用频繁
     * @return True if select() is efficiently implemented
     * @返回true,如果select() 是有效的
     */
    static bool efficientSelect();

    /**
     * Check if a socket handle can be used in select
     * 检查套接字句柄是否可选
     * @param handle The socket handle to check
     * @参数handle,要检查套接字句柄
     * @return True if the socket handle can be safely used in select
     * @返回true,如果套接字安全可选
     */
    static bool canSelect(SOCKET handle);

    /**
     * Check if this socket object can be used in a select
     * 检查套接字对象是否可选
     * @return True if this socket can be safely used in select
     * @返回true,如果套接字安全可选
     */
    virtual bool canSelect() const;

    /**
     * Connects the socket to a remote address
     * 连接一个远端的地址
     * @param addr Address to connect to
     * @参数addr,要练级的地址
     * @param addrlen Length of the address structure
     * @参数addrlen,地址长度
     * @return True if operation was successfull, false if an error occured
     * @返回true,如果操作成功,false,如果发生错误
     */
    virtual bool connect(struct sockaddr* addr, socklen_t addrlen);

    /**
     * Connects the socket to a remote address
     * 连接一个远端的地址
     * @param addr Socket address to connect to
     * @参数addr,要练级的地址
     * @return True if operation was successfull, false if an error occured
     * @返回true,如果操作成功,false,如果发生错误
     */
    inline bool connect(const SocketAddr& addr)
	{ return connect(addr.address(), addr.length()); }

    /**
     * Asynchronously connects the socket to a remote address.
     * 异步连接一个远端的地址
     * The socket must be selectable and in non-blocking operation mode
     * 套接字必须是可选的并且是非阻塞模式
     * @param addr Address to connect to
     * @参数addr,要练级的地址
     * @param addrlen Length of the address structure
     * @参数addrlen,地址长度
     * @param toutUs Timeout interval in microseconds
     * @参数toutUs,连接时延(微秒)
     * @param timeout Optional boolean flag to signal timeout
     * @参数timeout,时延信号
     * @return True on success
     * @返回true,成功
     */
    virtual bool connectAsync(struct sockaddr* addr, socklen_t addrlen, unsigned int toutUs,
	bool* timeout = 0);

    /**
     * Asynchronously connects the socket to a remote address.
     * 异步连接一个远端的地址
     * The socket must be selectable and in non-blocking operation mode
     * 套接字必须是可选的并且是非阻塞模式
     * @param addr Socket address to connect to
     * @参数addr,要练级的地址
     * @param toutUs Timeout interval in microseconds
     * @参数toutUs,连接时延(微秒)
     * @param timeout Optional boolean flag to signal timeout
     * @参数timeout,时延信号
     * @return True on success
     * @返回true,成功
     */
    inline bool connectAsync(const SocketAddr& addr, unsigned int toutUs,
	bool* timeout = 0)
	{ return connectAsync(addr.address(),addr.length(),toutUs,timeout); }

    /**
     * Shut down one or both directions of a full-duplex socket.
     * 关闭一个或两个方向的全双工套接字。
     * @param stopReads Request to shut down the read side of the socket
     * @参数stopReads, 请求关闭套接字读取的一面
     * @param stopWrites Request to shut down the write side of the socket
     * @参数stopWrites, 请求关闭套接字写的一面
     * @return True if operation was successfull, false if an error occured
     * @返回true,如果操作成功,false,如果发生错误
     */
    virtual bool shutdown(bool stopReads, bool stopWrites);

    /**
     * Retrieve the address of the local socket of a connection
     * 获得一个连接本地套接字的地址
     * @param addr Address to fill in with the address of the local socket
     * @参数addr,保底套接字的地址
     * @param addrlen Length of the address structure on input, length of address data on return
     * @参数addrlen,地址的长度
     * @return True if operation was successfull, false if an error occured
     * @返回true,如果操作成功,false,如果发生错误
     */
    virtual bool getSockName(struct sockaddr* addr, socklen_t* addrlen);

    /**
     * Retrieve the address of the local socket of a connection
     * 获得一个连接本地套接字的地址
     * @param addr Address to fill in with the address of the local socket
     * @参数addr,保底套接字的地址
     * @return True if operation was successfull, false if an error occured
     * @返回true,如果操作成功,false,如果发生错误
     */
    bool getSockName(SocketAddr& addr);

    /**
     * Retrieve the address of the remote socket of a connection
     * 获得套接字远端的地址
     * @param addr Address to fill in with the address of the remote socket
     * @参数addr,远端地址
     * @param addrlen Length of the address structure on input, length of address data on return
     * @参数addrlen,远端地址长度
     * @return True if operation was successfull, false if an error occured
     * @返回true,如果操作成功,false,如果发生错误
     */
    virtual bool getPeerName(struct sockaddr* addr, socklen_t* addrlen);

    /**
     * Retrieve the address of the remote socket of a connection
     * 获得套接字远端的地址
     * @param addr Address to fill in with the address of the remote socket
     * @参数addr,远端地址
     * @return True if operation was successfull, false if an error occured
     * @返回true,如果操作成功,false,如果发生错误
     */
    bool getPeerName(SocketAddr& addr);

    /**
     * Send a message over a connected or unconnected socket
     * 发送数据到已经连接或者没有连接的套接字
     * @param buffer Buffer for data transfer
     * @参数buffer,数据传输的缓冲区
     * @param length Length of the buffer
     * @参数length,缓冲区的长度
     * @param addr Address to send the message to, if NULL will behave like @ref send()
     * @参数addr,要发送的地址
     * @param adrlen Length of the address structure
     * @参数addr,要发送的地址长度
     * @param flags Operating system specific bit flags that change the behaviour
     * @参数flags,操作系统的特定位标志改变行为
     * @return Number of bytes transferred, @ref socketError() if an error occurred
     * @返回已经发送的数据长度,发生了一个错误
     */
    virtual int sendTo(const void* buffer, int length, const struct sockaddr* addr, socklen_t adrlen, int flags = 0);

    /**
     * Send a message over a connected or unconnected socket
     * 发送数据到已经连接或者没有连接的套接字
     * @param buffer Buffer for data transfer
     * @参数buffer,数据传输的缓冲区
     * @param length Length of the buffer
     * @参数length,缓冲区的长度
     * @param addr Address to send the message to
     * @参数addr,要发送的地址
     * @param flags Operating system specific bit flags that change the behaviour
     * @参数flags,操作系统的特定位标志改变行为
     * @return Number of bytes transferred, @ref socketError() if an error occurred
     * @返回已经发送的数据长度,发生了一个错误
     */
    inline int sendTo(const void* buffer, int length, const SocketAddr& addr, int flags = 0)
	{ return sendTo(buffer, length, addr.address(), addr.length(), flags); }

    /**
     * Send a message over a connected socket
     * 发送数据到已经连接的套接字
     * @param buffer Buffer for data transfer
     * @参数buffer,数据传输的缓冲区
     * @param length Length of the buffer
     * @参数length,缓冲区的长度
     * @param flags Operating system specific bit flags that change the behaviour
     * @参数flags,操作系统的特定位标志改变行为
     * @return Number of bytes transferred, @ref socketError() if an error occurred
     * @返回已经发送的数据长度,发生了一个错误
     */
    virtual int send(const void* buffer, int length, int flags = 0);

    /**
     * Write data to a connected stream socket
     * 写数据到已经连接的套接字
     * @param buffer Buffer for data transfer
     * @参数buffer,数据传输的缓冲区
     * @param length Length of the buffer
     * @参数length,缓冲区的长度
     * @return Number of bytes transferred, @ref socketError() if an error occurred
     * @返回已经写入的数据长度,发生了一个错误
     */
    virtual int writeData(const void* buffer, int length);

    /**
     * Receive a message from a connected or unconnected socket
     * 从一个已经连接或者没有连接的套接字的接收数据
     * @param buffer Buffer for data transfer
     * @参数buffer,数据传输的缓冲区
     * @param length Length of the buffer
     * @参数length,缓冲区的长度
     * @param addr Address to fill in with the address of the incoming data
     * @参数addr,进来数据的地址
     * @param adrlen Length of the address structure on input, length of address data on return
     * @参数adrlen,地址的长度
     * @param flags Operating system specific bit flags that change the behaviour
     * @参数flags,操作系统的特定位标志改变行为
     * @return Number of bytes transferred, @ref socketError() if an error occurred
     * @返回已经接收的数据长度,发生了一个错误
     */
    virtual int recvFrom(void* buffer, int length, struct sockaddr* addr = 0, socklen_t* adrlen = 0, int flags = 0);

    /**
     * Receive a message from a connected or unconnected socket
     * 从一个已经连接或者没有连接的套接字的接收数据
     * @param buffer Buffer for data transfer
     * @参数buffer,数据传输的缓冲区
     * @param length Length of the buffer
     * @参数length,缓冲区的长度
     * @param addr Address to fill in with the address of the incoming data
     * @参数addr,进来数据的地址
     * @param flags Operating system specific bit flags that change the behaviour
     * @参数flags,操作系统的特定位标志改变行为
     * @return Number of bytes transferred, @ref socketError() if an error occurred
     * @返回已经接收的数据长度,发生了一个错误
     */
    int recvFrom(void* buffer, int length, SocketAddr& addr, int flags = 0);

    /**
     * Receive a message from a connected socket
     * 从一个已经连接的套接字的接收数据
     * @param buffer Buffer for data transfer
     * @参数buffer,数据传输的缓冲区
     * @param length Length of the buffer
     * @参数length,缓冲区的长度
     * @param flags Operating system specific bit flags that change the behaviour
     * @参数flags,操作系统的特定位标志改变行为
     * @return Number of bytes transferred, @ref socketError() if an error occurred
     * @返回已经接收的数据长度,发生了一个错误
     */
    virtual int recv(void* buffer, int length, int flags = 0);

    /**
     * Receive data from a connected stream socket
     * 从一个已经连接的套接字的接收数据
     * @param buffer Buffer for data transfer
     * @参数buffer,数据传输的缓冲区
     * @param length Length of the buffer
     * @参数length,缓冲区的长度
     * @return Number of bytes transferred, @ref socketError() if an error occurred
     * @返回已经接收的数据长度,发生了一个错误
     */
    virtual int readData(void* buffer, int length);

    /**
     * Determines the availability to perform synchronous I/O of the socket
     * 确定可用性执行同步套接字I / O
     * @param readok Address of a boolean variable to fill with readability status
     * @参数readok,可读状态地址
     * @param writeok Address of a boolean variable to fill with writeability status
     * @参数writeok,可写状态地址
     * @param except Address of a boolean variable to fill with exceptions status
     * @参数except,异常状态地址
     * @param timeout Maximum time until the method returns, NULL for blocking
     * @参数timeout,最长时间方法返回之前,NULL阻塞
     * @return True if operation was successfull, false if an error occured
     * @返回true,如果操作成功,false,如果发生错误
     */
    virtual bool select(bool* readok, bool* writeok, bool* except, struct timeval* timeout = 0);

    /**
     * Determines the availability to perform synchronous I/O of the socket
     * 确定可用性执行同步套接字I / O
     * @param readok Address of a boolean variable to fill with readability status
     * @参数readok,可读状态地址
     * @param writeok Address of a boolean variable to fill with writeability status
     * @参数writeok,可写状态地址
     * @param except Address of a boolean variable to fill with exceptions status
     * @参数except,异常状态地址
     * @param timeout Maximum time until the method returns, -1 for blocking
     * @参数timeout,最长时间方法返回之前,-1阻塞
     * @return True if operation was successfull, false if an error occured
     * @返回true,如果操作成功,false,如果发生错误
     */
    bool select(bool* readok, bool* writeok, bool* except, int64_t timeout);

    /**
     * Install a new packet filter in the socket
     * 在套接字中安装一个新的滤包器
     * @param filter Pointer to the packet filter to install
     * @参数filter,要安装的滤包器
     * @return True if the filter was installed
     * @返回true,如果被安装了
     */
    bool installFilter(SocketFilter* filter);

    /**
     * Removes a packet filter and optionally destroys it
     * 删除一个数据包过滤和选择性地破坏它
     * @param filter Pointer to the packet filter to remove from socket
     * @参数filter,要从套接字中移除的滤包器。
     * @param delobj Set to true to also delete the filter
     * @参数delobj,设置为true, 同时删除
     */
    void removeFilter(SocketFilter* filter, bool delobj = false);

    /**
     * Removes and destroys all packet filters
     * 移除并且销毁所有包的过滤器
     */
    void clearFilters();

    /**
     * Run whatever actions required on idle thread runs.
     * 在空闲运行线程运行任何需要的操作
     * The default implementation calls @ref SocketFilter::timerTick()
     * 所有安装了的过滤器默认实现调用@ref SocketFilter::timerTick()
     *  for all installed filters.
     * @param when Time when the idle run started
     * @参数when,空闲开始运行的时间
     */
    virtual void timerTick(const Time& when);

    /**
     * Create a pair of bidirectionally connected sockets
     * 创建一对双向连接的套接字
     * @param sock1 Reference to first Socket to be paired
     * @参数sock1,第一个套接字
     * @param sock2 Reference to second Socket to be paired
     * @参数sock2,第二个套接字
     * @param domain Communication domain for the sockets (protocol family)
     * @参数domain,套接字通信域
     * @return True is the stream pair was created successfully
     * @返回true,创建成功
     */
    static bool createPair(Socket& sock1, Socket& sock2, int domain = AF_UNIX);

protected:

    /**
     * Copy the last error code from the operating system
     * 从操作系统返回最后的错误码
     */
    void copyError();

    /**
     * Copy the last error code from the operating system if an error occured, clear if not
     * 从操作系统中拷贝最后一个错误码,如果发生错误,如果没有发生,清理
     * @param retcode Operation return code to check, 0 for success
     * @参数recode,操作的返回码,0 代表成功
     * @param strict True to consider errors only return codes of @ref socketError()
     * @参数strict,true, 认为错误只从socketError()的返回码
     * @return True if operation succeeded (retcode == 0), false otherwise
     * @返回true操作成功,除此之外为false
     */
    bool checkError(int retcode, bool strict = false);

    /**
     * Apply installed filters to a received block of data
     * 申请安装一个过滤器用于接收的数据块
     * @param buffer Buffer for received data
     * @参数buffer,接收数据的缓冲区
     * @param length Length of the data in buffer
     * @参数length,数据缓冲区的长度
     * @param flags Operating system specific bit flags of the operation
     * @参数flags,操作系统操作的特定位标志
     * @param addr Address of the incoming data, may be NULL
     * @参数addr,进入数据的地址,可能为NULL
     * @param adrlen Length of the valid data in address structure
     * @参数addrlen, 有效数据地址结构的长度
     * @return True if one of the filters claimed the data
     * @返回true,如果过滤器拦截下数据
     */
    bool applyFilters(void* buffer, int length, int flags, const struct sockaddr* addr = 0, socklen_t adrlen = 0);

    SOCKET m_handle;
    ObjList m_filters;
};
时间: 2024-11-10 15:11:04

yate学习--yateclass.h--class YATE_API Socket : public Stream的相关文章

yate学习--yateclass.h--class YATE_API NamedCounter : public String

请声明出处: NamedCounter,对象命名的计数器: /** * An atomic counter with an associated name * 关联名的原子计数器 * @short Atomic counter with name * @short 名字的原子计数器 */ class YATE_API NamedCounter : public String { YNOCOPY(NamedCounter); // no automatic copies please public

yate学习--yateclass.h--class YATE_API RefObject : public GenObject

请声明出处: 对象的引用计数的类,基本大部分的类都继承了该类: /** * A reference counted object. * 引用计数的对象 * Whenever using multiple inheritance you should inherit this class virtually. * 使用多重继承,一般都会继承这个类 */ class YATE_API RefObject : public GenObject { YNOCOPY(RefObject); // no a

yate学习--yateclass.h--class YATE_API DebugEnabler

请声明转载出: DebugEnabler,这个类用于保存和修改调试级别,也就是日志的打印级别: /** * Holds a local debugging level that can be modified separately from the * global debugging * 保留本地的调试级别,这个级别能被个别的全局调试修改 * @short A holder for a debug level * @short 保存一个调试级别 */ class YATE_API DebugE

yate学习--yateclass.h--class YATE_API Stream

转载说明: yate中所有基于流操作的基类: /** * Base class for encapsulating system dependent stream capable objects * 封装能够基于系统的流对象的基类 * @short An abstract stream class capable of reading and writing * @short 能够读和写的抽象类 */ class YATE_API Stream { public: /** * Enumerate

yate学习--yatengine.h--class YATE_API MessageReceiver : public GenObject

请声明出处: MessageReceiver,这个类是一个消息接受的基类: /** * A multiple message receiver to be invoked by a message relay * 多个消息接收器调用消息传递 * @short A multiple message receiver * @short 多个消息接收器 */ class YATE_API MessageReceiver : public GenObject { public: /** * This m

Android socket 学习记录 之 执行new socket(ip, port)程序崩溃

这段时间在学习Android的socket编程,我不是专做APP的,做的是bootloader.驱动.hal.framework这个线的,也就是系统搭建和功能优化设计.为了打通这整条线,为此学习了不少东西,今天把Android的socket学习记录一下,以防止以后会出现这样的低级错误. 我这里是在极客学院的源码基础上做的自己的一些添加和修改,学习开始不就是先会修改么,举一反三,自然就很快学会了.由于看过视频和资料后就迫不及待的按照自己的想法想做一个功能,但是遇到麻烦了,就是执行new socke

yate学习--./yate/packingyate.logrotate

上一篇文章记录了yate学习--./yate/tools/log_rotate.sh: 今天继续看和日志部分的脚本./yate/packingyate.logrotate,先看看脚本源码. # Have to rotate the log and CDR files before each reaches 2GB in size /var/log/yate /var/log/yate-cdr.tsv { size=100M rotate 5 missingok sharedscripts not

Socket编程学习之道:揭开Socket编程的面纱

对TCP/IP.UDP.Socket编程这些词你不会很陌生吧?随着网络技术的发展,这些词充斥着我们的耳朵.那么我想问: 1.         什么是TCP/IP.UDP? 2.         Socket在哪里呢? 3.         Socket是什么呢? 4.         你会使用它们吗? 什么是TCP/IP.UDP? TCP/IP(Transmission Control Protocol/Internet Protocol)即传输控制协议/网间协议,是一个工业标准的协议集,它是为

yate学习--yatesip.h--class YSIP_API SIPMessage : public RefObject

请声明出处:http://blog.csdn.net/u012377333/article/details/45917579 本文开始详细的学习yate里面自定义的SIP协议库,消息体的定义: /** * An object that holds the sip message parsed into this library model. * 一个保存被解析的sip信息到这个库模型的对象 * This class can be used to parse a sip message from