| 252 | } |
| 253 | |
| 254 | static 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 | |
| 308 | static int connSocketBlockingConnect(connection *conn, const char *addr, int port, long long timeout) { |
| 309 | int fd = anetTcpNonBlockConnect(NULL,addr,port); |
nothing calls this directly
no test coverage detected