本文整理汇总了C++中Connection::IsRecvProtoReady方法的典型用法代码示例。如果您正苦于以下问题:C++ Connection::IsRecvProtoReady方法的具体用法?C++ Connection::IsRecvProtoReady怎么用?C++ Connection::IsRecvProtoReady使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Connection
的用法示例。
在下文中一共展示了Connection::IsRecvProtoReady方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: DoTcpRead
void EventModule::DoTcpRead(int conn_fd, void* arg)
{
Epoller* epoller_ = (Epoller*)arg;
static char recv_buf[PKG_BUF_SIZE] = {0};
EventModule* event_module = FindModule<EventModule>(App::GetInstance());
void* zmq_sock = event_module->zmq_sock();
ConnMgrModule* conn_mgr_module = FindModule<ConnMgrModule>(App::GetInstance());
Connection* conn = conn_mgr_module->GetConn(conn_fd);
if (conn == NULL) {
LOG(ERROR) << "GetConn error!";
return;
}
int32_t recv_len = recv(conn_fd, recv_buf, PKG_BUF_SIZE, 0);
if (recv_len < 0) {
PLOG(ERROR)
<< "recv";
conn_mgr_module->ReleaseConn(conn_fd);
epoller_->ClearEvent(conn_fd);
return;
} else if(recv_len == 0) {
LOG(INFO) << "client close connection!";
SendConnStop(zmq_sock, conn->player_idx());
conn_mgr_module->ReleaseConn(conn_fd);
epoller_->ClearEvent(conn_fd);
return;
}
LOG(INFO) << "-----> recv from client len[" << recv_len << "]";
if (conn->AddRecvData(recv_buf, recv_len) != 0) {
LOG(ERROR)
<< "conn_fd[" << conn_fd
<< "] over tcp buf";
conn_mgr_module->ReleaseConn(conn_fd);
epoller_->ClearEvent(conn_fd);
return;
}
while (conn->IsRecvProtoReady()) {
// 接收真实长度大于协议长度就进行处理
int32_t ret = 0;
const char* msg_buf = Utils::GetMsgFromClient(conn->recv_buf());
int32_t msg_len = Utils::GetMsgLenFromClient(conn->recv_buf());
static ProtoCs::Msg msg;
msg.Clear();
// Protobuf解析
if (msg.ParseFromArray(msg_buf, msg_len) == false) {
LOG(ERROR)
<< "protobuf parse error! msg_len[" << msg_len << "]";
}
if (msg_len > PKG_BUF_SIZE) {
LOG(ERROR)
<< "msg_len > PKG_BUF_SIZE";
return;
}
static ConnData conn_data;
if (conn->player_idx() == 0)
conn_data.conn_cmd = CONN_START;
else
conn_data.conn_cmd = CONN_PROC;
conn_data.conn_fd = conn_fd;
conn_data.player_idx = conn->player_idx();
static char send_buf[PKG_BUF_SIZE + sizeof(conn_data)];
// --- 组包 start ---
char* p = send_buf;
memcpy(p, &conn_data, sizeof(conn_data));
p += sizeof(conn_data);
memcpy(p, msg_buf, msg_len);
p += msg_len;
int32_t send_len = sizeof(conn_data) + msg_len;
// --- 组包 end ---
ret = zmq_send(zmq_sock, send_buf, send_len, ZMQ_DONTWAIT);
conn->RemoveRecvProto();
LOG(INFO) << "zmq_send ret[" << ret << "]";
if (ret < 0) {
LOG(ERROR) << "zmq_send errno[" << errno << "] error[" << strerror(errno) << "]";
conn_mgr_module->ReleaseConn(conn_fd);
epoller_->ClearEvent(conn_fd);
return;
}
}
}