mirror of
https://github.com/sogou/workflow.git
synced 2026-02-08 01:33:17 +08:00
Merge branch 'master' of https://github.com/sogou/workflow into nossl
This commit is contained in:
@@ -5,7 +5,7 @@ set(CMAKE_SKIP_RPATH TRUE)
|
||||
|
||||
project(
|
||||
workflow
|
||||
VERSION 0.11.7
|
||||
VERSION 0.11.8
|
||||
LANGUAGES C CXX
|
||||
)
|
||||
|
||||
|
||||
@@ -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不变。
|
||||
|
||||
# 访问连接上下文的时机和并发问题
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user