Merge branch 'master' of https://github.com/sogou/workflow into nossl

This commit is contained in:
Xie Han
2025-01-15 21:23:27 +08:00
5 changed files with 25 additions and 6 deletions

View File

@@ -5,7 +5,7 @@ set(CMAKE_SKIP_RPATH TRUE)
project(
workflow
VERSION 0.11.7
VERSION 0.11.8
LANGUAGES C CXX
)

View File

@@ -19,6 +19,8 @@ http协议可以说是一种完全无连接状态的协议http会话是通
事务型mysql可以固定连接这部分内容请参考mysql相关文档。
但是如果我们实现一个redis协议的server那我们需要知道当前连接上的状态了。
此外,我们还可以通过连接上下文件被释放的事件来感知连接被远端关闭。
# 使用连接上下文的方法
我们需要强调的是一般情况下只有server任务需要使用连接上下文并且只需要在process函数内部使用这也是最安全最简单的用法。
@@ -40,12 +42,16 @@ class WFConnection : public CommConnection
public:
void *get_context() const;
void set_context(void *context, std::function<void (void *)> deleter);
void set_context(void *context);
void *test_set_context(void *test_context, void *new_context,
std::function<void (void *)> deleter);
void *test_set_context(void *test_context, void *new_context);
};
~~~
get_connection()只可在process或callback里调用而且如果callback里调用需要检查返回值是否为NULL。
如果成功取得WFConnection对象就可以操作连接上下文了。连接上下文是一个void *指针在连接被关闭时deleter被自动调用
如果成功取得WFConnection对象就可以操作连接上下文了。连接上下文是一个void *指针。
设置连接上下文可以同时传入deleter函数在连接被关闭时deleter被自动调用。
如果调用无deleter参数的接口可以只设置新的上下文保持原有的deleter不变。
# 访问连接上下文的时机和并发问题

View File

@@ -20,6 +20,8 @@ Due to this limitation, in the framework, you cannot use the SELECT command of R
Transactional MySQL tasks can use fixed connections. Please see MySQL documentations for relevant details.
However, if you implement a server based on Redis protocol, you need to know the current connection status.
By using the deleter function of connection context, users can also get notified when the connection was closed by the peer.
# How to use connection context
Note: generally, only the server tasks need to use the connection context, and the connection context is used only inside the process function, which is also the safest and simplest.
@@ -44,13 +46,15 @@ class WFConnection : public CommConnection
public:
void *get_context() const;
void set_context(void *context, std::function<void (void *)> deleter);
void set_context(void *context);
void *test_set_context(void *test_context, void *new_context,
std::function<void (void *)> deleter);
void *test_set_context(void *test_context, void *new_context);
};
~~~
**get\_connection()** can only be called in a process or a callback. If you call it in the callback, please check whether the return value is NULL.
If you get the WFConnection object successfully, you can perform operations on the connection context. A connection context is a void \* pointer. When the connection is closed, the deleter is automatically called.
If you get the WFConnection object successfully, you can perform operations on the connection context. A connection context is a void \* pointer. When the connection is closed, the deleter is automatically called. When using the setting context functions without ``deleter`` argument, the original deleter will be kept unchanged.
# Timing and concurrency for accessing connection context

View File

@@ -290,10 +290,19 @@ inline IOService *__CommManager::get_io_service()
if (!fio_flag_)
{
int maxevents = WFGlobal::get_global_settings()->fio_max_events;
int n = 65536;
fio_service_ = new __FileIOService(&scheduler_);
if (fio_service_->init(maxevents) < 0)
abort();
while (fio_service_->init(maxevents) < 0)
{
if ((errno != EAGAIN && errno != EINVAL) || maxevents <= 16)
abort();
while (n >= maxevents)
n /= 2;
maxevents = n;
}
if (fio_service_->bind() < 0)
abort();

View File

@@ -1,5 +1,5 @@
set_project("workflow")
set_version("0.11.7")
set_version("0.11.8")
option("workflow_inc", {description = "workflow inc", default = "$(projectdir)/_include"})
option("workflow_lib", {description = "workflow lib", default = "$(projectdir)/_lib"})