diff options
author | Jon Bratseth <bratseth@yahoo-inc.com> | 2016-06-15 23:09:44 +0200 |
---|---|---|
committer | Jon Bratseth <bratseth@yahoo-inc.com> | 2016-06-15 23:09:44 +0200 |
commit | 72231250ed81e10d66bfe70701e64fa5fe50f712 (patch) | |
tree | 2728bba1131a6f6e5bdf95afec7d7ff9358dac50 /fnet/src/examples/ping/pingserver.cpp |
Publish
Diffstat (limited to 'fnet/src/examples/ping/pingserver.cpp')
-rw-r--r-- | fnet/src/examples/ping/pingserver.cpp | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/fnet/src/examples/ping/pingserver.cpp b/fnet/src/examples/ping/pingserver.cpp new file mode 100644 index 00000000000..346307a017c --- /dev/null +++ b/fnet/src/examples/ping/pingserver.cpp @@ -0,0 +1,65 @@ +// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +#include <vespa/fastos/fastos.h> +#include <vespa/log/log.h> +LOG_SETUP("pingserver"); +#include <vespa/fnet/fnet.h> +#include <examples/ping/packets.h> + + +class PingServer : public FNET_IServerAdapter, + public FNET_IPacketHandler, + public FastOS_Application +{ +public: + bool InitAdminChannel(FNET_Channel *) { return false; } + bool InitChannel(FNET_Channel *channel, uint32_t) + { + channel->SetContext(FNET_Context(channel)); + channel->SetHandler(this); + return true; + } + + HP_RetCode HandlePacket(FNET_Packet *packet, FNET_Context context) + { + if (packet->GetPCODE() == PCODE_PING_REQUEST) { + fprintf(stderr, "Got ping request, sending ping reply\n"); + context._value.CHANNEL->Send(new PingReply()); + } + packet->Free(); + return FNET_FREE_CHANNEL; + } + + int Main(); +}; + + +int +PingServer::Main() +{ + FNET_SignalShutDown::hookSignals(); + if (_argc < 2) { + printf("usage : pingserver <listenspec>\n"); + printf("example: pingserver 'tcp/8000'\n"); + return 1; + } + + FNET_Transport transport; + PingPacketFactory factory; + FNET_SimplePacketStreamer streamer(&factory); + FNET_Connector *listener = + transport.Listen(_argv[1], &streamer, this); + if (listener != NULL) + listener->SubRef(); + + FNET_SignalShutDown ssd(transport); + transport.Main(); + return 0; +} + + +int +main(int argc, char **argv) +{ + PingServer myapp; + return myapp.Entry(argc, argv); +} |