php와 C사이 에서 message Queue사용시..구조체전달?
글쓴이: MackTheKnife / 작성시간: 월, 2004/01/19 - 3:06오후
담과 같은 php로 큐에 데이터를 입력하면
$arr=array();
$arr["mtype"]=1;
$arr["processName"]="httpd";
$arr["logTime"]=strftime("%Y%m%d%H%M%S",time());
$result=msg_send($msg_key,1,$arr,true,false,$error_code);
echo "msg_key=".$msg_key." msg_send result=".$result."<br>";
C에서는 담과 같은 구조체로 데이터를 받습니다.
typedef struct
{
long mtype; //필수구현
union
{
BYTE partnerID;//소켓통신시에만 적용
struct
{
BYTE partnerFID :4; // Low
BYTE partnerPID :4; // High
};
};
BYTE errorLevel;//에러 레벨
BYTE errorType;//에러의 타입(SYSINIT.....)
BYTE option1;
BYTE option2;
BYTE errorCode;//사용자 define 코드
long systemErrorCode;//시스템 에러코드
char message[513];//사용자 define Message + 시스템 에러메세지
char processName[17];//로그를 발생시킨 프로세스이름
char logTime[15]; //로그가 발생한 시간
}LOGMSG_MON,*PLOGMSG_MON;
문제는 데이터를 큐에서 읽어오지만 내용이 이상해지네여..
message변수에 Php에서 입력한 모든값들이 들어갑니다.message="ype\";i:1;s:11:\"processName\";s:5:\"httpd\";s:7:\"logTime\";s:14:\"20040119150309\"
Forums:


자문자답임다.
이것때문에 반나절 소비했네여..
php에서 pack이라는 함수를 써서 구조체의 변수순서에 맞게 바이너러로 변환하여 queue에 넣음 됩니다.
class LOGMSG_MON { var $mtype; var $partnerID; var $errorLevel; var $errorType; var $option1; var $option2; var $errorCode; var $systemErrorCode; var $message; var $processName; var $logTime; function LOGMSG_MON() { $this->mtype=2; //php에서 로그는 2로함 $this->partnerID=0x70; $this->errorLevel=0x11; $this->errorType=0x12; $this->option1=0x00; $this->option2=0x00; $this->errorCode=0x01; $this->systemErrorCode=1234; $this->processName="httpd"; $this->logTime=strftime("%Y%m%d%H%M%S",time()); } function setMessage($msg) { $this->message=$msg; } function getBinary() { //$result.=pack("I",$this->mtype); $result.=pack("C",$this->partnerID); $result.=pack("C",$this->errorLevel); $result.=pack("C",$this->errorType); $result.=pack("C",$this->option1); $result.=pack("C",$this->option2); $result.=pack("C",$this->errorCode); $result.=pack("L",$this->systemErrorCode); $result.=pack("a513",$this->message); $result.=pack("a17",$this->processName); $result.=pack("a15",$this->logTime); return $result; } } $logMsg=new LOGMSG_MON(); $logMsg->setMessage("test message from php"); $msg_key=msg_get_queue(1215,0666); $result=msg_send($msg_key,1,$logMsg->getBinary(),false,false,$error_code);감사합니다. 잘 쓰겠습니다.
감사합니다. 잘 쓰겠습니다.
댓글 달기