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 @@
*
* 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
*
*/
......@@ -3926,51 +3924,71 @@ static SOCKET fastcgi_connect(const char *orig_path, SOCKET client_sock)
{
int result;
char *path = strdup(orig_path);
char *port = split_port_part(path);
ulong val;
SOCKET sock;
struct addrinfo hints,*res,*cur;
// TODO: UNIX-domain sockets...
if (strncmp(path, "unix:", 5) == 0) {
lprintf(LOG_ERR, "%04d UNIX-domain FastCGI sockets not supported (yet)", client_sock);
free(path);
return INVALID_SOCKET;
}
// TCP Socket
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 */
// UNIX-domain socket
struct sockaddr_un addr;
socklen_t addr_len;
sock = socket(AF_UNIX, SOCK_STREAM, 0);
if (sock == INVALID_SOCKET) {
lprintf(LOG_ERR, "%04d ERROR creating UNIX domain FastCGI socket", client_sock);
free(path);
return sock;
}
addr.sun_family = AF_UNIX;
SAFECOPY(addr.sun_path, path + 5);
#ifdef SUN_LEN
addr_len = SUN_LEN(&addr);
#else
addr_len = sizeof(addr);
#endif
if(connect(sock, (struct sockaddr*)&addr, addr_len) != 0) {
lprintf(LOG_ERR, "%04d ERROR %d connecting to UNIX domain FastCGI socket: %s"
,client_sock, ERROR_VALUE, addr.sun_path);
closesocket(sock);
sock = INVALID_SOCKET;
}
} else {
// TCP Socket
char *port = split_port_part(path);
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
closesocket(sock);
}
else
closesocket(sock);
if(result==0)
break;
}
if(result==0)
break;
}
freeaddrinfo(res);
freeaddrinfo(res);
}
if(sock == INVALID_SOCKET) {
lprintf(LOG_ERR, "%04d ERROR unable to make FastCGI connection to %s", client_sock, orig_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