#include <signal.h>
#include <stdio.h>
#include <sys/types.h>
#include <sys/ipc.h>
#include <errno.h>
#include <sys/msg.h>
#include <string.h>
#include <errno.h>

long que_id;
typedef struct
{
  long mtype;
  char mtext[2048];
} message;
message  msg1;
struct msqid_ds buf;
int que_size; 
int iret;
/* connect to queue */
queconn(msg_qu_key)
key_t *msg_qu_key;
{
  if((que_id = msgget(*msg_qu_key,0666))==-1)
	  {
	    perror("queueconn: Cannot locate message queue");
	    exit(1);
	  };
  iret=msgctl(que_id,IPC_STAT,&buf);
  if(iret){
    perror("queuesize error: ");
  };
  que_size=buf.msg_qbytes;
  if(que_size>2048) que_size=2048;
#ifdef DEBUG
  printf("queue size %d\n",que_size);
#endif
}
quewrite(s,msgtype)
char *s;
int msgtype;
{  
  msg1.mtype=msgtype;
  strcpy(msg1.mtext,s);
  if(msgsnd(que_id,&msg1,strlen(s)+1,0) == -1) {
    perror("quewrite: Not able to send the segment message"); 
	exit(-1);
  };
}

main(argc,argv)
int argc;
char *argv[];
{
char s[2049];
key_t msgqid=3075;
gets(s);
queconn(&msgqid);
quewrite(s,10);
}
