|
- 以下内容为程序代码:
- ACE_Message_Block *send_mb = 0;
- //处理数据,并回应数据
- if (ProcessPacket(&msg_blck, send_mb))
- {
- ws.write (*send_mb, send_mb->length());
- }
- ////////////////
- BOOL Asynch_Receiver::ProcessPacket(ACE_Message_Block *in_mb, ACE_Message_Block *&out_mb)
- {
- //假定包正确
- MsgHead *hd = (MsgHead*)in_mb->rd_ptr();
- if(hd->type == MSG_REQUEST)
- {
- switch(hd->req_type)
- {
- case REQ_LOGIN:
- {
- ReqLogin *msg = (ReqLogin*)in_mb->rd_ptr();
- ACE_DEBUG ((LM_DEBUG, "user %s logined\n", msg->name));
- AfxMessageBox(msg->name);
- ReplyLogin repy;
- repy.hd.identifier = hd->identifier + 1;
- repy.hd.length = sizeof(ReplyLogin) - sizeof(MsgHead);
- repy.hd.req_type = REPLY_LOGIN;
- repy.hd.retry_times = 999;
- repy.hd.type = MSG_REPLY;
- repy.success = TRUE;
- out_mb = this->aio_->malloc(DEFAULT_MAX_BLOCK_SIZE);
- ACE_ASSERT(out_mb);
- out_mb->socket_handle(this->handle());
- out_mb->remote_ip(this->remote_addr_.get_ip_address());
- out_mb->wr_ptr((char*)&repy);
- out_mb->wr_ptr(sizeof(ReplyLogin));
- out_mb->length(sizeof(ReplyLogin));
- break;
- }
- }
-
- return TRUE;
- }
- return FALSE;
- }
复制代码 |
|