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