Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 13 Aug 2002 16:59:51 -0700
From:      Terry Lambert <tlambert2@mindspring.com>
To:        hiten@uk.FreeBSD.org
Cc:        freebsd-hackers@FreeBSD.org
Subject:   Re: SysV IPC related question
Message-ID:  <3D599D77.C1657E75@mindspring.com>
References:  <20020813233459.25838.qmail@web21102.mail.yahoo.com>

next in thread | previous in thread | raw e-mail | index | archive | help
Hiten Pandya wrote:
> OK.  One more question; so, is there any particular reason why our cousin
> NetBSD doesnt use this "overlay" structure?  Also, the NetBSD SysV Msg
> regression tool defines its own struct mymsg; and doesnt have one standard
> in the <sys/msg.h> header file.

I don't know why NetBSD doesn't have this.  Perhaps they are
unconcerned with the portability of code using SYSV message
queues, when it comes to internal structure packing.

I would think directly casting it to a long in the kernel would
be a bad thing on Alpha, with certain source code in user space.

I expect that they define it for the regression test so that
they can actually do regression on these cases.


> Also, if possible, could you outline some situations where this would be
> used?  Help will be very appreicated.

It's because if you don't ask for a specific meswsage type (e.g.
it is important for you to get messages in the order they were
sent), then you can't control which message will be returned in
your message buffer passed to msgrcv(2).

Example:
----------
	struct mymsg {
		long	mtype;
		char	mtest[1];
	};

	#define	MTYPE_A		75
	struct msg_a {
		long	mtype;
		int	id;
		char	name[ 8];
	};

	#define	MTYPE_B		76
	struct msg_b {
		long	mtype;
		char	msg[ 16];
		struct stat data;
	};

	typedef union {
		struct mymsg	mymsg;
		struct msg_a	a;
		struct mdg_b	b;
	} msg_t;



		msg_t	msg;

                /* p3 = 0 :== receive any message */
                if ( msgrcv(msqid, &msg, sizeof(msg), 0, 0) == -1) {
                        perror("msgsnd");
                        exit( 3);
                }

		switch( msg.mymsg.mtype) {
		case MTYPE_A:
			printf( "name=%s, id = %d\n",
				msg.a.name,
				msg.a.id);
			break;
		case MTYPE_B:
			printf( "Result '%s', size= %d\n",
				msg.b.msg,
				msg.b.data.st_size);
			break;
		default:
			printf "Unrecognized message type: %d\n",
				msg.mymsg.mtype);
			break;
		}
----------

-- Terry

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-hackers" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?3D599D77.C1657E75>