[Info-vax] Apache + mod_php performance

Dan Cross cross at spitfire.i.gajendra.net
Fri Oct 11 10:14:53 EDT 2024


In article <vea6ak$3h25s$2 at dont-email.me>,
Dave Froble  <davef at tsoft-inc.com> wrote:
>On 10/7/2024 4:17 PM, Dan Cross wrote:
>> In article <ve1f1t$1mvdn$2 at dont-email.me>,
>> Arne Vajhøj  <arne at vajhoej.dk> wrote:
>>> On 10/7/2024 11:52 AM, Dan Cross wrote:
>>> $ cc zz
>>>
>>>    len = CMSG_SPACE(sizeof(int));
>>> .........^
>>> %CC-I-IMPLICITFUNC, In this statement, the identifier "CMSG_SPACE" is
>>> implicitly declared as a function.
>>> at line number 33 in file DKA0:[arne]zz.c;1
>>> [snip]
>>
>> Why would you try to build that under VMS?  It obviously would
>> not build or work there.
>
>Yeah, also wondered ...

I think he was confused.  His justification that VMS must not
support descriptor passing because of the errors he saw, and he
was just saying that, doesn't hold much water, either.

As I mentioned back in <vdk7fi$jdm$1 at reader1.panix.com>, the
descriptor passing mechanism was added in 4.2BSD, back in 1983,
but it was _updated_ in 4.4BSD, in 1994.  The code I posted
used the 4.4BSD mechansim.  Clearly, that isn't supported on VMS
as he showed, but that's not the only way to do it.

In particular, the 4.3BSD mechanism uses different fields in the
`struct msghdr` to move descriptors around, and those are at
least in the struct definitions on VMS.  Do they do anything?  I
kind of tend to doubt it, but for example the code below does
compile on Eisner, though I haven't written a driver to see if
it actually _works_.

	- Dan C.

/*
 * Example code to demonstrate file descriptor passing
 * over Berkeley sockets.
 *
 * Dan Cross <cross at gajendra.net>
 */
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/uio.h>
#include <sys/un.h>
#include <sys/wait.h>

#include <fcntl.h>
#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>

int
unix_server(char *path)
{
	int nsd, sd;
	socklen_t clen;
	struct sockaddr_un sock;

	sd = socket(AF_UNIX, SOCK_STREAM, 0);
	if (sd < 0) {
		perror("socket");
		exit(EXIT_FAILURE);
	}
	memset(&sock, 0, sizeof(sock));
	sock.sun_family = AF_UNIX;
	strncpy(sock.sun_path, path, sizeof(sock.sun_path));
	if (bind(sd, (struct sockaddr *)&sock, sizeof(sock)) < 0) {
		perror("bind");
		exit(EXIT_FAILURE);
	}
	if (listen(sd, 5) < 0) {
		perror("listen");
		exit(EXIT_FAILURE);
	}
	clen = sizeof(sock);
	nsd = accept(sd, (struct sockaddr *)&sock, &clen);
	if (nsd < 0) {
		perror("accept");
		exit(EXIT_FAILURE);
	}
	close(sd);

	return(nsd);
}

int
unix_client(char *path)
{
	int sd;
	struct sockaddr_un sock;

	sd = socket(AF_UNIX, SOCK_STREAM, 0);
	if (sd < 0) {
		perror("socket");
		exit(EXIT_FAILURE);
	}
	memset(&sock, 0, sizeof(sock));
	sock.sun_family = AF_UNIX;
	strncpy(sock.sun_path, path, sizeof(sock.sun_path));
	if (connect(sd, (struct sockaddr *)&sock, sizeof(sock)) < 0) {
		perror("connect");
		exit(EXIT_FAILURE);
	}

	return(sd);
}

/* Send a file descriptor; returns 1 on success, -1 on error */
int
send_fd(int sd, int fd)
{
	struct msghdr mh;
	struct iovec iv;
	char dummy;

	memset(&iv, 0, sizeof(iv));
	iv.iov_base = &dummy;
	iv.iov_len = sizeof(char);

	memset(&mh, 0, sizeof(mh));
	mh.msg_name = NULL;
	mh.msg_namelen = 0;
	mh.msg_iov = &iv;
	mh.msg_iovlen = 1;

	/* Now we copy in the file descriptor. */
	mh.msg_accrights = (caddr_t)&fd;
	mh.msg_accrightslen = sizeof(int);

	return(sendmsg(sd, &mh, 0));
}

/* Returns 1 on success, 0 on EOF, -1 on error. */
int
recv_fd(int sd, int *fdp)
{
	struct msghdr mh;
	struct iovec iv;
	int ret;
	char dummy;

	if (fdp == NULL)
		return(-1);

	memset(&iv, 0, sizeof(iv));
	iv.iov_base = &dummy;
	iv.iov_len = 1;

	memset(&mh, 0, sizeof(mh));
	mh.msg_name = NULL;
	mh.msg_namelen = 0;
	mh.msg_iov = &iv;
	mh.msg_iovlen = 1;
	mh.msg_accrights = (caddr_t)fdp;
	mh.msg_accrightslen = sizeof(int);

	if ((ret = recvmsg(sd, &mh, 0)) < 0)
		return(ret);

	if (mh.msg_accrightslen != sizeof(int))
		return(-1);

	return(1);
}


More information about the Info-vax mailing list