GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — cc_tutorial/tutorials/tutorial19/src/ServerSession.cpp at master · commschamp/cc_tutorial

Expand file tree

/

ServerSession.cpp

Copy path
More file actions
More file actions

Latest commit

 

History

History
History
61 lines (47 loc) · 1.94 KB
/

ServerSession.cpp

Copy path

File metadata and controls

61 lines (47 loc) · 1.94 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#include "ServerSession.h"
#include <cassert>
#include "comms/process.h"
#include "comms/iterator.h"
namespace cc_tutorial
{
void ServerSession::handle(Message& msg)
{
// The statement below uses polymorphic message name and ID retrievals.
std::cout << "Received message \"" << msg.name() << "\" with ID=" << (unsigned)msg.getId() << std::endl;
sendMessage(msg);
}
std::size_t ServerSession::processInputImpl(const std::uint8_t* buf, std::size_t bufLen)
{
std::cout << "Processing input: " << std::hex;
std::copy_n(buf, bufLen, std::ostream_iterator<unsigned>(std::cout, " "));
std::cout << std::dec << std::endl;
// Process reported input, create relevant message objects and
// dispatch all the created messages
// to this object for handling (handle() member function will be called)
return comms::processAllWithDispatch(buf, bufLen, m_frame, *this);
}
void ServerSession::sendMessage(const Message& msg)
{
std::cout << "Sending message \"" << msg.name() << "\" with ID=" << (unsigned)msg.getId() << std::endl;
std::vector<std::uint8_t> output;
// Use polymorphic serialization length calculation to create
// buffer of the requires size
output.resize(m_frame.length(msg));
// Serialize message into the buffer (including framing)
// The serialization uses polymorphic write functionality.
auto writeIter = &output[0];
auto es = m_frame.write(msg, writeIter, output.size());
if (es != comms::ErrorStatus::Success) {
assert(!"Write operation failed unexpectedly");
return;
}
// writeIter has been advanced, check that it reached end of the allocated buffer.
assert(output.size() == static_cast<std::size_t>(std::distance(&output[0], writeIter)));
// Send (re)serialized message back
sendOutput(&output[0], output.size());
}
SessionPtr Session::createServer(boost_wrap::io& io)
{
return SessionPtr(new ServerSession(io));
}
} // namespace cc_tutorial
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.