2019-07-28 10:31:56 +08:00
|
|
|
|
#pragma once
|
2017-06-02 14:47:24 +08:00
|
|
|
|
#include "../acl_cpp_define.hpp"
|
2015-06-29 17:33:11 +08:00
|
|
|
|
#if defined(_WIN32) || defined(_WIN64)
|
2014-11-19 00:25:21 +08:00
|
|
|
|
#include <WinSock2.h>
|
|
|
|
|
#endif
|
2019-08-20 17:17:37 +08:00
|
|
|
|
#include <string>
|
2017-06-02 14:47:24 +08:00
|
|
|
|
#include "istream.hpp"
|
|
|
|
|
#include "ostream.hpp"
|
2014-11-19 00:25:21 +08:00
|
|
|
|
|
|
|
|
|
struct ACL_VSTREAM;
|
|
|
|
|
|
|
|
|
|
namespace acl {
|
|
|
|
|
|
|
|
|
|
class ACL_CPP_API socket_stream
|
|
|
|
|
: public istream
|
|
|
|
|
, public ostream
|
|
|
|
|
{
|
|
|
|
|
public:
|
2018-09-16 21:49:58 +08:00
|
|
|
|
socket_stream(void);
|
|
|
|
|
virtual ~socket_stream(void);
|
2014-11-19 00:25:21 +08:00
|
|
|
|
|
|
|
|
|
/**
|
2019-07-28 10:31:56 +08:00
|
|
|
|
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ִ<EFBFBD>һ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
* @param fd <EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
* @param udp_mode {bool} <EFBFBD>Ƿ<EFBFBD><EFBFBD><EFBFBD> UDP <EFBFBD><EFBFBD>ʽ
|
|
|
|
|
* @return {bool} <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><EFBFBD>ɹ<EFBFBD>
|
2014-11-19 00:25:21 +08:00
|
|
|
|
*/
|
2015-06-29 17:33:11 +08:00
|
|
|
|
#if defined(_WIN32) || defined(_WIN64)
|
2017-06-26 18:10:47 +08:00
|
|
|
|
bool open(SOCKET fd, bool udp_mode = false);
|
2014-11-19 00:25:21 +08:00
|
|
|
|
#else
|
2017-06-26 18:10:47 +08:00
|
|
|
|
bool open(int fd, bool udp_mode = false);
|
2014-11-19 00:25:21 +08:00
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
/**
|
2019-07-28 10:31:56 +08:00
|
|
|
|
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD> ACL_VSTREAM <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
2014-11-19 00:25:21 +08:00
|
|
|
|
* @param vstream {ACL_VSTREAM*}
|
2019-07-28 10:31:56 +08:00
|
|
|
|
* @param udp_mode {bool} <EFBFBD>Ƿ<EFBFBD><EFBFBD><EFBFBD> UDP <EFBFBD><EFBFBD>ʽ
|
|
|
|
|
* @return {bool} <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><EFBFBD>ɹ<EFBFBD>
|
2014-11-19 00:25:21 +08:00
|
|
|
|
*/
|
2017-06-26 18:10:47 +08:00
|
|
|
|
bool open(ACL_VSTREAM* vstream, bool udp_mode = false);
|
2014-11-19 00:25:21 +08:00
|
|
|
|
|
|
|
|
|
/**
|
2019-07-28 10:31:56 +08:00
|
|
|
|
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD>Զ<EFBFBD>̷<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
2019-12-12 10:57:29 +08:00
|
|
|
|
* @param addr {const char*} <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ַ, <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ӿڷ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>(UNIXƽ̨),
|
|
|
|
|
* <EFBFBD><EFBFBD><EFBFBD>ӵ<EFBFBD>ַ<EFBFBD><EFBFBD>/tmp/test.sock<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Linux ƽ̨<EFBFBD>»<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ӳ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>֣<EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
* abastract unix socket<EFBFBD><EFBFBD>Ϊ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͨ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD>·<EFBFBD><EFBFBD><EFBFBD><EFBFBD>unix<EFBFBD><EFBFBD><EFBFBD>ӵ<EFBFBD>ַ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
* <EFBFBD><EFBFBD> acl <EFBFBD><EFBFBD><EFBFBD>й涨<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD><EFBFBD>һ<EFBFBD><EFBFBD><EFBFBD>ֽ<EFBFBD>Ϊ @<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ<EFBFBD><EFBFBD> Linux <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
* <EFBFBD><EFBFBD>abstract unix domain socket<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ע<EFBFBD><EFBFBD><EFBFBD>ù<EFBFBD><EFBFBD>ܽ<EFBFBD><EFBFBD><EFBFBD> Linux ƽ̨֧<EFBFBD><EFBFBD>,
|
|
|
|
|
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>磺@/tmp/test.sock<EFBFBD><EFBFBD>;
|
2020-06-27 14:01:13 +08:00
|
|
|
|
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><EFBFBD>TCP<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD><EFBFBD>ʽΪ: remote_addr[@local_ip],
|
|
|
|
|
* <EFBFBD><EFBFBD>: www.sina.com:80@60.28.250.199,
|
2019-07-28 10:31:56 +08:00
|
|
|
|
* <EFBFBD><EFBFBD>˼<EFBFBD>ǰ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ַΪ: 60.28.250.199, Զ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> www.sina.com <EFBFBD><EFBFBD> 80,
|
|
|
|
|
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>OS<EFBFBD>Զ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> IP <EFBFBD><EFBFBD>ַ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>дΪ<EFBFBD><EFBFBD>www.sina.com:80
|
2021-07-09 18:27:11 +08:00
|
|
|
|
* @param conn_timeout {int} <EFBFBD><EFBFBD><EFBFBD>ӳ<EFBFBD>ʱʱ<EFBFBD><EFBFBD>(<EFBFBD><EFBFBD>λֵȡ<EFBFBD><EFBFBD><EFBFBD><EFBFBD> use_ms)
|
|
|
|
|
* @param rw_timeout {int} <EFBFBD><EFBFBD>д<EFBFBD><EFBFBD>ʱʱ<EFBFBD><EFBFBD>(<EFBFBD><EFBFBD>λֵȡ<EFBFBD><EFBFBD><EFBFBD><EFBFBD> use_ms)
|
2021-07-19 18:29:34 +08:00
|
|
|
|
* @param unit {time_unit_t} <EFBFBD><EFBFBD>ʱʱ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD>䵥λ
|
2019-07-28 10:31:56 +08:00
|
|
|
|
* @return {bool} <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><EFBFBD>ɹ<EFBFBD>
|
2014-11-19 00:25:21 +08:00
|
|
|
|
*/
|
2021-07-09 18:27:11 +08:00
|
|
|
|
bool open(const char* addr, int conn_timeout, int rw_timeout,
|
2021-07-19 18:29:34 +08:00
|
|
|
|
time_unit_t unit = time_unit_s);
|
2014-11-19 00:25:21 +08:00
|
|
|
|
|
|
|
|
|
/**
|
2019-07-28 10:31:56 +08:00
|
|
|
|
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD> UDP <EFBFBD><EFBFBD>ַ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> UDP <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
2019-12-12 10:57:29 +08:00
|
|
|
|
* @param addr {const char*} <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʽ<EFBFBD><EFBFBD>ip:port<EFBFBD><EFBFBD><EFBFBD>õ<EFBFBD>ַҲ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ
|
|
|
|
|
* UNIX <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֻ<EFBFBD> Linux <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>֣<EFBFBD>Linux abstract unix socket<EFBFBD><EFBFBD>
|
2019-07-28 10:31:56 +08:00
|
|
|
|
* @param rw_timeout {int} <EFBFBD><EFBFBD>д<EFBFBD><EFBFBD>ʱʱ<EFBFBD><EFBFBD>(<EFBFBD><EFBFBD>)
|
2022-06-01 20:14:37 +08:00
|
|
|
|
* @param flag {unsigned} <EFBFBD>ñ<EFBFBD>־λ<EFBFBD>Ķ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>μ<EFBFBD> server_socket.hpp
|
2019-07-28 10:31:56 +08:00
|
|
|
|
* @return {bool} <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><EFBFBD>ɹ<EFBFBD>
|
2014-11-19 00:25:21 +08:00
|
|
|
|
*/
|
2017-12-10 22:23:37 +08:00
|
|
|
|
bool bind_udp(const char* addr, int rw_timeout = 0, unsigned flag = 0);
|
2014-11-19 00:25:21 +08:00
|
|
|
|
|
2017-04-07 20:13:08 +08:00
|
|
|
|
/**
|
2019-07-28 10:31:56 +08:00
|
|
|
|
* <EFBFBD>ر<EFBFBD><EFBFBD>ӿڶ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
2017-04-07 20:13:08 +08:00
|
|
|
|
* @return {bool}
|
|
|
|
|
*/
|
|
|
|
|
bool shutdown_read(void);
|
|
|
|
|
|
|
|
|
|
/**
|
2019-07-28 10:31:56 +08:00
|
|
|
|
* <EFBFBD>ر<EFBFBD><EFBFBD>ӿ<EFBFBD>д<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
2017-04-07 20:13:08 +08:00
|
|
|
|
* @return {bool}
|
|
|
|
|
*/
|
|
|
|
|
bool shutdown_write(void);
|
|
|
|
|
|
|
|
|
|
/**
|
2019-07-28 10:31:56 +08:00
|
|
|
|
* <EFBFBD>ر<EFBFBD><EFBFBD>ӿڶ<EFBFBD>д<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
2017-04-07 20:13:08 +08:00
|
|
|
|
* @return {bool}
|
|
|
|
|
*/
|
|
|
|
|
bool shutdown_readwrite(void);
|
|
|
|
|
|
2014-11-19 00:25:21 +08:00
|
|
|
|
/**
|
2019-07-28 10:31:56 +08:00
|
|
|
|
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ӿ<EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
* @return {ACL_SOCKET} <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> - 1(UNIX ƽ̨)
|
|
|
|
|
* <EFBFBD><EFBFBD> INVALID_SOCKET(win32ƽ̨)
|
2014-11-19 00:25:21 +08:00
|
|
|
|
*/
|
2015-06-29 17:33:11 +08:00
|
|
|
|
#if defined(_WIN32) || defined(_WIN64)
|
2018-09-16 21:49:58 +08:00
|
|
|
|
SOCKET sock_handle(void) const;
|
2014-11-19 00:25:21 +08:00
|
|
|
|
#else
|
2018-09-16 21:49:58 +08:00
|
|
|
|
int sock_handle(void) const;
|
2014-11-19 00:25:21 +08:00
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
/**
|
2019-07-28 10:31:56 +08:00
|
|
|
|
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>İ<EFBFBD>ϵ<EFBFBD><EFBFBD>ͬʱ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD><EFBFBD>ظ<EFBFBD><EFBFBD>û<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵĹ<EFBFBD><EFBFBD><EFBFBD>Ȩ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>û<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͷ<EFBFBD>ʱ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>رո<EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
* <EFBFBD><EFBFBD><EFBFBD>֣<EFBFBD><EFBFBD><EFBFBD><EFBFBD>û<EFBFBD><EFBFBD>ӹܸ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֺ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>뽫<EFBFBD><EFBFBD><EFBFBD>ر<EFBFBD>
|
|
|
|
|
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> close/open <EFBFBD>ĵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>⣬<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ĵ<EFBFBD><EFBFBD><EFBFBD>(<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD>д<EFBFBD><EFBFBD><EFBFBD><EFBFBD>)<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
* @return {ACL_SOCKET} <EFBFBD><EFBFBD><EFBFBD><EFBFBD> ACL_SOCKET_INVALID <EFBFBD><EFBFBD>ʾ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
* <EFBFBD>Ѿ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֽ<EFBFBD><EFBFBD><EFBFBD>
|
2014-11-19 00:25:21 +08:00
|
|
|
|
*/
|
2015-06-29 17:33:11 +08:00
|
|
|
|
#if defined(_WIN32) || defined(_WIN64)
|
2018-09-16 21:49:58 +08:00
|
|
|
|
SOCKET unbind_sock(void);
|
2014-11-19 00:25:21 +08:00
|
|
|
|
#else
|
2018-09-16 21:49:58 +08:00
|
|
|
|
int unbind_sock(void);
|
2014-11-19 00:25:21 +08:00
|
|
|
|
#endif
|
|
|
|
|
|
2018-09-16 21:49:58 +08:00
|
|
|
|
/**
|
2019-07-28 10:31:56 +08:00
|
|
|
|
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD> socket <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
* @return {int} <EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ<EFBFBD>У<EFBFBD>AF_INET, AF_INT6, AF_UNIX<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD><EFBFBD><EFBFBD> -1
|
2018-09-16 21:49:58 +08:00
|
|
|
|
*/
|
|
|
|
|
int sock_type(void) const;
|
|
|
|
|
|
2014-11-19 00:25:21 +08:00
|
|
|
|
/**
|
2019-07-28 10:31:56 +08:00
|
|
|
|
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD>Զ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ӵĵ<EFBFBD>ַ
|
|
|
|
|
* @param full {bool} <EFBFBD>Ƿ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>IP:PORT<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ò<EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
* Ϊ false<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> IP<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> IP:PORT
|
|
|
|
|
* @return {const char*} Զ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ӵ<EFBFBD>ַ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ == '\0' <EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʾ
|
|
|
|
|
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Զ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ӵ<EFBFBD>ַ
|
2014-11-19 00:25:21 +08:00
|
|
|
|
*/
|
|
|
|
|
const char* get_peer(bool full = false) const;
|
|
|
|
|
|
|
|
|
|
/**
|
2019-07-28 10:31:56 +08:00
|
|
|
|
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD>Զ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ӵ<EFBFBD> IP <EFBFBD><EFBFBD>ַ
|
|
|
|
|
* @return {const char*} Զ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ӵ<EFBFBD>ַ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ == '\0' <EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʾ
|
|
|
|
|
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Զ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ӵ<EFBFBD>ַ
|
2014-11-19 00:25:21 +08:00
|
|
|
|
*/
|
2018-09-16 21:49:58 +08:00
|
|
|
|
const char* get_peer_ip(void) const;
|
2014-11-19 00:25:21 +08:00
|
|
|
|
|
|
|
|
|
/**
|
2019-07-28 10:31:56 +08:00
|
|
|
|
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD>Զ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ӷ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ĵ<EFBFBD>ַ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> TCP <EFBFBD><EFBFBD><EFBFBD>䷽ʽ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҫ<EFBFBD><EFBFBD>ʾ<EFBFBD><EFBFBD><EFBFBD>ô˺<EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD>Զ<EFBFBD>̶<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD><EFBFBD>UDP <EFBFBD><EFBFBD><EFBFBD>䷽ʽʱ<EFBFBD><EFBFBD>Ҫ<EFBFBD><EFBFBD><EFBFBD>ô˺<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Զ<EFBFBD>̵<EFBFBD>ַ<EFBFBD><EFBFBD>Ȼ<EFBFBD><EFBFBD>
|
|
|
|
|
* <EFBFBD>ſ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Զ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>д<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
* @param addr {const char*} Զ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ӷ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ĵ<EFBFBD>ַ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʽ<EFBFBD><EFBFBD>ip:port
|
|
|
|
|
* @return {bool} <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>δ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD><EFBFBD><EFBFBD> false
|
2014-11-19 00:25:21 +08:00
|
|
|
|
*/
|
|
|
|
|
bool set_peer(const char* addr);
|
|
|
|
|
|
|
|
|
|
/**
|
2019-07-28 10:31:56 +08:00
|
|
|
|
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ӵı<EFBFBD><EFBFBD>ص<EFBFBD>ַ
|
|
|
|
|
* @param full {bool} <EFBFBD>Ƿ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>IP:PORT<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ò<EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
* Ϊ false<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> IP<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> IP:PORT
|
|
|
|
|
* @return {const char*} <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ӵı<EFBFBD><EFBFBD>ص<EFBFBD>ַ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ == "" <EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʾ
|
|
|
|
|
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ñ<EFBFBD><EFBFBD>ص<EFBFBD>ַ
|
2014-11-19 00:25:21 +08:00
|
|
|
|
*/
|
|
|
|
|
const char* get_local(bool full = false) const;
|
|
|
|
|
|
|
|
|
|
/**
|
2019-07-28 10:31:56 +08:00
|
|
|
|
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ӵı<EFBFBD><EFBFBD><EFBFBD> IP <EFBFBD><EFBFBD>ַ
|
|
|
|
|
* @return {const char*} <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ӵı<EFBFBD><EFBFBD>ص<EFBFBD>ַ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ == "" <EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʾ
|
|
|
|
|
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ñ<EFBFBD><EFBFBD>ص<EFBFBD>ַ
|
2014-11-19 00:25:21 +08:00
|
|
|
|
*/
|
2018-09-16 21:49:58 +08:00
|
|
|
|
const char* get_local_ip(void) const;
|
2014-11-19 00:25:21 +08:00
|
|
|
|
|
|
|
|
|
/**
|
2019-07-28 10:31:56 +08:00
|
|
|
|
* <EFBFBD><EFBFBD><EFBFBD>ñ<EFBFBD><EFBFBD>ص<EFBFBD>ַ
|
|
|
|
|
* @param addr {const char*} <EFBFBD><EFBFBD>ַ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʽ<EFBFBD><EFBFBD>ip:port
|
|
|
|
|
* @return {bool} <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>δ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD><EFBFBD><EFBFBD> false
|
2014-11-19 00:25:21 +08:00
|
|
|
|
*/
|
|
|
|
|
bool set_local(const char* addr);
|
|
|
|
|
|
|
|
|
|
/**
|
2019-07-28 10:31:56 +08:00
|
|
|
|
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ӿ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ӵĴ<EFBFBD><EFBFBD><EFBFBD>״̬(<EFBFBD>ڲ<EFBFBD>ʹ<EFBFBD><EFBFBD><EFBFBD>˷<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ķ<EFBFBD>ʽ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>̽<EFBFBD><EFBFBD>)
|
|
|
|
|
* @return {bool} <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>δ<EFBFBD><EFBFBD><EFBFBD>Ѿ<EFBFBD><EFBFBD>ر<EFBFBD>ʱ<EFBFBD>ú<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> false<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> true
|
2014-11-19 00:25:21 +08:00
|
|
|
|
*/
|
2018-09-16 21:49:58 +08:00
|
|
|
|
bool alive(void) const;
|
2014-11-19 00:25:21 +08:00
|
|
|
|
|
|
|
|
|
/**
|
2019-07-28 10:31:56 +08:00
|
|
|
|
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD> TCP <EFBFBD><EFBFBD><EFBFBD>ֵ<EFBFBD> nodelay <EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
* @param on {bool} true <EFBFBD><EFBFBD>ʾ<EFBFBD><EFBFBD>false <EFBFBD><EFBFBD>ʾ<EFBFBD>ر<EFBFBD>
|
2014-11-19 00:25:21 +08:00
|
|
|
|
* @return {socket_stream&}
|
|
|
|
|
*/
|
|
|
|
|
socket_stream& set_tcp_nodelay(bool on);
|
|
|
|
|
|
|
|
|
|
/**
|
2019-07-28 10:31:56 +08:00
|
|
|
|
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD> TCP <EFBFBD><EFBFBD><EFBFBD>ֵ<EFBFBD> SO_LINGER ѡ<EFBFBD><EFBFBD>
|
|
|
|
|
* @param on {bool} <EFBFBD>Ƿ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> SO_LINGER ѡ<EFBFBD><EFBFBD>
|
|
|
|
|
* @param linger {int} <EFBFBD><EFBFBD>SO_LINGER<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD>ȡ<EFBFBD><EFBFBD> timed_wait <EFBFBD><EFBFBD>ʱ<EFBFBD>䣬<EFBFBD><EFBFBD>λΪ<EFBFBD><EFBFBD>
|
2014-11-19 00:25:21 +08:00
|
|
|
|
* @return {socket_stream&}
|
|
|
|
|
*/
|
|
|
|
|
socket_stream& set_tcp_solinger(bool on, int linger);
|
|
|
|
|
|
|
|
|
|
/**
|
2019-07-28 10:31:56 +08:00
|
|
|
|
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD> TCP <EFBFBD><EFBFBD><EFBFBD>ֵ<EFBFBD>д<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>С
|
|
|
|
|
* @param size {int} <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ô<EFBFBD>С
|
2014-11-19 00:25:21 +08:00
|
|
|
|
* @return {socket_stream&}
|
|
|
|
|
*/
|
|
|
|
|
socket_stream& set_tcp_sendbuf(int size);
|
|
|
|
|
|
|
|
|
|
/**
|
2019-07-28 10:31:56 +08:00
|
|
|
|
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD> TCP <EFBFBD><EFBFBD><EFBFBD>ֵĶ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>С
|
|
|
|
|
* @param size {int} <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ô<EFBFBD>С
|
2014-11-19 00:25:21 +08:00
|
|
|
|
* @return {socket_stream&}
|
|
|
|
|
*/
|
|
|
|
|
socket_stream& set_tcp_recvbuf(int size);
|
|
|
|
|
|
2015-01-14 23:35:23 +08:00
|
|
|
|
/**
|
2019-07-28 10:31:56 +08:00
|
|
|
|
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD> TCP <EFBFBD><EFBFBD><EFBFBD>ֵķ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>״̬
|
|
|
|
|
* @param on {bool} <EFBFBD>Ƿ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>״̬<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ true ʱ<EFBFBD><EFBFBD>
|
|
|
|
|
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֱ<EFBFBD><EFBFBD><EFBFBD>Ϊ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>״̬<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>״̬
|
2015-01-14 23:35:23 +08:00
|
|
|
|
* @return {socket_stream&}
|
|
|
|
|
*/
|
|
|
|
|
socket_stream& set_tcp_non_blocking(bool on);
|
|
|
|
|
|
2014-11-19 00:25:21 +08:00
|
|
|
|
/**
|
2019-07-28 10:31:56 +08:00
|
|
|
|
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD> TCP <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> nodelay ѡ<EFBFBD><EFBFBD>
|
|
|
|
|
* @return {bool} true <EFBFBD><EFBFBD>ʾ<EFBFBD><EFBFBD>false <EFBFBD><EFBFBD>ʾ<EFBFBD>ر<EFBFBD>
|
2014-11-19 00:25:21 +08:00
|
|
|
|
*/
|
2018-09-16 21:49:58 +08:00
|
|
|
|
bool get_tcp_nodelay(void);
|
2014-11-19 00:25:21 +08:00
|
|
|
|
|
|
|
|
|
/**
|
2019-07-28 10:31:56 +08:00
|
|
|
|
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD> TCP <EFBFBD><EFBFBD><EFBFBD>ֵ<EFBFBD> linger ֵ
|
|
|
|
|
* @return {int} <EFBFBD><EFBFBD><EFBFBD><EFBFBD> -1 <EFBFBD><EFBFBD>ʾδ<EFBFBD><EFBFBD><EFBFBD><EFBFBD> linger ѡ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڲ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>>= 0
|
|
|
|
|
* <EFBFBD><EFBFBD>ʾ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> linger ѡ<EFBFBD><EFBFBD><EFBFBD>Ҹ<EFBFBD>ֵ<EFBFBD><EFBFBD>ʾ<EFBFBD><EFBFBD><EFBFBD>ֹرպ<EFBFBD><EFBFBD><EFBFBD> TCP <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ں<EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
* ά<EFBFBD><EFBFBD> TIME_WAIT ״̬<EFBFBD>Ķ<EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD>(<EFBFBD><EFBFBD>)
|
2014-11-19 00:25:21 +08:00
|
|
|
|
*/
|
2018-09-16 21:49:58 +08:00
|
|
|
|
int get_tcp_solinger(void);
|
2014-11-19 00:25:21 +08:00
|
|
|
|
|
|
|
|
|
/**
|
2019-07-28 10:31:56 +08:00
|
|
|
|
* <EFBFBD><EFBFBD>ȡ TCP <EFBFBD><EFBFBD><EFBFBD>ֵ<EFBFBD>д<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>С
|
|
|
|
|
* @return {int} <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>С
|
2014-11-19 00:25:21 +08:00
|
|
|
|
*/
|
2018-09-16 21:49:58 +08:00
|
|
|
|
int get_tcp_sendbuf(void);
|
2014-11-19 00:25:21 +08:00
|
|
|
|
|
|
|
|
|
/**
|
2019-07-28 10:31:56 +08:00
|
|
|
|
* <EFBFBD><EFBFBD>ȡ TCP <EFBFBD><EFBFBD><EFBFBD>ֵĶ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>С
|
|
|
|
|
* @return {int} <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>С
|
2014-11-19 00:25:21 +08:00
|
|
|
|
*/
|
2018-09-16 21:49:58 +08:00
|
|
|
|
int get_tcp_recvbuf(void);
|
2014-11-19 00:25:21 +08:00
|
|
|
|
|
2015-01-14 23:35:23 +08:00
|
|
|
|
/**
|
2019-07-28 10:31:56 +08:00
|
|
|
|
* <EFBFBD>жϵ<EFBFBD>ǰ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>˷<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ģʽ
|
2015-01-14 23:35:23 +08:00
|
|
|
|
* @return {bool}
|
2019-07-28 10:31:56 +08:00
|
|
|
|
* ע<EFBFBD><EFBFBD><EFBFBD>÷<EFBFBD><EFBFBD><EFBFBD>Ŀǰ<EFBFBD><EFBFBD>֧<EFBFBD><EFBFBD> UNIX ƽ̨
|
2015-01-14 23:35:23 +08:00
|
|
|
|
*/
|
2018-09-16 21:49:58 +08:00
|
|
|
|
bool get_tcp_non_blocking(void);
|
2015-01-14 23:35:23 +08:00
|
|
|
|
|
2014-11-19 00:25:21 +08:00
|
|
|
|
private:
|
2019-08-20 17:17:37 +08:00
|
|
|
|
std::string ipbuf_;
|
|
|
|
|
const char* get_ip(const char* addr, std::string& out);
|
2014-11-19 00:25:21 +08:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
} // namespace acl
|