Skip to content

Commit

Permalink
Update about-connection-context.md
Browse files Browse the repository at this point in the history
  • Loading branch information
Barenboim authored Jan 14, 2025
1 parent dd7b83d commit fdc554f
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion docs/en/about-connection-context.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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

Expand Down

0 comments on commit fdc554f

Please sign in to comment.