websocket-transport.hpp
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
26 #ifndef NFD_DAEMON_FACE_WEBSOCKET_TRANSPORT_HPP
27 #define NFD_DAEMON_FACE_WEBSOCKET_TRANSPORT_HPP
28 
29 #include "transport.hpp"
30 #include "websocketpp.hpp"
31 #include "core/scheduler.hpp"
32 
33 namespace nfd {
34 namespace face {
35 
41 {
42 public:
46 
50 };
51 
54 class WebSocketTransport final : public Transport
55  , protected virtual WebSocketTransportCounters
56 {
57 public:
61 
62  WebSocketTransport(websocketpp::connection_hdl hdl,
63  websocket::Server& server,
64  time::milliseconds pingInterval);
65 
66  virtual const Counters&
67  getCounters() const override;
68 
72  void
73  receiveMessage(const std::string& msg);
74 
75  void
76  handlePong();
77 
78  void
80 
81 protected:
82  virtual void
83  beforeChangePersistency(ndn::nfd::FacePersistency newPersistency) final;
84 
85  virtual void
86  doClose() final;
87 
88 private:
89  virtual void
90  doSend(Transport::Packet&& packet) final;
91 
92  void
93  schedulePing();
94 
95  void
96  sendPing();
97 
98  void
99  processErrorCode(const websocketpp::lib::error_code& error);
100 
101 private:
102  websocketpp::connection_hdl m_handle;
103  websocket::Server& m_server;
104  time::milliseconds m_pingInterval;
105  scheduler::ScopedEventId m_pingEventId;
106 };
107 
108 inline const WebSocketTransport::Counters&
110 {
111  return *this;
112 }
113 
114 } // namespace face
115 } // namespace nfd
116 
117 #endif // NFD_DAEMON_FACE_WEBSOCKET_TRANSPORT_HPP
void receiveMessage(const std::string &msg)
Translates a message into a Block and delivers it to the link service.
websocketpp::server< websocketpp::config::asio > Server
Definition: websocketpp.hpp:46
virtual void doClose() final
performs Transport specific operations to close the transport
the lower part of a Face
Definition: transport.hpp:104
WebSocketTransport(websocketpp::connection_hdl hdl, websocket::Server &server, time::milliseconds pingInterval)
stores a packet along with the remote endpoint
Definition: transport.hpp:113
represents a counter of number of packets
Definition: counter.hpp:77
Copyright (c) 2014-2015, Regents of the University of California, Arizona Board of Regents...
Definition: algorithm.hpp:32
counters provided by WebSocketTransport
virtual const Counters & getCounters() const override
counters provided by Transport
Definition: transport.hpp:57
PacketCounter nOutPings
count of outgoing Pings
PacketCounter nInPongs
count of incoming Pongs
virtual void beforeChangePersistency(ndn::nfd::FacePersistency newPersistency) final
invoked before persistency is changed
WebSocketTransportCounters Counters
counters provided by WebSocketTransport
A Transport that communicates on a WebSocket connection.