📄 msg.c
字号:
#include <stdio.h>
#include <errno.h>
#include <sys/types.h>
#include <sys/ipc.h>
#include <sys/msg.h>
#include <signal.h>
#include "all.h"
#include "atmstruct.h"
#include "atmextern.h"
#include "public.h"
#include "repcode.h"
static void
snd_out_alarm ( int signo )
{
}
long init_req_msg(int _Flag)
{
char pathfil[40];
key_t msgkey;
long g_htopq;
struct msqid_ds msgqid;
memset ( pathfil, 0x00, sizeof(pathfil) );
sprintf(pathfil,"%s%s",getenv("WORKDIR"),FILE_NAME);
msgkey=ftok(pathfil,HTOP_ID);
if ( _Flag == 1 ) {
g_htopq = msgget(ftok (pathfil,HTOP_ID),IPC_CREAT|0666);
} else
if ( _Flag == 0 ) {
g_htopq = msgget(ftok (pathfil,HTOP_ID),IPC_CREAT);
}
msgctl(g_htopq,IPC_STAT,&msgqid);
msgqid.msg_qbytes=32767;
msgctl(g_htopq,IPC_SET,&msgqid);
return ( g_htopq );
}
long init_resp_msg(int _Flag)
{
char pathfil[80];
key_t msgkey;
long g_ptohq;
struct msqid_ds msgqid;
memset ( pathfil, 0x00, sizeof(pathfil) );
sprintf(pathfil,"%s%s",getenv("WORKDIR"),FILE_NAME);
msgkey=ftok(pathfil,PTOH_ID);
if ( _Flag == 1 ) {
g_ptohq = msgget(ftok (pathfil,PTOH_ID),IPC_CREAT|0666);
} else
if ( _Flag == 0 ) {
g_ptohq = msgget(ftok (pathfil,PTOH_ID),IPC_CREAT);
}
msgctl(g_ptohq,IPC_STAT,&msgqid);
msgqid.msg_qbytes=32767;
msgctl(g_ptohq,IPC_SET,&msgqid);
return ( g_ptohq );
}
int rcv_msg(long msgid,long msgtype,PUBLIC *pcs)
{
int i=0;
int len;
struct msqid_ds msgqid;
len = sizeof(PUBLIC);
alarm ( 5 );
if ((i=msgrcv(msgid,pcs,sizeof(PUBLIC),msgtype, 0))< 0) {
/**
errcall(ERROR, "Switchsrv error EXIT,msgtype[%ld]",msgtype);
msgctl(msgid,IPC_STAT,&msgqid);
errcall(ERROR, "Recv:Error msg_cbytes[%lu], \
msg_qbytes[%lu] qnum[%lu]", msgqid.msg_cbytes, \
msgqid.msg_qbytes,msgqid.msg_qnum);
**/
return i;
}
return i;
}
int snd_msg(long msgid, long msgtype,PUBLIC spcs )
{
int i=0;
int len;
struct msqid_ds msgqid;
int TryCount=0;
len = sizeof(PUBLIC);
alarm ( MAXALRM );
spcs.mytype=msgtype;
if ((i=msgsnd( msgid,(char *)&spcs, len,0)) < 0 ) {
/**
msgctl(msgid,IPC_STAT,&msgqid);
errcall(ERROR, "Snd:Error msg_cbytes[%lu], \
msg_qbytes[%lu] qnum[%lu]", msgqid.msg_cbytes, \
msgqid.msg_qbytes,msgqid.msg_qnum);
**/
return i;
}
return i;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -