Skip to content
Snippets Groups Projects
Commit 38b9bc8a authored by Rob Swindell's avatar Rob Swindell :speech_balloon:
Browse files

Add UNIX domain FastCGI support

Resolves a long-standing todo comment and has made wiki.synchro.net page
rendering even faster.

PHP-FPM defaults to creating/listening on UNIX domain sockets.

This resolves gitlab issue #507
parent fe30acd5
No related branches found
No related tags found
1 merge request!463MRC mods by Codefenix (2024-10-20)
Pipeline #3729 failed
...@@ -30,8 +30,6 @@ ...@@ -30,8 +30,6 @@
* *
* Add support for multipart/form-data * Add support for multipart/form-data
* *
* Add support for UNIX-domain sockets for FastCGI
*
* Improved Win32 support for POST data... currently will read past Content-Length * Improved Win32 support for POST data... currently will read past Content-Length
* *
*/ */
...@@ -3926,51 +3924,71 @@ static SOCKET fastcgi_connect(const char *orig_path, SOCKET client_sock) ...@@ -3926,51 +3924,71 @@ static SOCKET fastcgi_connect(const char *orig_path, SOCKET client_sock)
{ {
int result; int result;
char *path = strdup(orig_path); char *path = strdup(orig_path);
char *port = split_port_part(path);
ulong val; ulong val;
SOCKET sock; SOCKET sock;
struct addrinfo hints,*res,*cur;
// TODO: UNIX-domain sockets...
if (strncmp(path, "unix:", 5) == 0) { if (strncmp(path, "unix:", 5) == 0) {
lprintf(LOG_ERR, "%04d UNIX-domain FastCGI sockets not supported (yet)", client_sock); // UNIX-domain socket
free(path); struct sockaddr_un addr;
return INVALID_SOCKET; socklen_t addr_len;
} sock = socket(AF_UNIX, SOCK_STREAM, 0);
if (sock == INVALID_SOCKET) {
// TCP Socket lprintf(LOG_ERR, "%04d ERROR creating UNIX domain FastCGI socket", client_sock);
memset(&hints, 0, sizeof(hints)); free(path);
hints.ai_socktype = SOCK_STREAM; return sock;
hints.ai_flags = AI_ADDRCONFIG; }
result = getaddrinfo(path, port, &hints, &res);
if(result != 0) { addr.sun_family = AF_UNIX;
lprintf(LOG_ERR, "%04d ERROR resolving FastCGI address %s port %s", client_sock, path, port); SAFECOPY(addr.sun_path, path + 5);
free(path); #ifdef SUN_LEN
return INVALID_SOCKET; addr_len = SUN_LEN(&addr);
} #else
for(cur=res,result=1; result && cur; cur=cur->ai_next) { addr_len = sizeof(addr);
sock = socket(cur->ai_family, cur->ai_socktype, cur->ai_protocol); #endif
if (sock == INVALID_SOCKET) if(connect(sock, (struct sockaddr*)&addr, addr_len) != 0) {
continue; lprintf(LOG_ERR, "%04d ERROR %d connecting to UNIX domain FastCGI socket: %s"
val=1; ,client_sock, ERROR_VALUE, addr.sun_path);
ioctlsocket(sock,FIONBIO,&val); closesocket(sock);
result=connect(sock, cur->ai_addr, cur->ai_addrlen); sock = INVALID_SOCKET;
}
if (result==SOCKET_ERROR) { } else {
if((ERROR_VALUE==EWOULDBLOCK || ERROR_VALUE==EINPROGRESS)) { // TCP Socket
if (socket_writable(sock, 1000 /* TODO: Make configurable! */)) char *port = split_port_part(path);
result=0; /* success */ struct addrinfo hints,*res,*cur;
memset(&hints, 0, sizeof(hints));
hints.ai_socktype = SOCK_STREAM;
hints.ai_flags = AI_ADDRCONFIG;
result = getaddrinfo(path, port, &hints, &res);
if(result != 0) {
lprintf(LOG_ERR, "%04d ERROR resolving FastCGI address %s port %s", client_sock, path, port);
free(path);
return INVALID_SOCKET;
}
for(cur=res,result=1; result && cur; cur=cur->ai_next) {
sock = socket(cur->ai_family, cur->ai_socktype, cur->ai_protocol);
if (sock == INVALID_SOCKET)
continue;
val=1;
ioctlsocket(sock,FIONBIO,&val);
result=connect(sock, cur->ai_addr, cur->ai_addrlen);
if (result==SOCKET_ERROR) {
if((ERROR_VALUE==EWOULDBLOCK || ERROR_VALUE==EINPROGRESS)) {
if (socket_writable(sock, 1000 /* TODO: Make configurable! */))
result=0; /* success */
else
closesocket(sock);
}
else else
closesocket(sock); closesocket(sock);
} }
else if(result==0)
closesocket(sock); break;
} }
if(result==0)
break;
}
freeaddrinfo(res); freeaddrinfo(res);
}
if(sock == INVALID_SOCKET) { if(sock == INVALID_SOCKET) {
lprintf(LOG_ERR, "%04d ERROR unable to make FastCGI connection to %s", client_sock, orig_path); lprintf(LOG_ERR, "%04d ERROR unable to make FastCGI connection to %s", client_sock, orig_path);
free(path); free(path);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment