Neutrino Newgroup & STATE_REPLY

Hi,
I tried to post this to the Neutrino newsgroup, but it would not post
and there was no clear reason why ?? – Any ideas on the following:

I am working on getting 2 programs to talk to each other, and have
implemented time outs on the MsgSend and MsgReceive. I can get it all
to work except for STATE_REPLY blocking on the sender. It will time out
on MsgSend if I don’t receive, but if I receive and don’t reply, then
the sending program hangs in the Reply State and does not time out.

Source code follows: (sorry the indenting has gone all to %&$@#)

Makefile for 2 program that talk to each other

LDFLAGS= -lm
CFLAGS= -c -I. -g
CC= qcc

all::client

client: client.o
$(CC) -o client client.o $(LDFLAGS)

client.o: client.c
$(CC) client.c $(CFLAGS)

all:: server

server: server.o
$(CC) -o server server.o $(LDFLAGS)

server.o: server.c
$(CC) server.c $(CFLAGS)

//
// Client.c program that talks to a simple server!
//

#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>
#include <errno.h>
#include <sys/neutrino.h>
#include <sys/types.h>
#include <time.h>
#include <spawn.h>
#include <process.h>
#include <unistd.h>

int commchan, commcon;

#define TWOSECS (2.0e9) // 2 seconds

int main(int argc, char** argv)
{
int i;
struct sigevent event;
pid_t server_pid;
int message_id;
struct inheritance inherit;
_uint64 timeout = 1.0e6; // In Nanoseconds!
iov_t sndiov;
iov_t rcviov;
unsigned flags =
_NTO_CHF_FIXED_PRIORITY |
_NTO_CHF_SENDER_LEN |
_NTO_CHF_UNBLOCK ;
char* serv_args[2] = {“server”, };
serv_args[1] = NULL;

printf(“Hello, I am the Client\n”);

timeout = TWOSECS;

inherit.flags = 0;
server_pid = spawn(“server”, 0, NULL, &inherit, serv_args,
NULL);

if (server_pid != -1)
printf(“Server has been spawned %d\n”, server_pid);
else
{
perror("Server not spawned ");
exit(1);
}

// Give the server a moment to start running !
sleep(1);

commchan = 1;
commcon = ConnectAttach(0, server_pid, commchan, 0, flags);

if (commcon >= 0)
printf(“Connect Attach worked %d \n”, commcon);
else
{
perror("Connect Attach did not work: ");
if (kill(server_pid, SIGKILL) == -1)
perror(“Could not kill the server:”);
else
printf(“Killed the server\n”);
exit(1);
}

for (i = 0; i < 100; i++)
{
printf(“Hello from Client %d\n”, i);
// Tel the server a weird number.
message_id = i * 27;

event.sigev_notify = SIGEV_UNBLOCK;
TimerTimeout(CLOCK_REALTIME, _NTO_TIMEOUT_SEND |
_NTO_TIMEOUT_REPLY, &event,
&timeout, NULL);

SETIOV(&sndiov, &message_id, sizeof(int));

// if (MsgSend(commcon, (void )&message_id,
sizeof(int), (void
)&timeis,
sizeof(float)) == -1)

if (MsgSendv(commcon, &sndiov, 1, NULL, 0) == -1)
{
if (errno != 260) // Timeout is “somewhat”
expected
{
perror("Client MsgSend failed: ");
break;
}
else
printf(“Client time out\n”);
}
sleep(1);
}

printf(“Client Exits\n”);
exit(0);
}

// Server.c program that replies to client!

#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <sys/neutrino.h>

#define TWOSECS (2.0e9) // 2 seconds in nanoseconds

int main(int argc, char** argv)
{
int i, rcvid;
struct sigevent event;
int msgcode;
int tickchan;
struct _msg_info info;
_uint64 timeout = 1.0e8; // In Nanoseconds! = 1 millisecond
unsigned flags =
_NTO_CHF_FIXED_PRIORITY |
_NTO_CHF_SENDER_LEN |
_NTO_CHF_UNBLOCK ;

timeout = TWOSECS;

printf(“Hello, I am the Server %d, I was created by %d\n”, getpid(),
getppid());

tickchan = ChannelCreate(flags);
printf(“Server channel created %d \n”, tickchan);

sleep(1); // Just to get (roughly) in time with the client

for (i = 0; i < 10; i++)
{
printf(“Hello from Server %d\n”, i);

/* Now process input if any */

event.sigev_notify = SIGEV_UNBLOCK;
TimerTimeout(CLOCK_REALTIME, _NTO_TIMEOUT_RECEIVE,
&event, &timeout, NULL);
if ((rcvid = MsgReceive(tickchan, (void *)&msgcode,
sizeof(msgcode), &info)) == -1)
{
if (errno != 260) // Timeout is (somewhat) expected
{
perror("Server MsgReceive failed: ");
}
else
printf(“Server time out\n”);
}
else
{
printf(“Message receive %d \n”, msgcode);

// Let’s see if we can trigger a STATE_REPLY timeout
if (i == 4)
printf(“Receiving message %d, no reply \n”, i);
else
MsgReply(rcvid, EOK, NULL, 0);
}
sleep(1);
}


sleep(8);
printf(“Server exits\n”);
exit(0);
}

\

Simon Wakley

“Simon Wakley” <Simon@cameracontrol.com> wrote in message
news:JDZcSFAnXLA6EwBJ@cameracontrol.com

Hi,
I tried to post this to the Neutrino newsgroup, but it would not post
and there was no clear reason why ?? – Any ideas on the following:

There is a clear reason, post was made today about it. It says:



I am working on getting 2 programs to talk to each other, and have
implemented time outs on the MsgSend and MsgReceive. I can get it all
to work except for STATE_REPLY blocking on the sender. It will time out
on MsgSend if I don’t receive, but if I receive and don’t reply, then
the sending program hangs in the Reply State and does not time out.

Source code follows: (sorry the indenting has gone all to %&$@#)

Makefile for 2 program that talk to each other

LDFLAGS= -lm
CFLAGS= -c -I. -g
CC= qcc

all::client

client: client.o
$(CC) -o client client.o $(LDFLAGS)

client.o: client.c
$(CC) client.c $(CFLAGS)

all:: server

server: server.o
$(CC) -o server server.o $(LDFLAGS)

server.o: server.c
$(CC) server.c $(CFLAGS)

//
// Client.c program that talks to a simple server!
//

#include <stdio.h
#include <stdlib.h
#include <pthread.h
#include <errno.h
#include <sys/neutrino.h
#include <sys/types.h
#include <time.h
#include <spawn.h
#include <process.h
#include <unistd.h

int commchan, commcon;

#define TWOSECS (2.0e9) // 2 seconds

int main(int argc, char** argv)
{
int i;
struct sigevent event;
pid_t server_pid;
int message_id;
struct inheritance inherit;
_uint64 timeout = 1.0e6; // In Nanoseconds!
iov_t sndiov;
iov_t rcviov;
unsigned flags =
_NTO_CHF_FIXED_PRIORITY |
_NTO_CHF_SENDER_LEN |
_NTO_CHF_UNBLOCK ;
char* serv_args[2] = {“server”, };
serv_args[1] = NULL;

printf(“Hello, I am the Client\n”);

timeout = TWOSECS;

inherit.flags = 0;
server_pid = spawn(“server”, 0, NULL, &inherit, serv_args,
NULL);

if (server_pid != -1)
printf(“Server has been spawned %d\n”, server_pid);
else
{
perror("Server not spawned ");
exit(1);
}

// Give the server a moment to start running !
sleep(1);

commchan = 1;
commcon = ConnectAttach(0, server_pid, commchan, 0, flags);

if (commcon >= 0)
printf(“Connect Attach worked %d \n”, commcon);
else
{
perror("Connect Attach did not work: ");
if (kill(server_pid, SIGKILL) == -1)
perror(“Could not kill the server:”);
else
printf(“Killed the server\n”);
exit(1);
}

for (i = 0; i < 100; i++)
{
printf(“Hello from Client %d\n”, i);
// Tel the server a weird number.
message_id = i * 27;

event.sigev_notify = SIGEV_UNBLOCK;
TimerTimeout(CLOCK_REALTIME, _NTO_TIMEOUT_SEND |
_NTO_TIMEOUT_REPLY, &event,
&timeout, NULL);

SETIOV(&sndiov, &message_id, sizeof(int));

// if (MsgSend(commcon, (void )&message_id,
sizeof(int), (void
)&timeis,
sizeof(float)) == -1)

if (MsgSendv(commcon, &sndiov, 1, NULL, 0) == -1)
{
if (errno != 260) // Timeout is “somewhat”
expected
{
perror("Client MsgSend failed: ");
break;
}
else
printf(“Client time out\n”);
}
sleep(1);
}

printf(“Client Exits\n”);
exit(0);
}

// Server.c program that replies to client!

#include <stdio.h
#include <stdlib.h
#include <errno.h
#include <sys/neutrino.h

#define TWOSECS (2.0e9) // 2 seconds in nanoseconds

int main(int argc, char** argv)
{
int i, rcvid;
struct sigevent event;
int msgcode;
int tickchan;
struct _msg_info info;
_uint64 timeout = 1.0e8; // In Nanoseconds! = 1 millisecond
unsigned flags =
_NTO_CHF_FIXED_PRIORITY |
_NTO_CHF_SENDER_LEN |
_NTO_CHF_UNBLOCK ;

timeout = TWOSECS;

printf(“Hello, I am the Server %d, I was created by %d\n”, getpid(),
getppid());

tickchan = ChannelCreate(flags);
printf(“Server channel created %d \n”, tickchan);

sleep(1); // Just to get (roughly) in time with the client

for (i = 0; i < 10; i++)
{
printf(“Hello from Server %d\n”, i);

/* Now process input if any */

event.sigev_notify = SIGEV_UNBLOCK;
TimerTimeout(CLOCK_REALTIME, _NTO_TIMEOUT_RECEIVE,
&event, &timeout, NULL);
if ((rcvid = MsgReceive(tickchan, (void *)&msgcode,
sizeof(msgcode), &info)) == -1)
{
if (errno != 260) // Timeout is (somewhat) expected
{
perror("Server MsgReceive failed: ");
}
else
printf(“Server time out\n”);
}
else
{
printf(“Message receive %d \n”, msgcode);

// Let’s see if we can trigger a STATE_REPLY timeout
if (i == 4)
printf(“Receiving message %d, no reply \n”, i);
else
MsgReply(rcvid, EOK, NULL, 0);
}
sleep(1);
}


sleep(8);
printf(“Server exits\n”);
exit(0);
}

\

Simon Wakley

“Simon Wakley” <Simon@cameracontrol.com> wrote in message
news:JDZcSFAnXLA6EwBJ@cameracontrol.com

Hi,
I tried to post this to the Neutrino newsgroup, but it would not post
and there was no clear reason why ?? – Any ideas on the following:

Sorry it the wrong key, it says:

This newsgroup is now read only.
Please post QNX Neutrino issues in qdn.public.qnxrtp.os

I am working on getting 2 programs to talk to each other, and have
implemented time outs on the MsgSend and MsgReceive. I can get it all
to work except for STATE_REPLY blocking on the sender. It will time out
on MsgSend if I don’t receive, but if I receive and don’t reply, then
the sending program hangs in the Reply State and does not time out.

Source code follows: (sorry the indenting has gone all to %&$@#)

Makefile for 2 program that talk to each other

LDFLAGS= -lm
CFLAGS= -c -I. -g
CC= qcc

all::client

client: client.o
$(CC) -o client client.o $(LDFLAGS)

client.o: client.c
$(CC) client.c $(CFLAGS)

all:: server

server: server.o
$(CC) -o server server.o $(LDFLAGS)

server.o: server.c
$(CC) server.c $(CFLAGS)

//
// Client.c program that talks to a simple server!
//

#include <stdio.h
#include <stdlib.h
#include <pthread.h
#include <errno.h
#include <sys/neutrino.h
#include <sys/types.h
#include <time.h
#include <spawn.h
#include <process.h
#include <unistd.h

int commchan, commcon;

#define TWOSECS (2.0e9) // 2 seconds

int main(int argc, char** argv)
{
int i;
struct sigevent event;
pid_t server_pid;
int message_id;
struct inheritance inherit;
_uint64 timeout = 1.0e6; // In Nanoseconds!
iov_t sndiov;
iov_t rcviov;
unsigned flags =
_NTO_CHF_FIXED_PRIORITY |
_NTO_CHF_SENDER_LEN |
_NTO_CHF_UNBLOCK ;
char* serv_args[2] = {“server”, };
serv_args[1] = NULL;

printf(“Hello, I am the Client\n”);

timeout = TWOSECS;

inherit.flags = 0;
server_pid = spawn(“server”, 0, NULL, &inherit, serv_args,
NULL);

if (server_pid != -1)
printf(“Server has been spawned %d\n”, server_pid);
else
{
perror("Server not spawned ");
exit(1);
}

// Give the server a moment to start running !
sleep(1);

commchan = 1;
commcon = ConnectAttach(0, server_pid, commchan, 0, flags);

if (commcon >= 0)
printf(“Connect Attach worked %d \n”, commcon);
else
{
perror("Connect Attach did not work: ");
if (kill(server_pid, SIGKILL) == -1)
perror(“Could not kill the server:”);
else
printf(“Killed the server\n”);
exit(1);
}

for (i = 0; i < 100; i++)
{
printf(“Hello from Client %d\n”, i);
// Tel the server a weird number.
message_id = i * 27;

event.sigev_notify = SIGEV_UNBLOCK;
TimerTimeout(CLOCK_REALTIME, _NTO_TIMEOUT_SEND |
_NTO_TIMEOUT_REPLY, &event,
&timeout, NULL);

SETIOV(&sndiov, &message_id, sizeof(int));

// if (MsgSend(commcon, (void )&message_id,
sizeof(int), (void
)&timeis,
sizeof(float)) == -1)

if (MsgSendv(commcon, &sndiov, 1, NULL, 0) == -1)
{
if (errno != 260) // Timeout is “somewhat”
expected
{
perror("Client MsgSend failed: ");
break;
}
else
printf(“Client time out\n”);
}
sleep(1);
}

printf(“Client Exits\n”);
exit(0);
}

// Server.c program that replies to client!

#include <stdio.h
#include <stdlib.h
#include <errno.h
#include <sys/neutrino.h

#define TWOSECS (2.0e9) // 2 seconds in nanoseconds

int main(int argc, char** argv)
{
int i, rcvid;
struct sigevent event;
int msgcode;
int tickchan;
struct _msg_info info;
_uint64 timeout = 1.0e8; // In Nanoseconds! = 1 millisecond
unsigned flags =
_NTO_CHF_FIXED_PRIORITY |
_NTO_CHF_SENDER_LEN |
_NTO_CHF_UNBLOCK ;

timeout = TWOSECS;

printf(“Hello, I am the Server %d, I was created by %d\n”, getpid(),
getppid());

tickchan = ChannelCreate(flags);
printf(“Server channel created %d \n”, tickchan);

sleep(1); // Just to get (roughly) in time with the client

for (i = 0; i < 10; i++)
{
printf(“Hello from Server %d\n”, i);

/* Now process input if any */

event.sigev_notify = SIGEV_UNBLOCK;
TimerTimeout(CLOCK_REALTIME, _NTO_TIMEOUT_RECEIVE,
&event, &timeout, NULL);
if ((rcvid = MsgReceive(tickchan, (void *)&msgcode,
sizeof(msgcode), &info)) == -1)
{
if (errno != 260) // Timeout is (somewhat) expected
{
perror("Server MsgReceive failed: ");
}
else
printf(“Server time out\n”);
}
else
{
printf(“Message receive %d \n”, msgcode);

// Let’s see if we can trigger a STATE_REPLY timeout
if (i == 4)
printf(“Receiving message %d, no reply \n”, i);
else
MsgReply(rcvid, EOK, NULL, 0);
}
sleep(1);
}


sleep(8);
printf(“Server exits\n”);
exit(0);
}

\

Simon Wakley

Simon Wakley <Simon@cameracontrol.com> wrote:

Hi,
I tried to post this to the Neutrino newsgroup, but it would not post
and there was no clear reason why ?? – Any ideas on the following:

That newsgroup is now READ ONLY. As others have posted, there are now
other newsgroups for this sort of post.

I am working on getting 2 programs to talk to each other, and have
implemented time outs on the MsgSend and MsgReceive. I can get it all
to work except for STATE_REPLY blocking on the sender. It will time out
on MsgSend if I don’t receive, but if I receive and don’t reply, then
the sending program hangs in the Reply State and does not time out.

In your ChannelCreate(), you pass the flag _NTO_CHF_UNBLOCK, asking
for a pulse when anybody reply blocked on you tries to unblock (signal|
timeout), but in your server code you don’t handle this pulse. By setting
this, you prevent the client from ever unblocking until the server replies
to the client. Pulse come in with a rcvid of 0 – and inside the pulse it
will identify which client (by rcvid) has been unblocked.

-David

Source code follows: (sorry the indenting has gone all to %&$@#)

Makefile for 2 program that talk to each other

LDFLAGS= -lm
CFLAGS= -c -I. -g
CC= qcc

all::client

client: client.o
$(CC) -o client client.o $(LDFLAGS)

client.o: client.c
$(CC) client.c $(CFLAGS)

all:: server

server: server.o
$(CC) -o server server.o $(LDFLAGS)

server.o: server.c
$(CC) server.c $(CFLAGS)

//
// Client.c program that talks to a simple server!
//

#include <stdio.h
#include <stdlib.h
#include <pthread.h
#include <errno.h
#include <sys/neutrino.h
#include <sys/types.h
#include <time.h
#include <spawn.h
#include <process.h
#include <unistd.h

int commchan, commcon;

#define TWOSECS (2.0e9) // 2 seconds

int main(int argc, char** argv)
{
int i;
struct sigevent event;
pid_t server_pid;
int message_id;
struct inheritance inherit;
_uint64 timeout = 1.0e6; // In Nanoseconds!
iov_t sndiov;
iov_t rcviov;
unsigned flags =
_NTO_CHF_FIXED_PRIORITY |
_NTO_CHF_SENDER_LEN |
_NTO_CHF_UNBLOCK ;
char* serv_args[2] = {“server”, };
serv_args[1] = NULL;

printf(“Hello, I am the Client\n”);

timeout = TWOSECS;

inherit.flags = 0;
server_pid = spawn(“server”, 0, NULL, &inherit, serv_args,
NULL);

if (server_pid != -1)
printf(“Server has been spawned %d\n”, server_pid);
else
{
perror("Server not spawned ");
exit(1);
}

// Give the server a moment to start running !
sleep(1);

commchan = 1;
commcon = ConnectAttach(0, server_pid, commchan, 0, flags);

if (commcon >= 0)
printf(“Connect Attach worked %d \n”, commcon);
else
{
perror("Connect Attach did not work: ");
if (kill(server_pid, SIGKILL) == -1)
perror(“Could not kill the server:”);
else
printf(“Killed the server\n”);
exit(1);
}

for (i = 0; i < 100; i++)
{
printf(“Hello from Client %d\n”, i);
// Tel the server a weird number.
message_id = i * 27;

event.sigev_notify = SIGEV_UNBLOCK;
TimerTimeout(CLOCK_REALTIME, _NTO_TIMEOUT_SEND |
_NTO_TIMEOUT_REPLY, &event,
&timeout, NULL);

SETIOV(&sndiov, &message_id, sizeof(int));

// if (MsgSend(commcon, (void )&message_id,
sizeof(int), (void
)&timeis,
sizeof(float)) == -1)

if (MsgSendv(commcon, &sndiov, 1, NULL, 0) == -1)
{
if (errno != 260) // Timeout is “somewhat”
expected
{
perror("Client MsgSend failed: ");
break;
}
else
printf(“Client time out\n”);
}
sleep(1);
}

printf(“Client Exits\n”);
exit(0);
}

// Server.c program that replies to client!

#include <stdio.h
#include <stdlib.h
#include <errno.h
#include <sys/neutrino.h

#define TWOSECS (2.0e9) // 2 seconds in nanoseconds

int main(int argc, char** argv)
{
int i, rcvid;
struct sigevent event;
int msgcode;
int tickchan;
struct _msg_info info;
_uint64 timeout = 1.0e8; // In Nanoseconds! = 1 millisecond
unsigned flags =
_NTO_CHF_FIXED_PRIORITY |
_NTO_CHF_SENDER_LEN |
_NTO_CHF_UNBLOCK ;

timeout = TWOSECS;

printf(“Hello, I am the Server %d, I was created by %d\n”, getpid(),
getppid());

tickchan = ChannelCreate(flags);
printf(“Server channel created %d \n”, tickchan);

sleep(1); // Just to get (roughly) in time with the client

for (i = 0; i < 10; i++)
{
printf(“Hello from Server %d\n”, i);

/* Now process input if any */

event.sigev_notify = SIGEV_UNBLOCK;
TimerTimeout(CLOCK_REALTIME, _NTO_TIMEOUT_RECEIVE,
&event, &timeout, NULL);
if ((rcvid = MsgReceive(tickchan, (void *)&msgcode,
sizeof(msgcode), &info)) == -1)
{
if (errno != 260) // Timeout is (somewhat) expected
{
perror("Server MsgReceive failed: ");
}
else
printf(“Server time out\n”);
}
else
{
printf(“Message receive %d \n”, msgcode);

// Let’s see if we can trigger a STATE_REPLY timeout
if (i == 4)
printf(“Receiving message %d, no reply \n”, i);
else
MsgReply(rcvid, EOK, NULL, 0);
}
sleep(1);
}


sleep(8);
printf(“Server exits\n”);
exit(0);
}


Simon Wakley

Simon Wakley wrote:

I tried to post this to the Neutrino newsgroup, but it would not post
and there was no clear reason why ??

They appear to have marked that newsgroup as being read-only;
not sure what that means for the fate of QNX vs Neutrino vs RTP;
could be a marketing reorientation, or perhaps the recent “uname”
postings explain it all somewhat?

– Any ideas on the following:
I am working on getting 2 programs to talk to each other, and have
implemented time outs on the MsgSend and MsgReceive. I can get it all

Ripping out a server that has Receive()d but not Reply()d is
generally a bad thing to do. It may leave the server internal
data structures in a bad state (it thinks it still has the
client blocked on it but that isn’t the case anymore) or may
cause message corruption (the server does eventually Reply()
but it is to a new/different client message, which is a real
possibility in a multi-threaded system).

You may know of the QNX4 _PPF_SIGNAL flag; the Neutrino
corolloary is the _NTO_CHF_UNBLOCK flag. What I suspect the
OS will do, is rather than unilaterally rip out the client,
it will send an unblock pulse to the server indicating this
intent. In your server you should already see this with your
existing code… do you get an additional “Message receive 0”
and “Hello from Server 6” messages printed? If so, that is the
unblock pulse. Make your receive object in the server larger
(to hold a struct _pulse) and this will allow your server to
see that the client wishes to timeout and that it should clean
up any client-specific-queuing data and make the Reply() now.

If this is not the case, and you don’t see these messages, perhaps
you could post the actual output from your test programs?