Ejemplo n.º 1
0
int main(int argc, char** argv)
{
    if (argc != 2)
    {
        printf("Need one arg for this programme.");
        return -1;
    }
    int total = atoi(argv[1]);
    printf("Total:%d\n", total);
    ChannelService service;
    ClientSocketChannel* client = service.NewClientSocketChannel();
    ChannelOptions ops;
    ops.user_write_buffer_water_mark = 8192;
    ops.user_write_buffer_flush_timeout_mills = 1;

    SocketHostAddress address("127.0.0.1", 48100);
    SocketUnixAddress unix_address("./server.unix");
    SocketHostAddress local("127.0.0.1", 5678);
    SocketUnixAddress local_unix_address("./client.unix");
    client->Bind(&local_unix_address);
    client->Connect(&unix_address);
    client->Configure(ops);
    client->GetPipeline().AddLast("decoder", new DelimiterBasedFrameDecoder(8192, CommonDelimiters::CRLFDelimiter()));
    client->GetPipeline().AddLast("default", new ClientHandler(
            total));

    uint64 start = get_current_epoch_millis();
    arch::logging::Logger* logger = arch::logging::LoggerFactory::GetDevelopLogger();
    logger->SetLevel(arch::logging::INFO_LOG_LEVEL);
    service.Start(true);
    uint64 end = get_current_epoch_millis();
    printf("Cost %llums for total %d send/recv transaction.\n", (end - start), total);
    return 1;
}
Ejemplo n.º 2
0
ClientSocketChannel* ChannelService::NewClientSocketChannel()
{
    ClientSocketChannel* ch = NULL;
    NEW(ch, ClientSocketChannel(*this));
    if (NULL != ch)
    {
        Channel* c = ch;
        c->m_id = (((c->m_id) << 4) + TCP_CLIENT_SOCKET_CHANNEL_ID_BIT_MASK);
        m_channel_table[c->m_id] = c;
        ch->GetPipeline().Attach(ch);
    }
    return ch;
}