void Connection::updateRecvCmds() { ReadCmd *cmd = NULL; if (!cmds.empty()) { if (cmds.readOnly(cmd)) { Record *record = NULL; while (!recvs.empty()) { if (recvs.readOnly(record)) { cmd->offset += record->recv(nowCmd+ cmd->offset,cmd->size - cmd->offset); if (record->empty()) { delete record; recvs.pop(); } if (cmd->offset == cmd->size) { cmds.pop(); // 处理回调 cmd->func->callback(this,nowCmd,cmd->size); memset(nowCmd,0,65535); delete cmd; break; } }else break; } } } }
/** * pool **/ void Connection::doSend(EventBase *evt,bool over) { bool tag = false; OutEvent<Connection>* event = static_cast<OutEvent<Connection>*>( evt ); if (event->msgLen < event->dataLen && !over) { return; } event->dataLen = 0; event->reset(); int leftLen = EventBase::MAX_BUFFER_LEN; while (!sends.empty() && leftLen > 0) { tag = true; Record *record = NULL; if (sends.readOnly(record)) { unsigned int realCopySize = record->recv(event->buffer,leftLen); evt->dataLen += realCopySize; if (leftLen == realCopySize) { leftLen = 0; if (record->empty()) { delete record; sends.pop(); } break; } else { leftLen -= realCopySize; if(!record->empty()) { // TODO ERROR } sends.pop(); } }else break; } if (tag) evt->redo(); }
/** * ????????????? **/ unsigned int Connection::recv(void *cmd,unsigned int size) { unsigned int realcopy = 0; // while (recvs.size()) while (!recvs.empty()) { Record *record = NULL; if (recvs.readOnly(record)) { realcopy = record->recv(cmd,size); if (record->empty()) { delete record; recvs.pop(); } if (realcopy == size) { return size; } }else break; } return realcopy; }