}
}
+static void fcgi_hook_dummy() {
+ return;
+}
+
FCGI_API fcgi_request *fcgi_init_request(fcgi_request *req, int listen_socket)
{
memset(req, 0, sizeof(fcgi_request));
*/
req->out_pos = req->out_buf;
+ req->hook.on_accept = fcgi_hook_dummy;
+ req->hook.on_read = fcgi_hook_dummy;
+ req->hook.on_close = fcgi_hook_dummy;
#ifdef _WIN32
req->tcp = !GetNamedPipeInfo((HANDLE)_get_osfhandle(req->listen_socket), NULL, NULL, NULL, NULL);
#endif
+
fcgi_hash_init(&req->env);
return req;
}
FCGI_API void fcgi_destroy_request(fcgi_request *req) {
- if (req->env.buckets) {
- fcgi_hash_destroy(&req->env);
- }
+ fcgi_hash_destroy(&req->env);
}
static inline ssize_t safe_write(fcgi_request *req, const void *buf, size_t count)
#endif
req->fd = -1;
- if (req->hook.on_close) {
- req->hook.on_close();
- }
+ req->hook.on_close();
}
}
sa_t sa;
socklen_t len = sizeof(sa);
- if (req->hook.on_accept) {
- req->hook.on_accept();
- }
+ req->hook.on_accept();
FCGI_LOCK(req->listen_socket);
req->fd = accept(listen_socket, (struct sockaddr *)&sa, &len);
struct pollfd fds;
int ret;
- if (req->hook.on_read) {
- req->hook.on_read();
- }
+ req->hook.on_read();
fds.fd = req->fd;
fds.events = POLLIN;
}
fcgi_close(req, 1, 0);
#else
- if (req->hook.on_read) {
- req->hook.on_read();
- }
+ req->hook.on_read();
if (req->fd < FD_SETSIZE) {
struct timeval tv = {5,0};
fpm_init_request(&request, fcgi_fd);
zend_first_try {
- while (fcgi_accept_request(&request) >= 0) {
+ while (EXPECTED(fcgi_accept_request(&request) >= 0)) {
request_body_fd = -1;
SG(server_context) = (void *) &request;
init_request_info();
/* request startup only after we've done all we can to
* get path_translated */
- if (php_request_startup() == FAILURE) {
+ if (UNEXPECTED(php_request_startup() == FAILURE)) {
fcgi_finish_request(&request, 1);
SG(server_context) = NULL;
php_module_shutdown();
/* check if request_method has been sent.
* if not, it's certainly not an HTTP over fcgi request */
- if (!SG(request_info).request_method) {
+ if (UNEXPECTED(!SG(request_info).request_method)) {
goto fastcgi_request_done;
}
- if (fpm_status_handle_request()) {
+ if (UNEXPECTED(fpm_status_handle_request())) {
goto fastcgi_request_done;
}
/* If path_translated is NULL, terminate here with a 404 */
- if (!SG(request_info).path_translated) {
+ if (UNEXPECTED(!SG(request_info).path_translated)) {
zend_try {
zlog(ZLOG_DEBUG, "Primary script unknown");
SG(sapi_headers).http_response_code = 404;
goto fastcgi_request_done;
}
- if (fpm_php_limit_extensions(SG(request_info).path_translated)) {
+ if (UNEXPECTED(fpm_php_limit_extensions(SG(request_info).path_translated))) {
SG(sapi_headers).http_response_code = 403;
PUTS("Access denied.\n");
goto fastcgi_request_done;
primary_script = estrdup(SG(request_info).path_translated);
/* path_translated exists, we can continue ! */
- if (php_fopen_primary_script(&file_handle) == FAILURE) {
+ if (UNEXPECTED(php_fopen_primary_script(&file_handle) == FAILURE)) {
zend_try {
zlog(ZLOG_ERROR, "Unable to open primary script: %s (%s)", primary_script, strerror(errno));
if (errno == EACCES) {
php_execute_script(&file_handle);
fastcgi_request_done:
- if (primary_script) {
+ if (EXPECTED(primary_script)) {
efree(primary_script);
}
- if (request_body_fd != -1) {
+ if (UNEXPECTED(request_body_fd != -1)) {
close(request_body_fd);
}
request_body_fd = -2;
- if (EG(exit_status) == 255) {
+ if (UNEXPECTED(EG(exit_status) == 255)) {
if (CGIG(error_header) && *CGIG(error_header)) {
sapi_header_line ctr = {0};
php_request_shutdown((void *) 0);
requests++;
- if (max_requests && (requests == max_requests)) {
+ if (UNEXPECTED(max_requests && (requests == max_requests))) {
fcgi_finish_request(&request, 1);
break;
}