mirror of
https://gitee.com/acl-dev/acl.git
synced 2024-11-30 10:57:34 +08:00
add open flag for aio_listen_stream
This commit is contained in:
parent
cb218497b6
commit
893facc629
@ -56,9 +56,10 @@ public:
|
||||
* 格式:
|
||||
* 针对TCP连接:IP:PORT,如:127.0.0.1:9001
|
||||
* 针对域套接口:{path},如:/tmp/my.sock
|
||||
* @param flag {unsigned} 创建监听套接口时的打开标志位,见 server_socket.hpp
|
||||
* @return {bool} 监听是否成功
|
||||
*/
|
||||
bool open(const char* addr);
|
||||
bool open(const char* addr, unsigned flag = 0);
|
||||
|
||||
/**
|
||||
* 获得服务器监听地址
|
||||
|
@ -9,12 +9,12 @@ namespace acl {
|
||||
|
||||
class socket_stream;
|
||||
|
||||
typedef enum {
|
||||
enum {
|
||||
OPEN_FLAG_NONE = 0,
|
||||
OPEN_FLAG_NONBLOCK = 1, // 非阻塞模式
|
||||
OPEN_FLAG_REUSEPORT = 1 << 1, // 端口复用,要求 Linux3.0 以上
|
||||
OPEN_FLAG_EXCLUSIVE = 1 << 2, // 是否禁止复用地址
|
||||
} open_flag_t;
|
||||
};
|
||||
|
||||
/**
|
||||
* 服务端监听套接口类,接收客户端连接,并创建客户端流连接对象
|
||||
@ -34,7 +34,7 @@ public:
|
||||
* @param flag {unsigned} 定义参见 OPEN_FLAG_XXX
|
||||
* @param backlog {int} 监听套接口队列长度
|
||||
*/
|
||||
explicit server_socket(open_flag_t flag, int backlog = 128);
|
||||
explicit server_socket(unsigned flag, int backlog = 128);
|
||||
|
||||
/**
|
||||
* 构造函数,调用本构造函数后禁止再调用 open 方法
|
||||
|
@ -1,6 +1,7 @@
|
||||
#include "acl_stdafx.hpp"
|
||||
#ifndef ACL_PREPARE_COMPILE
|
||||
#include "acl_cpp/stdlib/snprintf.hpp"
|
||||
#include "acl_cpp/stream/socket_stream.hpp"
|
||||
#include "acl_cpp/stream/aio_handle.hpp"
|
||||
#include "acl_cpp/stream/aio_socket_stream.hpp"
|
||||
#include "acl_cpp/stream/aio_listen_stream.hpp"
|
||||
@ -38,9 +39,14 @@ void aio_listen_stream::add_accept_callback(aio_accept_callback* callback)
|
||||
accept_callbacks_.push_back(callback);
|
||||
}
|
||||
|
||||
bool aio_listen_stream::open(const char* addr)
|
||||
bool aio_listen_stream::open(const char* addr, unsigned flag /* = 0 */)
|
||||
{
|
||||
ACL_VSTREAM *sstream = acl_vstream_listen(addr, 128);
|
||||
unsigned oflag = 0;
|
||||
if (flag & OPEN_FLAG_REUSEPORT)
|
||||
oflag |= ACL_INET_FLAG_REUSEPORT;
|
||||
if (flag & OPEN_FLAG_EXCLUSIVE)
|
||||
oflag |= ACL_INET_FLAG_EXCLUSIVE;
|
||||
ACL_VSTREAM *sstream = acl_vstream_listen_ex(addr, 128, oflag, 0, 0);
|
||||
if (sstream == NULL)
|
||||
return false;
|
||||
|
||||
|
@ -20,7 +20,7 @@ server_socket::server_socket(int backlog /* = 128 */, bool block /* = true */)
|
||||
open_flag_ = block ? ACL_BLOCKING : ACL_NON_BLOCKING;
|
||||
}
|
||||
|
||||
server_socket::server_socket(open_flag_t flag, int backlog /* = 128 */)
|
||||
server_socket::server_socket(unsigned flag, int backlog /* = 128 */)
|
||||
: backlog_(backlog)
|
||||
, unix_sock_(false)
|
||||
, fd_(ACL_SOCKET_INVALID)
|
||||
|
Loading…
Reference in New Issue
Block a user