the server code:
#include <stdio.h>
#include <stdlib.h>
#include <limits.h>
#include <errno.h>
#include <iostream.h>
#include <unistd.h>
#include <time.h>
#include <inttypes.h>
#include <pthread.h>
#include <sched.h>
#include <sys/dispatch.h>
#include <sys/neutrino.h>
#include <sys/mman.h>
#include <sys/syspage.h>
#include <hw/inout.h>
void Tempo( int v )
{
while( v ) {
for( int ii = 0; ii < 1000000 ; ii++ );
v–;
}
}
#define ATTACH_POINT “myname”
/* We specify the header as being at least a pulse */
typedef struct _pulse msg_header_t;
/* Our real data comes after the header */
typedef struct _my_data {
msg_header_t hdr;
int data;
} my_data_t;
/*** Server Side of the code ***/
int main() {
name_attach_t *attach;
my_data_t msg;
int rcvid;
/* Create a local name (/dev/name/local/...) */
if ((attach = name_attach(NULL, ATTACH_POINT, 0)) == NULL) {
return EXIT_FAILURE;
}
/* Do your MsgReceive's here now with the chid */
while (1) {
rcvid = MsgReceive(attach->chid, &msg, sizeof(msg), NULL);
if (rcvid == -1) {/* Error condition, exit */
break;
}
if (rcvid == 0) {/* Pulse received */
switch (msg.hdr.code) {
case _PULSE_CODE_DISCONNECT:
/*
* A client disconnected all its connections (called
* name_close() for each name_open() of our name) or
* terminated
*/
ConnectDetach(msg.hdr.scoid);
break;
case _PULSE_CODE_UNBLOCK:
/*
* REPLY blocked client wants to unblock (was hit by
* a signal or timed out). It's up to you if you
* reply now or later.
*/
break;
default:
/*
* A pulse sent by one of your processes or a
* _PULSE_CODE_COIDDEATH or _PULSE_CODE_THREADDEATH
* from the kernel?
*/
continue;
}
}
/* A QNX IO message received, reject */
if (msg.hdr.type >= _IO_BASE && msg.hdr.type <= _IO_MAX) {
MsgError(rcvid, ENOSYS);
continue;
}
/* A message (presumable ours) received, handle */
printf("Server receive %d \n", msg.data);
Tempo(5000);
MsgReply(rcvid, EOK, 0, 0);
}
/* Remove the name from the space */
name_detach(attach, 0);
return EXIT_SUCCESS;
}
C1 code:
#include <stdio.h>
#include <stdlib.h>
#include <limits.h>
#include <errno.h>
#include <iostream.h>
#include <unistd.h>
#include <time.h>
#include <inttypes.h>
#include <pthread.h>
#include <sched.h>
#include <sys/dispatch.h>
#include <sys/neutrino.h>
#include <sys/mman.h>
#include <sys/syspage.h>
#include <hw/inout.h>
#define ATTACH_POINT “myname”
/* We specify the header as being at least a pulse */
typedef struct _pulse msg_header_t;
/* Our real data comes after the header */
typedef struct _my_data {
msg_header_t hdr;
int data;
} my_data_t;
int main () {
my_data_t msg;
int fd;
if ((fd = name_open(ATTACH_POINT, 0)) == -1) {
return EXIT_FAILURE;
}
/* We would have pre-defined data to stuff here */
msg.hdr.type = 0x00;
msg.hdr.subtype = 0x00;
/* Do whatever work you wanted with server connection */
for (int ii = 0; ii < 5 ; ii++ ) {
msg.data = 0x100 | ii;
printf("Client 1 sending %d \n", msg.data);
if (MsgSend(fd, &msg, sizeof(msg), NULL, 0) == -1) {
break;
}
}
/* Close the connection */
name_close(fd);
return EXIT_SUCCESS;
}
C2 code:
#include <stdio.h>
#include <stdlib.h>
#include <limits.h>
#include <errno.h>
#include <iostream.h>
#include <unistd.h>
#include <time.h>
#include <inttypes.h>
#include <pthread.h>
#include <sched.h>
#include <sys/dispatch.h>
#include <sys/neutrino.h>
#include <sys/mman.h>
#include <sys/syspage.h>
#include <hw/inout.h>
#define ATTACH_POINT “myname”
/* We specify the header as being at least a pulse */
typedef struct _pulse msg_header_t;
/* Our real data comes after the header */
typedef struct _my_data {
msg_header_t hdr;
int data;
} my_data_t;
int main () {
my_data_t msg;
int fd;
if ((fd = name_open(ATTACH_POINT, 0)) == -1) {
return EXIT_FAILURE;
}
/* We would have pre-defined data to stuff here */
msg.hdr.type = 0x00;
msg.hdr.subtype = 0x00;
/* Do whatever work you wanted with server connection */
for (int ii = 0; ii < 5 ; ii++ ) {
msg.data = 0x200 | ii;
printf("Client 2 sending %d \n", msg.data);
if (MsgSend(fd, &msg, sizeof(msg), NULL, 0) == -1) {
break;
}
}
/* Close the connection */
name_close(fd);
return EXIT_SUCCESS;
}
X code :
#include <stdio.h>
int main( )
{
char Texte[80];
while(1) { printf( “Running in priority \n”); }
}
I thing if I replace the printf by a delay call in the code of X, I change the problem because the X process goes to nanosleep state and yield the CPU and that is not that I want. I want the X process runs with highest priority than the server S.