#include <stdio.h> #include <stdlib.h> #include <string.h> #include "p_entry.h" #include "p_return.h" #include "p_symbol.h" #include <unistd.h> #include <sys/types.h> /**//*attach到消息队列里去,qid为消息队列的id*/ int qattach(short qid) { q_address q_addr; int32 attach_mode; int32 dmq_status; int32 q_num_len; int32 q_type; char q_num_str[4]; int rc; attach_mode = PSYM_ATTACH_BY_NUMBER; q_type = PSYM_ATTACH_PQ; memset(q_num_str, 0x00, 4); (void)sprintf( q_num_str, "%d", qid ); q_num_len = (int32) strlen( q_num_str ); dmq_status = pams_attach_q( &attach_mode, &q_addr, &q_type, q_num_str, &q_num_len, (int32 *) 0, (int32 *) 0, (int32 *) 0, (char *) 0, (char *) 0); if(dmq_status==PAMS__SUCCESS) { return(0); } else { return ( dmq_status ); } } /**//*从消息队列里detach*/ int32 qdetach( ) { int32 dmq_status; dmq_status = pams_exit( ); if(dmq_status==PAMS__SUCCESS) { return(0); } else { return ( dmq_status ); } } /**//*从消息队列读取消息,msg_area为消息内容,msg_size为读取长度,qid为队列编号*/ int32 qread(char *msg_area, short *msg_size, short *qid) { char priority; q_address msg_source; short msg_class; short msg_type; short msg_area_len; short msg_data_len; int32 timeout; int32 dmq_status; char *qgroup, *getenv( ); int i; priority = 0; /**//* get all messages */ msg_area_len = *msg_size; /**//* size of the message buffer */ timeout = 0; dmq_status = pams_get_msgw( msg_area, /**//* where msg is written */ &priority, /**//* get all messages */ &msg_source, /**//* q_address of sender */ &msg_class, /**//* class of received msg */ &msg_type, /**//* type of received msg */ &msg_area_len, /**//* size of message buffer */ msg_size, /**//* actual size of the msg */ &timeout, (int32 *) 0, (struct PSB *) 0, (struct show_buffer *) 0, (int32 *) 0, (int32 *) 0, (int32 *) 0, (char *) 0 ); if ( dmq_status == PAMS__SUCCESS ) { return( 0 ); } else { return ( dmq_status ); } } /**//*往消息队列里发送消息,msg_area为消息内容,msg_size为消息长度,qdest为消息队列编号*/ int32 qwrite(char *msg_area, short msg_size, short qdest) { char priority; char delivery; char uma; short msg_class; short msg_type; int32 dmq_status; int32 timeout; struct PSB put_psb; char *qgroup, *getenv( ); q_address qdest_addr; int i; priority = 0; /**//* No priority */ msg_class = msg_type = 0; /**//* No type or class at the moment */ delivery = PDEL_MODE_NN_MEM; /**//* No Notification and nonrecoverable */ timeout = 100; /**//* Wait 10 seconds before giving up */ uma = PDEL_UMA_DISCL; /**//* If can't deliver it, DISCard and Log */ qgroup=getenv("DMQ_GROUP_ID"); qdest_addr.au.queue=(int16)qdest; qdest_addr.au.group=(int16)atoi(qgroup); dmq_status = pams_put_msg( msg_area, &priority, &qdest_addr, /**//* passed in */ &msg_class, &msg_type, &delivery, &msg_size, &timeout, &put_psb, &uma, (q_address *) 0, (int32 *) 0, (char *) 0, (char *) 0 ); if ( dmq_status == PAMS__SUCCESS ) { return( 0 ); } else { return ( dmq_status ); } } 版权声明 请尊重原创作品。转载请保持文章完整性,并以超链接形式注明原始作者“tingsking18”和主站点地址,方便其他朋友提问和指正。