int check_package(fmsg_pack *p) { if (p == NULL) err_common("bad package"); if (p->from == NULL || p->to == NULL || p->fmsg == NULL) err_common("bad package"); return 0; }
/* 打印日志信息。 */ void log_msg (const char*file,const Int32_t line,const char *text, ...) { va_list arg; char buf[LINE_LEN]; memset(buf,'\0',sizeof(buf)); if((file != NULL) && (line>0)) { snprintf(buf,sizeof(buf),"%s:%d %s",file,line,text); } else { memcpy(buf,text,strlen(text)); } va_start (arg, text); err_common (B_FALSE, buf, arg); va_end (arg); }
int msg_receive(fmsg_pack *q, int fdself) { if (q == NULL) err_common("bad address"); //lock fdself if (lockf(fdself, 1, 0) == -1) sys_quit("lock failed"); if (read(fdself, q, sizeof(fmsg_pack)) < 0) sys_quit("error occured while attempted to read :"); //unlock fdself if (lockf(fdself, 0, 0) == -1) sys_quit("unlock failed"); if (check_package(q)) return -1; return 0; }