Skip to content

Commit 84988d2

Browse files
committed
cli server addressing few todos.
Closes GH-10124.
1 parent 23fe58c commit 84988d2

File tree

1 file changed

+19
-20
lines changed

1 file changed

+19
-20
lines changed

sapi/cli/php_cli_server.c

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -270,10 +270,10 @@ static bool php_cli_server_get_system_time(char *buf) {
270270

271271
gettimeofday(&tv, NULL);
272272

273-
/* TODO: should be checked for NULL tm/return value */
274-
php_localtime_r(&tv.tv_sec, &tm);
275-
php_asctime_r(&tm, buf);
276-
return true;
273+
if (!php_localtime_r(&tv.tv_sec, &tm)) {
274+
return false;
275+
}
276+
return php_asctime_r(&tm, buf) != NULL;
277277
}
278278
#endif
279279

@@ -865,7 +865,6 @@ static int php_cli_server_poller_poll(php_cli_server_poller *poller, struct time
865865
return php_select(poller->max_fd + 1, &poller->active.rfds, &poller->active.wfds, NULL, tv);
866866
} /* }}} */
867867

868-
// TODO Return value is unused, refactor?
869868
static zend_result php_cli_server_poller_iter_on_active(php_cli_server_poller *poller, void *opaque, zend_result(*callback)(void *, php_socket_t fd, int events)) /* {{{ */
870869
{
871870
zend_result retval = SUCCESS;
@@ -2214,10 +2213,9 @@ static void php_cli_server_request_shutdown(php_cli_server *server, php_cli_serv
22142213
}
22152214
/* }}} */
22162215

2217-
// TODO Use bool, return value is strange
2218-
static int php_cli_server_dispatch_router(php_cli_server *server, php_cli_server_client *client) /* {{{ */
2216+
static bool php_cli_server_dispatch_router(php_cli_server *server, php_cli_server_client *client) /* {{{ */
22192217
{
2220-
int decline = 0;
2218+
bool decline = false;
22212219
zend_file_handle zfd;
22222220
char *old_cwd;
22232221

@@ -2253,7 +2251,6 @@ static int php_cli_server_dispatch_router(php_cli_server *server, php_cli_server
22532251
}
22542252
/* }}} */
22552253

2256-
// TODO Return FAILURE on error? Or voidify as return value of function not checked
22572254
static zend_result php_cli_server_dispatch(php_cli_server *server, php_cli_server_client *client) /* {{{ */
22582255
{
22592256
int is_static_file = 0;
@@ -2269,7 +2266,7 @@ static zend_result php_cli_server_dispatch(php_cli_server *server, php_cli_serve
22692266
if (server->router || !is_static_file) {
22702267
if (FAILURE == php_cli_server_request_startup(server, client)) {
22712268
php_cli_server_request_shutdown(server, client);
2272-
return SUCCESS;
2269+
return FAILURE;
22732270
}
22742271
}
22752272

@@ -2610,8 +2607,7 @@ static zend_result php_cli_server_recv_event_read_request(php_cli_server *server
26102607
return php_cli_server_send_error_page(server, client, 501);
26112608
}
26122609
php_cli_server_poller_remove(&server->poller, POLLIN, client->sock);
2613-
php_cli_server_dispatch(server, client);
2614-
return SUCCESS;
2610+
return php_cli_server_dispatch(server, client);
26152611
case 0:
26162612
php_cli_server_poller_add(&server->poller, POLLIN, client->sock);
26172613
return SUCCESS;
@@ -2657,7 +2653,6 @@ typedef struct php_cli_server_do_event_for_each_fd_callback_params {
26572653
zend_result(*whandler)(php_cli_server*, php_cli_server_client*);
26582654
} php_cli_server_do_event_for_each_fd_callback_params;
26592655

2660-
// TODO return FAILURE on failure???
26612656
static zend_result php_cli_server_do_event_for_each_fd_callback(void *_params, php_socket_t fd, int event) /* {{{ */
26622657
{
26632658
php_cli_server_do_event_for_each_fd_callback_params *params = _params;
@@ -2677,12 +2672,12 @@ static zend_result php_cli_server_do_event_for_each_fd_callback(void *_params, p
26772672
efree(errstr);
26782673
}
26792674
pefree(sa, 1);
2680-
return SUCCESS;
2675+
return FAILURE;
26812676
}
26822677
if (SUCCESS != php_set_sock_blocking(client_sock, 0)) {
26832678
pefree(sa, 1);
26842679
closesocket(client_sock);
2685-
return SUCCESS;
2680+
return FAILURE;
26862681
}
26872682
client = pemalloc(sizeof(php_cli_server_client), 1);
26882683

@@ -2717,10 +2712,11 @@ static void php_cli_server_do_event_for_each_fd(php_cli_server *server,
27172712
whandler
27182713
};
27192714

2720-
php_cli_server_poller_iter_on_active(&server->poller, &params, php_cli_server_do_event_for_each_fd_callback);
2715+
if (SUCCESS != php_cli_server_poller_iter_on_active(&server->poller, &params, php_cli_server_do_event_for_each_fd_callback)) {
2716+
php_cli_server_logf(PHP_CLI_SERVER_LOG_ERROR, "Failed to poll event");
2717+
}
27212718
} /* }}} */
27222719

2723-
// TODO Return value of function is not used
27242720
static zend_result php_cli_server_do_event_loop(php_cli_server *server) /* {{{ */
27252721
{
27262722
zend_result retval = SUCCESS;
@@ -2763,7 +2759,7 @@ int do_cli_server(int argc, char **argv) /* {{{ */
27632759
{
27642760
char *php_optarg = NULL;
27652761
int php_optind = 1;
2766-
int c;
2762+
int c, r;
27672763
const char *server_bind_address = NULL;
27682764
extern const opt_struct OPTIONS[];
27692765
const char *document_root = NULL;
@@ -2841,6 +2837,7 @@ int do_cli_server(int argc, char **argv) /* {{{ */
28412837
sapi_module.phpinfo_as_text = 0;
28422838

28432839
{
2840+
r = 0;
28442841
bool ipv6 = strchr(server.host, ':');
28452842
php_cli_server_logf(
28462843
PHP_CLI_SERVER_LOG_PROCESS,
@@ -2859,7 +2856,9 @@ int do_cli_server(int argc, char **argv) /* {{{ */
28592856

28602857
zend_signal_init();
28612858

2862-
php_cli_server_do_event_loop(&server);
2859+
if (SUCCESS != php_cli_server_do_event_loop(&server)) {
2860+
r = 1;
2861+
}
28632862
php_cli_server_dtor(&server);
2864-
return 0;
2863+
return r;
28652864
} /* }}} */

0 commit comments

Comments
 (0)