Skip to content

Commit

Permalink
#50 - Websocket Ping/Pong
Browse files Browse the repository at this point in the history
  • Loading branch information
PerMalmberg committed Aug 9, 2019
1 parent 3c9c073 commit 0f365ee
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 15 deletions.
2 changes: 1 addition & 1 deletion lib/smooth/application/network/http/HTTPServerClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ namespace smooth::application::network::http
}
else if (ws_op == OpCode::Ping)
{
// Reply with a ping and place it first in the queue.
// Reply with a Pong and place it first in the queue.
reply(std::make_unique<WSResponse>(OpCode::Pong), true);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ namespace smooth::application::network::http::websocket::responses

smooth::application::network::http::websocket::OpCode op_code;

bool first_fragment{false};
bool last_fragment{false};
bool first_fragment{true};
bool last_fragment{true};

std::vector<uint8_t> data{};
};
Expand Down
14 changes: 5 additions & 9 deletions test/http_server_test/WSEchoServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,19 @@

using namespace smooth::application::network::http::websocket::responses;
using namespace smooth::application::network::http::websocket;
using namespace smooth::core::ipc;

namespace http_server_test
{
using namespace smooth::core::timer;
using namespace std::chrono;

WSEchoServer::WSEchoServer(smooth::application::network::http::IServerResponse& response, smooth::core::Task& task)
: WebsocketServer(response, task)/*,
timer_queue("time_queue", 1, task, *this),
timer(Timer::create("Ping", 0, timer_queue, true, seconds{1}))*/
: WebsocketServer(response, task),
timer_queue(TaskEventQueue<TimerExpiredEvent>::create("time_queue", 1, task, *this)),
timer(Timer::create("Ping", 0, timer_queue, true, seconds{1}))
{
//timer->start();
timer->start();
}

void http_server_test::WSEchoServer::data_received(bool first_part, bool last_part, bool is_text,
Expand All @@ -45,9 +46,4 @@ namespace http_server_test
{
response.reply(std::make_unique<WSResponse>(OpCode::Ping), true);
}

WSEchoServer::~WSEchoServer()
{
//timer->stop();
}
}
6 changes: 3 additions & 3 deletions test/http_server_test/WSEchoServer.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,14 @@ namespace http_server_test
public:
WSEchoServer(smooth::application::network::http::IServerResponse& response, smooth::core::Task& task);

~WSEchoServer() override;
~WSEchoServer() override = default;

void data_received(bool first_part, bool last_part, bool is_text, const std::vector<uint8_t>& data) override;

void event(const smooth::core::timer::TimerExpiredEvent& event) override;

private:
//smooth::core::ipc::TaskEventQueue<smooth::core::timer::TimerExpiredEvent> timer_queue;
//std::shared_ptr<smooth::core::timer::Timer> timer;
std::shared_ptr<smooth::core::ipc::TaskEventQueue<smooth::core::timer::TimerExpiredEvent>> timer_queue;
smooth::core::timer::TimerOwner timer;
};
}

0 comments on commit 0f365ee

Please sign in to comment.