本文整理汇总了C++中ChannelHandlerContext类的典型用法代码示例。如果您正苦于以下问题:C++ ChannelHandlerContext类的具体用法?C++ ChannelHandlerContext怎么用?C++ ChannelHandlerContext使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ChannelHandlerContext类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: RETURN_NULL_IF_NULL
ChannelHandler* ChannelPipeline::Remove(ChannelHandlerContext* ctx)
{
RETURN_NULL_IF_NULL(ctx);
ChannelHandler* handler = ctx->GetHandler();
if (m_head == m_tail)
{
m_head = NULL;
m_tail = NULL;
m_name2ctx.clear();
DELETE(ctx);
return handler;
}
else if (ctx == m_head)
{
return RemoveFirst();
}
else if (ctx == m_tail)
{
return RemoveLast();
}
else
{
//callBeforeRemove(ctx);
ChannelHandlerContext* prev = ctx->GetPrev();
ChannelHandlerContext* next = ctx->GetNext();
prev->SetNext(next);
next->SetPrev(prev);
m_name2ctx.erase(ctx->GetName());
DELETE(ctx);
//callAfterRemove(ctx);
return handler;
}
}
示例2: MessageReceived
void MessageReceived(ChannelHandlerContext& ctx, MessageEvent<
Buffer>& e)
{
total_received++;
DEBUG_LOG("Received response with total:%d", total_received);
if (total_received == total_would_send)
{
ctx.GetChannel()->Close();
ctx.GetChannel()->GetService().Stop();
}
else if (total_received % 2000 == 0)
{
//INFO_LOG("Received %d response\n", total_received);
Buffer buf(16);
buf.Write("Hello,world\r\n", 13);
for (uint32 i = 0; i < 2000; i++)
{
if(!ctx.GetChannel()->Write(buf))
{
ERROR_LOG("Failed to write buf to channel with total send:%d", total_send);
continue;
}
total_send++;
buf.SetReadIndex(0);
}
//INFO_LOG("Write %d request\n", total_send);
}
}
示例3: ChannelClosed
void DispatcerIPCEventHandler::ChannelClosed(ChannelHandlerContext& ctx,
ChannelStateEvent& e)
{
DEBUG_LOG("Dispatcher(%s_%u) close a client.",g_service_proc->GetServiceName().c_str(), g_service_proc->GetProcessIndex());
ChannelList::iterator it = m_client_channel_list.begin();
while (it != m_client_channel_list.end())
{
if (ctx.GetChannel() == *it)
{
m_client_channel_list.erase(it);
break;
}
it++;
}
IPCChannelTable::iterator tit = m_ipc_channel_table.begin();
while (tit != m_ipc_channel_table.end())
{
if (ctx.GetChannel() == tit->second)
{
ProcessAddress addr = tit->first;
m_ipc_channel_table.erase(tit);
DispatcherProcess* proc = (DispatcherProcess*) g_service_proc;
if (proc->GetIPCType() == IPC_FIFO)
{
proc->CreateServiceProcessIPCFIFOChannel(addr);
}
break;
}
tit++;
}
}
示例4: GetAll
void ChannelPipeline::GetAll(vector<ChannelHandler*> handlerlist)
{
ChannelHandlerContext* ctx = m_head;
while(NULL != ctx)
{
handlerlist.push_back(ctx->GetHandler());
ctx = ctx->GetNext();
}
}
示例5: WriteRequested
bool RedisCommandEncoder::WriteRequested(ChannelHandlerContext& ctx, MessageEvent<RedisCommandFrame>& e)
{
RedisCommandFrame* msg = e.GetMessage();
if (Encode(ctx.GetChannel()->GetOutputBuffer(), *msg))
{
ctx.GetChannel()->EnableWriting();
return true;
}
return false;
}
示例6: MessageReceived
void Slave::MessageReceived(ChannelHandlerContext& ctx, MessageEvent<RedisMessage>& e)
{
if (e.GetMessage()->IsReply())
{
HandleRedisReply(ctx.GetChannel(), e.GetMessage()->reply);
}
else if (e.GetMessage()->IsCommand())
{
HandleRedisCommand(ctx.GetChannel(), e.GetMessage()->command);
}
else
{
HandleRedisDumpChunk(ctx.GetChannel(), e.GetMessage()->chunk);
}
}
示例7: ChannelClosed
void ServiceIPCEventHandler::ChannelClosed(ChannelHandlerContext& ctx,
ChannelStateEvent& e)
{
Channel* ch = ctx.GetChannel();
Address* addr = const_cast<Address*>(ch->GetRemoteAddress());
Address* localaddr = const_cast<Address*>(ch->GetLocalAddress());
if (NULL != addr && InstanceOf<SocketUnixAddress>(addr).OK)
{
SocketUnixAddress* un = (SocketUnixAddress*) addr;
SocketUnixAddress* un1 = (SocketUnixAddress*) localaddr;
DEBUG_LOG(
"Local %s Closed %s", un1->GetPath().c_str(), un->GetPath().c_str());
if (m_service->GetManagerProcess()->IsManagerIPCUnixSocketServer(
un->GetPath()))
{
m_service->SetIPCUnixSocket(NULL);
}
else if (m_service->GetManagerProcess()->IsManagerCtrlUnixSocketServer(
un->GetPath()))
{
m_service->SetCtrlChannel(NULL);
}
else
{
GetServiceProcess()->AddClosedDispatcherIPCChannel(ch);
VirtualChannelHelper::ClearTable(ch);
}
}
}
示例8: MessageReceived
void MessageReceived(ChannelHandlerContext& ctx,
MessageEvent<Buffer>& e)
{
total_recv += (e.GetMessage()->ReadableBytes());
Buffer send(7);
send.Write("Hello\r\n", 7);
ctx.GetChannel()->Write(send);
//total_received++;
//DEBUG_LOG("Received response with total:%d", total_received);
// if (total_received == total_would_send)
// {
// ctx.GetChannel()->Close();
// ctx.GetChannel()->GetService().Stop();
// }
// else if (total_received % 2000 == 0)
// {
// //INFO_LOG("Received %d response\n", total_received);
// Buffer buf(16);
// buf.Write("Hello,world\r\n", 13);
// for (uint32 i = 0; i < 2000; i++)
// {
// if (!ctx.GetChannel()->Write(buf))
// {
// ERROR_LOG("Failed to write buf to channel with total send:%d", total_send);
// continue;
// }
// total_send++;
// buf.SetReadIndex(0);
// }
// //INFO_LOG("Write %d request\n", total_send);
// }
}
示例9: MessageReceived
void Master::MessageReceived(ChannelHandlerContext& ctx, MessageEvent<RedisCommandFrame>& e)
{
RedisCommandFrame* cmd = e.GetMessage();
DEBUG_LOG("Master recv cmd from slave:%s", cmd->ToString().c_str());
if (!strcasecmp(cmd->GetCommand().c_str(), "replconf"))
{
if (cmd->GetArguments().size() == 2 && !strcasecmp(cmd->GetArguments()[0].c_str(), "ack"))
{
int64 offset;
if (string_toint64(cmd->GetArguments()[1], offset))
{
SlaveConnTable::iterator found = m_slaves.find(ctx.GetChannel()->GetID());
if (found != m_slaves.end())
{
SlaveConn* slave = found->second;
if (NULL != slave)
{
slave->acktime = time(NULL);
slave->ack_offset = offset;
}
}
}
}
}
}
示例10: ChannelWritable
void Master::ChannelWritable(ChannelHandlerContext& ctx, ChannelStateEvent& e)
{
uint32 conn_id = ctx.GetChannel()->GetID();
SlaveConnTable::iterator found = m_slave_table.find(conn_id);
if (found != m_slave_table.end())
{
SlaveConnection* slave = found->second;
if (slave->state == SLAVE_STATE_SYNING_CACHE_DATA)
{
if ((uint64) slave->sync_offset >= m_backlog.GetReplEndOffset())
{
slave->state = SLAVE_STATE_SYNCED;
ChannelOptions options;
options.auto_disable_writing = true;
slave->conn->Configure(options);
} else
{
if (!m_backlog.IsValidOffset(slave->sync_offset))
{
slave->conn->Close();
} else
{
size_t len = m_backlog.WriteChannel(slave->conn, slave->sync_offset, MAX_SEND_CACHE_SIZE);
slave->sync_offset += len;
slave->conn->EnableWriting();
}
}
}
}
}
示例11: HandleStreamEvent
inline bool HandleStreamEvent(ChannelHandlerContext& ctx,
ChannelStateEvent& e)
{
//ChannelStateEvent& stateEvent = (ChannelStateEvent&) e;
switch (e.GetState())
{
case CLOSED:
{
CloseRequested(ctx, e);
break;
}
case BOUND:
{
BindRequested(ctx, e);
break;
}
case CONNECTED:
{
ConnectRequested(ctx, e);
break;
}
default:
{
ctx.SendDownstream(e);
break;
}
}
return true;
}
示例12: ChannelConnected
void DispatcerIPCEventHandler::ChannelConnected(ChannelHandlerContext& ctx,
ChannelStateEvent& e)
{
DEBUG_LOG("Dispatcher(%s_%u) accept a client.", g_service_proc->GetServiceName().c_str(), g_service_proc->GetProcessIndex());
Channel* ch = ctx.GetChannel();
Address* remote = const_cast<Address*> (ch->GetRemoteAddress());
if (NULL != remote)
{
if (InstanceOf<SocketUnixAddress> (remote).OK)
{
SocketUnixAddress* un = (SocketUnixAddress*) remote;
const std::string& path = un->GetPath();
ProcessAddress proc_addr;
g_service_proc->GetManagerProcess()->ParseDispatcherClientUnixSocketAddress(path,
proc_addr);
DEBUG_LOG("Parsed process address %u_%u", proc_addr.proc_type, proc_addr.proc_idx);
IPCChannelTable::iterator tit = m_ipc_channel_table.find(proc_addr);
if (tit == m_ipc_channel_table.end())
{
AddServiceIPCChannel(proc_addr, ch);
}
}
}
}
示例13: ChannelConnected
void HttpClientHandler::ChannelConnected(ChannelHandlerContext& ctx,
ChannelStateEvent& e)
{
m_connected = true;
m_client = ctx.GetChannel();
g_ready_channels.insert(this);
try_send_request();
}
示例14: ChannelConnected
void Slave::ChannelConnected(ChannelHandlerContext& ctx, ChannelStateEvent& e)
{
DEBUG_LOG("Master conn connected.");
Buffer info;
info.Printf("info Server\r\n");
ctx.GetChannel()->Write(info);
m_slave_state = SLAVE_STATE_WAITING_INFO_REPLY;
m_ping_recved_time = time(NULL);
m_master_link_down_time = 0;
}
示例15: ChannelClosed
void Master::ChannelClosed(ChannelHandlerContext& ctx, ChannelStateEvent& e)
{
uint32 conn_id = ctx.GetChannel()->GetID();
SlaveConnTable::iterator found = m_slaves.find(conn_id);
if (found != m_slaves.end())
{
WARN_LOG("Slave %s closed.", found->second->GetAddress().c_str());
found->second = NULL;
}
}