MCPcopy Create free account
hub / github.com/Snapchat/KeyDB / connSocketSetWriteHandler

Function connSocketSetWriteHandler

src/connection.cpp:225–245  ·  view source on GitHub ↗

Register a write handler, to be called when the connection is writable. * If NULL, the existing handler is removed. * * The barrier flag indicates a write barrier is requested, resulting with * CONN_FLAG_WRITE_BARRIER set. This will ensure that the write handler is * always called before and not after the read handler in a single event * loop. */

Source from the content-addressed store, hash-verified

223 * loop.
224 */
225static int connSocketSetWriteHandler(connection *conn, ConnectionCallbackFunc func, int barrier, bool fThreadSafe) {
226 if (func == conn->write_handler) return C_OK;
227
228 conn->write_handler = func;
229 if (barrier)
230 conn->flags |= CONN_FLAG_WRITE_BARRIER;
231 else
232 conn->flags &= ~CONN_FLAG_WRITE_BARRIER;
233
234 if (fThreadSafe)
235 conn->flags |= CONN_FLAG_WRITE_THREADSAFE;
236 else
237 conn->flags &= ~CONN_FLAG_WRITE_THREADSAFE;
238
239 if (!conn->write_handler)
240 aeDeleteFileEvent(serverTL->el,conn->fd,AE_WRITABLE);
241 else
242 if (aeCreateFileEvent(serverTL->el,conn->fd,AE_WRITABLE|AE_WRITE_THREADSAFE,
243 conn->type->ae_handler,conn) == AE_ERR) return C_ERR;
244 return C_OK;
245}
246
247/* Register a read handler, to be called when the connection is readable.
248 * If NULL, the existing handler is removed.

Callers

nothing calls this directly

Calls 2

aeDeleteFileEventFunction · 0.85
aeCreateFileEventFunction · 0.85

Tested by

no test coverage detected