Skip to content

cli server addressing few todos. #10124

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 19 additions & 19 deletions sapi/cli/php_cli_server.c
Original file line number Diff line number Diff line change
Expand Up @@ -270,10 +270,10 @@ static bool php_cli_server_get_system_time(char *buf) {

gettimeofday(&tv, NULL);

/* TODO: should be checked for NULL tm/return value */
php_localtime_r(&tv.tv_sec, &tm);
php_asctime_r(&tm, buf);
return true;
if (!php_localtime_r(&tv.tv_sec, &tm)) {
return false;
}
return php_asctime_r(&tm, buf) != NULL;
}
#endif

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

// TODO Return value is unused, refactor?
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)) /* {{{ */
{
zend_result retval = SUCCESS;
Expand Down Expand Up @@ -2214,10 +2213,9 @@ static void php_cli_server_request_shutdown(php_cli_server *server, php_cli_serv
}
/* }}} */

// TODO Use bool, return value is strange
static int php_cli_server_dispatch_router(php_cli_server *server, php_cli_server_client *client) /* {{{ */
static bool php_cli_server_dispatch_router(php_cli_server *server, php_cli_server_client *client) /* {{{ */
{
int decline = 0;
bool decline = false;
zend_file_handle zfd;
char *old_cwd;

Expand Down Expand Up @@ -2269,7 +2267,7 @@ static zend_result php_cli_server_dispatch(php_cli_server *server, php_cli_serve
if (server->router || !is_static_file) {
if (FAILURE == php_cli_server_request_startup(server, client)) {
php_cli_server_request_shutdown(server, client);
return SUCCESS;
return FAILURE;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove the TODO comment above the function definition?

}
}

Expand Down Expand Up @@ -2610,8 +2608,7 @@ static zend_result php_cli_server_recv_event_read_request(php_cli_server *server
return php_cli_server_send_error_page(server, client, 501);
}
php_cli_server_poller_remove(&server->poller, POLLIN, client->sock);
php_cli_server_dispatch(server, client);
return SUCCESS;
return php_cli_server_dispatch(server, client);
case 0:
php_cli_server_poller_add(&server->poller, POLLIN, client->sock);
return SUCCESS;
Expand Down Expand Up @@ -2657,7 +2654,6 @@ typedef struct php_cli_server_do_event_for_each_fd_callback_params {
zend_result(*whandler)(php_cli_server*, php_cli_server_client*);
} php_cli_server_do_event_for_each_fd_callback_params;

// TODO return FAILURE on failure???
static zend_result php_cli_server_do_event_for_each_fd_callback(void *_params, php_socket_t fd, int event) /* {{{ */
{
php_cli_server_do_event_for_each_fd_callback_params *params = _params;
Expand All @@ -2677,12 +2673,12 @@ static zend_result php_cli_server_do_event_for_each_fd_callback(void *_params, p
efree(errstr);
}
pefree(sa, 1);
return SUCCESS;
return FAILURE;
}
if (SUCCESS != php_set_sock_blocking(client_sock, 0)) {
pefree(sa, 1);
closesocket(client_sock);
return SUCCESS;
return FAILURE;
}
client = pemalloc(sizeof(php_cli_server_client), 1);

Expand Down Expand Up @@ -2717,10 +2713,11 @@ static void php_cli_server_do_event_for_each_fd(php_cli_server *server,
whandler
};

php_cli_server_poller_iter_on_active(&server->poller, &params, php_cli_server_do_event_for_each_fd_callback);
if (SUCCESS != php_cli_server_poller_iter_on_active(&server->poller, &params, php_cli_server_do_event_for_each_fd_callback)) {
php_cli_server_logf(PHP_CLI_SERVER_LOG_ERROR, "Failed to poll event");
}
} /* }}} */

// TODO Return value of function is not used
static zend_result php_cli_server_do_event_loop(php_cli_server *server) /* {{{ */
{
zend_result retval = SUCCESS;
Expand Down Expand Up @@ -2763,7 +2760,7 @@ int do_cli_server(int argc, char **argv) /* {{{ */
{
char *php_optarg = NULL;
int php_optind = 1;
int c;
int c, r;
const char *server_bind_address = NULL;
extern const opt_struct OPTIONS[];
const char *document_root = NULL;
Expand Down Expand Up @@ -2841,6 +2838,7 @@ int do_cli_server(int argc, char **argv) /* {{{ */
sapi_module.phpinfo_as_text = 0;

{
r = 0;
bool ipv6 = strchr(server.host, ':');
php_cli_server_logf(
PHP_CLI_SERVER_LOG_PROCESS,
Expand All @@ -2859,7 +2857,9 @@ int do_cli_server(int argc, char **argv) /* {{{ */

zend_signal_init();

php_cli_server_do_event_loop(&server);
if (SUCCESS != php_cli_server_do_event_loop(&server)) {
r = 1;
}
php_cli_server_dtor(&server);
return 0;
return r;
} /* }}} */