Skip to content

Commit 8cf3efd

Browse files
committed
php#53: Optimize network_async_accept_incoming: try accept() first, ensure non-blocking mode
- Try accept() immediately instead of waiting for READ event first - Only wait in event loop if accept() returns EAGAIN/EWOULDBLOCK - Ensure socket is in non-blocking mode before accept() calls - Eliminates unnecessary syscalls when connections are already ready - Refactor with centralized error handling and better code structure
1 parent 8ecf22b commit 8cf3efd

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

main/network_async.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1154,6 +1154,15 @@ ZEND_API php_socket_t network_async_accept_incoming(php_stream *stream,
11541154
error = EBADF;
11551155
goto return_error;
11561156
}
1157+
1158+
// Ensure socket is in non-blocking mode for async operations
1159+
if (sock->is_blocked && !sock->nonblocking_applied) {
1160+
network_async_set_socket_blocking(sock->socket, false, sock);
1161+
if (UNEXPECTED(EG(exception) != NULL)) {
1162+
goto return_error;
1163+
}
1164+
}
1165+
11571166
// Try accept() first - there might be a connection ready already
11581167
clisock = accept(sock->socket, (struct sockaddr*)&sa, &sl);
11591168

0 commit comments

Comments
 (0)