POCO库中文编程参考指南(3)Poco::Net::Socket

时间:2022-09-17 00:00:15

POCO库中文编程参考指南(3)Poco::Net::Socket

  • 作者:柳大·Poechant
  • 博客:Blog.CSDN.net/Poechant
  • 邮箱:zhongchao.ustc#gmail.com (# -> @)
  • 日期:April 14th, 2012

1 SelectMode

enum SelectMode
/// The mode argument to poll() and select().
{
SELECT_READ = 1,
SELECT_WRITE = 2,
SELECT_ERROR = 4
};

2 SocketList

typedef std::vector<Socket> SocketList;

3 构造函数

未初始化的 socket:

Socket();

拷贝构造函数

Socket(const Socket& socket);

4 重载运算符

赋值运算符:

Socket& operator = (const Socket& socket);

比较运算符:

bool operator == (const Socket& socket) const;
bool operator != (const Socket& socket) const;
bool operator < (const Socket& socket) const;
bool operator <= (const Socket& socket) const;
bool operator > (const Socket& socket) const;
bool operator >= (const Socket& socket) const;

5 常用 socket 操作

返回该 socket 的可读数据的字节数,该操作不引起 socket 阻塞:

int available() const;

关闭 socket:

void close();

poll:

bool poll(const Poco::Timespan& timeout, int mode) const;
/// Determines the status of the socket, using a
/// call to select().
///
/// The mode argument is constructed by combining the values
/// of the SelectMode enumeration.
///
/// Returns true if the next operation corresponding to
/// mode will not block, false otherwise. SocketImpl* impl() const;
/// Returns the SocketImpl for this socket.

检查这个 socket 的连接是否是安全的(使用 SSL 或 TLS):

bool secure() const;

6 缓冲区

发送数据的缓冲区:

void setSendBufferSize(int size);
int getSendBufferSize() const;

接收数据的缓冲区:

void setReceiveBufferSize(int size);
int getReceiveBufferSize() const;

7 超时时间

发送数据的超时时间:

void setSendTimeout(const Poco::Timespan& timeout);
Poco::Timespan getSendTimeout() const;

接收数据的超时时间:

void setReceiveTimeout(const Poco::Timespan& timeout);
Poco::Timespan getReceiveTimeout() const;

8 其他接口

void setOption(int level, int option, int value);
void setOption(int level, int option, unsigned value);
void setOption(int level, int option, unsigned char value);
void setOption(int level, int option, const Poco::Timespan& value);
void setOption(int level, int option, const IPAddress& value); void getOption(int level, int option, int& value) const;
void getOption(int level, int option, unsigned& value) const;
void getOption(int level, int option, unsigned char& value) const;
void getOption(int level, int option, Poco::Timespan& value) const;
void getOption(int level, int option, IPAddress& value) const; void setLinger(bool on, int seconds);
void getLinger(bool& on, int& seconds) const; void setNoDelay(bool flag);
bool getNoDelay() const; void setKeepAlive(bool flag);
bool getKeepAlive() const; void setReuseAddress(bool flag);
bool getReuseAddress() const; void setReusePort(bool flag);
bool getReusePort() const; void setOOBInline(bool flag);
bool getOOBInline() const; void setBlocking(bool flag);
bool getBlocking() const;

获取 socket 的 IP 和端口:

SocketAddress address() const;

获取 peer socket 的 IP 地址和端口:

SocketAddress peerAddress() const;

9 静态函数

select:

static int select(SocketList& readList,
SocketList& writeList,
SocketList& exceptList,
const Poco::Timespan& timeout); /// Determines the status of one or more sockets,
/// using a call to select().
///
/// ReadList contains the list of sockets which should be
/// checked for readability.
///
/// WriteList contains the list of sockets which should be
/// checked for writeability.
///
/// ExceptList contains a list of sockets which should be
/// checked for a pending error.
///
/// Returns the number of sockets ready.
///
/// After return,
/// * readList contains those sockets ready for reading,
/// * writeList contains those sockets ready for writing,
/// * exceptList contains those sockets with a pending error.
///
/// If the total number of sockets passed in readList, writeList and
/// exceptList is zero, select() will return immediately and the
/// return value will be 0.
///
/// If one of the sockets passed to select() is closed while
/// select() runs, select will return immediately. However,
/// the closed socket will not be included in any list.
/// In this case, the return value may be greater than the sum
/// of all sockets in all list.

检查是否支持 IPv4 或 IPv6:

static bool supportsIPv4();
static bool supportsIPv6();

-

from:Blog.CSDN.net/Poechant

POCO库中文编程参考指南(3)Poco::Net::Socket的更多相关文章

  1. POCO库中文编程参考指南(4)Poco&colon;&colon;Net&colon;&colon;IPAddress

    POCO库中文编程参考指南(4)Poco::Net::IPAddress 作者:柳大·Poechant 博客:Blog.CSDN.net/Poechant 邮箱:zhongchao.ustc#gmai ...

  2. POCO库中文编程参考指南(2)基本数据类型(Poco&sol;Types&period;h)

    POCO库中文编程参考指南(2)基本数据类型 作者:柳大·Poechant 博客:Blog.CSDN.net/Poechant 邮箱:zhongchao.ustc#gmail.com (# -> ...

  3. POCO库中文编程参考指南(1)总览

    POCO库中文编程参考指南(1)总览 作者:柳大·Poechant 博客:Blog.CSDN.net/Poechant 邮箱:zhongchao.ustc#gmail.com (# -> @) ...

  4. POCO库中文编程参考指南(11)如何使用Reactor框架?

    1 Reactor 框架概述 POCO 中的 Reactor 框架是基于 Reactor 设计模式进行设计的.其中由 Handler 将某 Socket 产生的事件,发送到指定的对象的方法上,作为回调 ...

  5. POCO库中文编程参考指南(8)丰富的Socket编程

    POCO库中文编程参考指南(8)丰富的Socket编程 作者:柳大·Poechant 博客:Blog.CSDN.net/Poechant 邮箱:zhongchao.ustc#gmail.com (# ...

  6. POCO库中文编程参考指南(10)如何使用TCPServer框架?

    1 TCPServer 框架概述 POCO 库提供TCPServer框架,用以搭建自定义的 TCP 服务器.TCPServer维护一个连接队列.一个连接线程池.连接线程用于处理连接,连接线程只要一空闲 ...

  7. POCO库中文编程参考指南(9)Poco&colon;&colon;Net&colon;&colon;DNS

    1 Poco::Net::DNS namespace Poco { namespace Net { class Net_API DNS { public: static HostEntry hostB ...

  8. POCO库中文编程参考指南(5)Poco&colon;&colon;Net&colon;&colon;SocketAddress

    1 枚举 最大地址长度,这个与Poco::Net::IPAddress中的定义可以类比,不过这里指的是`struct sockaddr_in6 enum { MAX_ADDRESS_LENGTH = ...

  9. POCO库中文编程参考指南(6)Poco&colon;&colon;Timestamp

    1 类型别名 三个时间戳相关的类型别名,TimeDiff表示两个时间戳的差,第二个是以微秒为单位的时间戳,第三个是以 100 纳秒(0.1 微妙)为单位的时间戳: typedef Int64 Time ...

随机推荐

  1. 网站常用UI整理

    1.UI插件包使用   Bootstrap 地址:http://v3.bootcss.com/getting-started/     Bootstrap buttons 按钮 地址:http://w ...

  2. Spark External Datasets

    Spark能够从任何支持Hadoop的存储源来创建RDD,包括本地的文件系统,HDFS,Cassandra,Hbase,Amazon S3等.Spark支持textFile.SequenceFiles ...

  3. GCD基础知识总结

    iOS三种多线程编程技术: 1.NSThread 2.NSOperation 3.GCD(Grand Central Dispatch) 从上到下,抽象度层次从低到高,抽象度越高的使用越简单,也是Ap ...

  4. ScheduledExecutorService定时周期执行指定的任务

    示例代码 package com.effective.common.concurrent.execute; import java.text.DateFormat; import java.text. ...

  5. Corelocation及地图控件学习笔记

    Corelocation基本使用 在地图章节的学习中,首先要学的便是用户位置定位,因此我们首先要掌握Corelocation的使用.(在IOS8以前可以系统会直接请求授权,现在需要我们自己调用方式通知 ...

  6. 详解如何在linuxmint上用源码包安装nodejs

    第一步:安装依赖包   因为Linuxmint 和 Ubuntu 同属 Debian系的Linux,而且Linuxmint是建立在Ubuntu的基础上的,所以Ubuntu下的命令和包,Linuxmin ...

  7. 给class添加id封装

    <!doctype html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  8. mybatis 存储过程调用

    接口 UserInfoMapper.java xml   UserInfoMapper.xml 如何关联 <?xml version="1.0" encoding=&quot ...

  9. java mutilThread

    可以参考https://www.cnblogs.com/wxd0108/p/5479442.html 这里补充一下我理解多线程这部分的一些要点. 1.首先是java的monitor概念:https:/ ...

  10. kali&lowbar;linux学习笔记

    kali linux ssh登陆: 一.配置SSH参数 修改sshd_config文件,命令为: vi /etc/ssh/sshd_config 将#PasswordAuthentication no ...