MsgReceive()

If a process is sitting on MsgReceive() waiting for a message and the sending process dies what should happen?

Normal operation MsgReceive returns a large rcvid > 65000 and I get the expected message.

When I slay the sending process I get a 4 byte empty message with a return value of 2.

If I set _NTO_CHF_DISCONNECT when the channel is created I get the expected pulse indicating the disconnect but the mysterious 4 byte blank message still preceeds it.

The docs indicate that a negative rcvid is returned with errno set.

Where is this 4 byte message coming from???

anybody?

Can you write a small test case and post it?

To reproduce execute the msgrectest and make not of pid and connection id. They are paramaters to the msgtest program. Connection id first then, pid.

Once message passing has begun slay the msgtest process and notice the rcvid of 2 with empty 4 byte message.

[size=150]msgrectest_g code[/size]

[code]#include <stdlib.h>
#include <stdio.h>

#include <sys/neutrino.h>
#include <errno.h>
#include <process.h>

int main(int argc, char *argv[])
{
int connection_id = 0;
int rcvid = 0;
char Incommingbuffer[500];
struct _pulse * p;
struct _msg_info info;

// create channel
if ( (connection_id = ChannelCreate(_NTO_CHF_DISCONNECT )) == -1)
{
	printf("Failed to Create the Channel\n");
	return 0;	
}

printf("Connection id is %d\n", connection_id);
printf("Process id is %d\n", getpid() );

for ( ; ; )
{
	
	memset(Incommingbuffer, '\0',500 );
	
	rcvid = MsgReceive(connection_id, Incommingbuffer, 500, &info);
			
	printf("rcvid id %d \n", rcvid);
	printf("Message is %s \n", Incommingbuffer);
	printf("length is %d \n", info.msglen );
				
	if (rcvid == 0 )
	{
		// got a pulse indicating logger died
		p = (void *)Incommingbuffer;
		if (p->code == _PULSE_CODE_DISCONNECT )
		{
			printf("Detected that the logger process died\n");
			exit(-1);	
		}
			
	}
	else
	{
		MsgReply(rcvid, EOK, NULL, 0);
			
	}
	
}
	


return EXIT_SUCCESS;

}[/code]

[size=150]msgtest_g code[/size]

[code]#include <stdlib.h>
#include <stdio.h>

#include <sys/neutrino.h>
#include <errno.h>
#include <string.h>
#include <unistd.h>

int main(int argc, char *argv[])

{
char outGoingBuffer[25];
int coid = 0;
int pid = 0;

strcpy(outGoingBuffer, "This is a test");

if (argc != 3)
{
	printf("Must invoke with channel id then process id");	
	exit(0);
}

coid = atoi(argv[1]);
pid = atoi(argv[2]);

printf("connecting to channel id %d\n", coid);
printf("connecting to process id %d\n", pid);

coid = ConnectAttach(0, pid, coid, 0, 0);

for ( ; ; )
{
	if(MsgSend(coid, &outGoingBuffer, 25, NULL, NULL) == -1)
	{
		printf("Error Sending Message: %s\n", strerror(errno));
	}	
	
	
	delay( 2000);
}


return EXIT_SUCCESS;

}[/code]

[size=150]msgrectest_g console[/size]

Connection id is 1
Process id is 2695211
rcvid id 2
Message is This is a test
length is 25
rcvid id 2
Message is
length is 4
rcvid id 0
Message is
length is 4
Detected that the logger process died

[size=150]msgtest_g console[/size]

./msgtest_g 1 2695211 &

[1] 2699308

connecting to channel id 1

connecting to process id 2695211

slay msgtest_g

[1] + Terminated ./msgtest_g 1 2695211

I think the 4 byte message you receive is a close message, when I look at the data that you received in Incommingbuffer I see the following data:
0x16 0x01 0x04 0x00
The 0x16 and 0x01 represent the message id which is 0x116 (@ base 0x100) which according to iomsg.h would be a io_close message.

I am told this is a relatively new thing but at least you know what it is now :slight_smile:

Cheers!

Eric

There should be something in _msg_info indicating it is a close message.

I guess I’ll have to hack in a cheap fix. If message is 4 bytes long and is 0x16 0x01 0x04 0x00, then ignore…

Thanks.

If you don’t want the close, create the channel as a NTO_SIDE_CHANNEL

New under qnx 6.3, there is a message when the connection happens, the first (short) element has the value of _IO_CONNECT. (i.e, ((short*) rcvBuffer)[0] == _IO_CONNECT). You are supposed to reply to it with MsgReply(rcvid, EOK, 0,0). Could that be your mystery message? I remember a post about this in the forum, but I don’t have the link on hand.