Name
mesgsnd � Send an IPC message
Synopsis
#include "spp.h"
int mesgsnd (mdest, msgp, msgsz, msgflag)
int mdest; /* Message Qkey to send to */
union msgunion *msgp; /* message to send */
int msgsz; /* size of message */
int msgflag; /* flag for controlling send */
Description
mesgsnd sends the IPC message pointed by msgp to qkey mdest. The number of bytes in the message is specified by msgsz. The message consists of the header and data parts. The header is defined as struct mbhdr in mesg.h. The size of message ( msgsz ) should include the header and data parts. Mesgsnd actually sends the message by calling the system call msgsnd. Msgflag is sent directly to the system call msgsnd.
mesgsnd creates the IPC message queue for qkey mdest if necessary. When returning dbase messages to TSM, it is necessary to include the channel number value which originally came from TSM.
Example
The following is an example of a function that sends employee information to the TSM script running on the specified channel.
#include "spp.h"
#include "mesg.h"
/* Define message to send */
struct employeeMsg {
struct mbhdr hd; /* see mesg.h */
char ename[25];/* employee name */
int payrollNo; /* employee number */
};
#define EMPLOYEE_INFO#7890/* message id */
extern int MyQkey; /* sender's Qkey */
int
sendEmsg(chan, ename, enumber)
int chan;
char *ename;
int enumber;
{
Struct employeeMsg emsg;
int retcode;
/* Package Message */
emsg.hd.mchan = chan;
emsg.hd.mtype = 1;/* should be positive non-zero */
emsg.hd.morig = MyQkey;
emsg.hd.mcont = EMPLOYEE_INFO;
emsg.hd.mseqno = 0;/* set to zero for safety */
strcpy(emsg.ename, ename);
emsg.payrollNo = enumber;
retcode = mesgsnd(TSM, &emsg, sizeof(emsg), 0);
return(retcode);
}
Diagnostics
Upon successful completion, mesgsnd returns zero (the value returned by msgsnd system call). Otherwise, one of the following negative values is returned:
Value |
Description |
-1 |
An error occurred in msgsnd and errno is set accordingly |
-2 |
Can not create or get the message queue |
-3 |
Destination qkey ( mdest ) is not in the voice system range (1-95) |
-4 |
The size of the message is too small (less than 4 bytes) |