Skip to content

Commit d4d1bc0

Browse files
committed
poll: fix wsapoll CS
1 parent 425265c commit d4d1bc0

File tree

1 file changed

+23
-19
lines changed

1 file changed

+23
-19
lines changed

main/poll/poll_backend_wsapoll.c

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,8 @@ static uint32_t wsapoll_events_from_native(uint32_t native)
6666

6767
static zend_result wsapoll_backend_init(php_poll_ctx *ctx)
6868
{
69-
wsapoll_backend_data_t *data = php_poll_calloc(1, sizeof(wsapoll_backend_data_t), ctx->persistent);
69+
wsapoll_backend_data_t *data
70+
= php_poll_calloc(1, sizeof(wsapoll_backend_data_t), ctx->persistent);
7071
if (!data) {
7172
php_poll_set_error(ctx, PHP_POLL_ERR_NOMEM);
7273
return FAILURE;
@@ -131,7 +132,8 @@ static zend_result wsapoll_backend_add(php_poll_ctx *ctx, int fd, uint32_t event
131132
return SUCCESS;
132133
}
133134

134-
static zend_result wsapoll_backend_modify(php_poll_ctx *ctx, int fd, uint32_t events, void *user_data)
135+
static zend_result wsapoll_backend_modify(
136+
php_poll_ctx *ctx, int fd, uint32_t events, void *user_data)
135137
{
136138
wsapoll_backend_data_t *backend_data = (wsapoll_backend_data_t *) ctx->backend_data;
137139

@@ -177,14 +179,16 @@ static bool wsapoll_build_fds_callback(int fd, php_poll_fd_entry *entry, void *u
177179
wsapoll_build_context *ctx = (wsapoll_build_context *) user_data;
178180

179181
ctx->fds[ctx->index].fd = (SOCKET) fd;
180-
ctx->fds[ctx->index].events = (SHORT) wsapoll_events_to_native(entry->events & ~(PHP_POLL_ET | PHP_POLL_ONESHOT));
182+
ctx->fds[ctx->index].events
183+
= (SHORT) wsapoll_events_to_native(entry->events & ~(PHP_POLL_ET | PHP_POLL_ONESHOT));
181184
ctx->fds[ctx->index].revents = 0;
182185
ctx->index++;
183186

184187
return true;
185188
}
186189

187-
static int wsapoll_backend_wait(php_poll_ctx *ctx, php_poll_event *events, int max_events, int timeout)
190+
static int wsapoll_backend_wait(
191+
php_poll_ctx *ctx, php_poll_event *events, int max_events, int timeout)
188192
{
189193
wsapoll_backend_data_t *backend_data = (wsapoll_backend_data_t *) ctx->backend_data;
190194

@@ -199,7 +203,7 @@ static int wsapoll_backend_wait(php_poll_ctx *ctx, php_poll_event *events, int m
199203
/* Ensure temp_fds array is large enough */
200204
if (fd_count > backend_data->temp_fds_capacity) {
201205
WSAPOLLFD *new_fds = php_poll_realloc(
202-
backend_data->temp_fds, fd_count * sizeof(WSAPOLLFD), ctx->persistent);
206+
backend_data->temp_fds, fd_count * sizeof(WSAPOLLFD), ctx->persistent);
203207
if (!new_fds) {
204208
php_poll_set_error(ctx, PHP_POLL_ERR_NOMEM);
205209
return -1;
@@ -219,19 +223,19 @@ static int wsapoll_backend_wait(php_poll_ctx *ctx, php_poll_event *events, int m
219223
/* WSAPoll specific error handling */
220224
int wsa_error = WSAGetLastError();
221225
php_poll_error error_code;
222-
226+
223227
switch (wsa_error) {
224228
case WSAENOTSOCK:
225-
/* Special case: all sockets in array are invalid
226-
* WSAPoll fails entirely, but we should clean up and return 0
227-
* This differs from Unix poll() which would report POLLNVAL per socket */
228-
229-
/* Remove all invalid sockets from fd_table */
230-
for (int i = 0; i < fd_count; i++) {
231-
int fd = (int) backend_data->temp_fds[i].fd;
232-
php_poll_fd_table_remove(backend_data->fd_table, fd);
233-
}
234-
return 0;
229+
/* Special case: all sockets in array are invalid
230+
* WSAPoll fails entirely, but we should clean up and return 0
231+
* This differs from Unix poll() which would report POLLNVAL per socket */
232+
233+
/* Remove all invalid sockets from fd_table */
234+
for (int i = 0; i < fd_count; i++) {
235+
int fd = (int) backend_data->temp_fds[i].fd;
236+
php_poll_fd_table_remove(backend_data->fd_table, fd);
237+
}
238+
return 0;
235239
case WSAENOBUFS:
236240
error_code = PHP_POLL_ERR_NOMEM;
237241
break;
@@ -243,7 +247,7 @@ static int wsapoll_backend_wait(php_poll_ctx *ctx, php_poll_event *events, int m
243247
error_code = PHP_POLL_ERR_SYSTEM;
244248
break;
245249
}
246-
250+
247251
php_poll_set_error(ctx, error_code);
248252
return -1;
249253
}
@@ -268,9 +272,9 @@ static int wsapoll_backend_wait(php_poll_ctx *ctx, php_poll_event *events, int m
268272

269273
/* Convert WSAPoll events to PHP poll events */
270274
uint32_t converted_events = wsapoll_events_from_native(pfd->revents);
271-
275+
272276
/* Special check if POLLERR and POLLHUP are reported */
273-
if ((pfd->revents & POLLERR) && (pfd->revents & POLLHUP)) {
277+
if ((pfd->revents & POLLERR) && (pfd->revents & POLLHUP)) {
274278
/* Clear ERROR if HUP present to match other backends */
275279
converted_events &= ~PHP_POLL_ERROR;
276280
}

0 commit comments

Comments
 (0)