MCPcopy Create free account
hub / github.com/F-Stack/f-stack / connSocketEventHandler

Function connSocketEventHandler

app/redis-6.2.6/src/connection.c:254–306  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

252}
253
254static void connSocketEventHandler(struct aeEventLoop *el, int fd, void *clientData, int mask)
255{
256 UNUSED(el);
257 UNUSED(fd);
258 connection *conn = clientData;
259
260 if (conn->state == CONN_STATE_CONNECTING &&
261 (mask & AE_WRITABLE) && conn->conn_handler) {
262
263 int conn_error = connGetSocketError(conn);
264 if (conn_error) {
265 conn->last_errno = conn_error;
266 conn->state = CONN_STATE_ERROR;
267 } else {
268 conn->state = CONN_STATE_CONNECTED;
269 }
270
271 if (!conn->write_handler) aeDeleteFileEvent(server.el,conn->fd,AE_WRITABLE);
272
273 if (!callHandler(conn, conn->conn_handler)) return;
274 conn->conn_handler = NULL;
275 }
276
277 /* Normally we execute the readable event first, and the writable
278 * event later. This is useful as sometimes we may be able
279 * to serve the reply of a query immediately after processing the
280 * query.
281 *
282 * However if WRITE_BARRIER is set in the mask, our application is
283 * asking us to do the reverse: never fire the writable event
284 * after the readable. In such a case, we invert the calls.
285 * This is useful when, for instance, we want to do things
286 * in the beforeSleep() hook, like fsync'ing a file to disk,
287 * before replying to a client. */
288 int invert = conn->flags & CONN_FLAG_WRITE_BARRIER;
289
290 int call_write = (mask & AE_WRITABLE) && conn->write_handler;
291 int call_read = (mask & AE_READABLE) && conn->read_handler;
292
293 /* Handle normal I/O flows */
294 if (!invert && call_read) {
295 if (!callHandler(conn, conn->read_handler)) return;
296 }
297 /* Fire the writable event. */
298 if (call_write) {
299 if (!callHandler(conn, conn->write_handler)) return;
300 }
301 /* If we have to invert the call, fire the readable event now
302 * after the writable one. */
303 if (invert && call_read) {
304 if (!callHandler(conn, conn->read_handler)) return;
305 }
306}
307
308static int connSocketBlockingConnect(connection *conn, const char *addr, int port, long long timeout) {
309 int fd = anetTcpNonBlockConnect(NULL,addr,port);

Callers

nothing calls this directly

Calls 3

connGetSocketErrorFunction · 0.85
aeDeleteFileEventFunction · 0.85
callHandlerFunction · 0.85

Tested by

no test coverage detected