本文整理汇总了C++中Protocol::encode方法的典型用法代码示例。如果您正苦于以下问题:C++ Protocol::encode方法的具体用法?C++ Protocol::encode怎么用?C++ Protocol::encode使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Protocol
的用法示例。
在下文中一共展示了Protocol::encode方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: on_writeable
HANDLE_RESULT NetInterface::on_writeable(int fd)
{
SLOG_TRACE("socket on_writeabble. fd=%d", fd);
TransSocket* trans_socket = (TransSocket*)m_socket_manager->find_trans_socket(fd);
if(trans_socket == NULL)
{
SLOG_ERROR("can't find trans socket in socket manager. fd=%d", fd);
return HANDLE_ERROR;
}
int ret = trans_socket->send_buffer();
if(ret == TRANS_ERROR)
return HANDLE_ERROR;
else if(ret > 0) //只发送部分数据
{
SLOG_INFO("remain %d bytes data wait for sending on socket fd=%d",ret, fd);
if(m_io_demuxer->register_event(fd, EVENT_WRITE, m_socket_idle_timeout_ms, this) != 0)
{
SLOG_ERROR("register write event error. fd=%d", fd);
return HANDLE_ERROR;
}
return HANDLE_OK;
}
//移出一个待发送的协议
Protocol* protocol = get_wait_to_send_protocol(fd);
if(protocol == NULL)
return HANDLE_OK;
if(protocol->encode() == false)
{
SLOG_ERROR("protocol encode error. fd=%d", fd);
on_protocol_send_error(fd, protocol);
return HANDLE_ERROR;
}
ByteBuffer *raw_data = protocol->detach_raw_data(); //脱离raw_data
trans_socket->push_send_buffer(raw_data);
ret = trans_socket->send_buffer();
if(ret == TRANS_ERROR)
{
on_protocol_send_error(fd, protocol);
return HANDLE_ERROR;
}
else if(ret > 0) //只发送了部分数据
{
SLOG_INFO("send %s. remain %d bytes data wait for sending on socket fd=%d", protocol->details(), ret, fd);
if(m_io_demuxer->register_event(fd, EVENT_WRITE, m_socket_idle_timeout_ms, this) != 0)
{
SLOG_ERROR("register write event error. fd=%d", fd);
on_protocol_send_error(fd, protocol);
return HANDLE_ERROR;
}
on_protocol_send_succ(fd, protocol);
return HANDLE_OK;
}
on_protocol_send_succ(fd, protocol);
if((get_wait_to_send_protocol_number(fd)>0) && (m_io_demuxer->register_event(fd, EVENT_WRITE, m_socket_idle_timeout_ms, this)!=0))
{
SLOG_ERROR("register write event error. fd=%d", fd);
return HANDLE_ERROR;
}
return HANDLE_OK;
}