void Channel::HandleEvent(const Timestamp& fire_time) { LOG_DEBUG << this << endl; LOG_INFO << "event happend at:" << fire_time.ToString() << endl; LOG_INFO << ReadyEventToString() << endl; LOG_INFO << CareEventToString() << endl; if (ready_events_ & (EPOLLIN | EPOLLHUP)) { if (read_callback_) { read_callback_(fire_time); } } if (ready_events_ & EPOLLOUT) { if (write_callback_) { write_callback_(); } } if (ready_events_ & EPOLLERR) { if (error_callback_) { error_callback_(); } } // 这里记得清0 ready_events_ = 0; }
void ReqGetNewMsgs::OnSuccess() { PXml p = m_xml.getChildNode(0); Assert(SafeStrCmp(p.getName(), "now")); timestamp = p.getText(); p = m_xml.getChildNode(1); if (SafeStrCmp(p.getName(), "msgs")) { int numMsgs = p.nChildNode(); for (int i = 0; i < numMsgs; i++) { PXml msg = p.getChildNode(i); int id = atoi(msg.getChildNode(0).getText()); int senderId = atoi(msg.getChildNode(1).getText()); timestamp = msg.getChildNode(2).getText(); Timestamp whenSent = atoi(timestamp.c_str()); std::string text = msg.getChildNode(3).getText(); text = DecodeMsg(text); ////Replace(text, "_", " "); // replace underscores with spaces -- TODO punctuation int recipId = atoi(msg.getChildNode(4).getText()); std::cout << "GOT NEW MSG!! ID: " << id << " sender: " << senderId << " sent: " << whenSent.ToString() << " text: " << text << "\n"; TheMsgManager::Instance()->QueueMsg(MsgManager::Msg(id, text, senderId, recipId, whenSent)); } } else { ShowError("Unexpected format for msgs response"); } }