Responsible for orchestrating the high-level life cycle of a daemon-side NCP server and multiplexing connections over a single hardware comms channel (serial port, etc).
More...
#include <ncp_session.h>
|
| | NCPSession (int portNumber, int baudRate, std::string host, std::string serialDevice, bool autoexit, unsigned short nverbose) |
| |
| | ~NCPSession () |
| |
| int | start () |
| | Creates and manages all the threads necessary to run a full session for communicating with a Psion and exposing that to clients via the a TCP socket. More...
|
| |
| void | cancel () |
| | Mark the session as cancelled. More...
|
| |
| void | wait () |
| | Wait for the session to terminate. More...
|
| |
Responsible for orchestrating the high-level life cycle of a daemon-side NCP server and multiplexing connections over a single hardware comms channel (serial port, etc).
Creates and manages three threads (ncp_session_main_thread, link_thread, and socket_connection_polling_thread) that drive the serial ports, accept incoming TCP connections from clients, and poll connected TCP sockets.
Definition at line 41 of file ncp_session.h.
◆ NCPSession()
| NCPSession::NCPSession |
( |
int |
portNumber, |
|
|
int |
baudRate, |
|
|
std::string |
host, |
|
|
std::string |
serialDevice, |
|
|
bool |
autoexit, |
|
|
unsigned short |
nverbose |
|
) |
| |
|
inline |
◆ ~NCPSession()
| NCPSession::~NCPSession |
( |
| ) |
|
◆ cancel()
| void NCPSession::cancel |
( |
| ) |
|
Mark the session as cancelled.
It is anticipated that this method be called from within an interrupt handler in CLI apps. When using cancel to initiate session shutdown, it should be paired with wait.
Definition at line 229 of file ncp_session.cc.
◆ isCancelled()
| bool NCPSession::isCancelled |
( |
| ) |
|
|
private |
◆ start()
| int NCPSession::start |
( |
| ) |
|
Creates and manages all the threads necessary to run a full session for communicating with a Psion and exposing that to clients via the a TCP socket.
This is a non-blocking function. The session should be stopped by calling stop or cancelling the session using cancel interrupting the session thread with SIGINT.
Definition at line 219 of file ncp_session.cc.
◆ wait()
| void NCPSession::wait |
( |
| ) |
|
Wait for the session to terminate.
A typical usage pattern might call stop, followed by, wait to ensure the session is fully terminated and cleaned up before doing further work (e.g., starting a new session with a different configuration).
Definition at line 245 of file ncp_session.cc.
◆ check_for_new_socket_connection
| void check_for_new_socket_connection |
( |
NCPSession * |
session | ) |
|
|
friend |
◆ link_thread
| void * link_thread |
( |
void * |
arg | ) |
|
|
friend |
- Todo:
- There's something really nuanced going on with the use of the NCPSession::socketChannelWatch_ here. Specifically, while it might look like it's just being used as a timeout (which might be the intent), new TCP sockets are added to it on a successful accept, meaning that this will wake up frequently whenever there's activity on the socket. This will cause frequent NCP::hasFailed checks, and very timely resets (NCP::reset) whenever a client is connected. It's possible this was introduced as a work-around to connectivity issues. It is also worth noting that IOWatch is not thread-safe, so using it in link_thread, and adding to it in ncp_session_main_thread (as we are doing) is definitely a bad thing.
The NCP::reset call here is currently required (even though it feels like it shouldn't be) as it's responsible for preparing the stack after a successful connection has ended (packet currently has responsibility for performing internal resets when auto-detecting baud rate).
Definition at line 51 of file ncp_session.cc.
◆ ncp_session_main_thread
| void * ncp_session_main_thread |
( |
void * |
arg | ) |
|
|
friend |
◆ socket_connection_polling_thread
| void * socket_connection_polling_thread |
( |
void * |
arg | ) |
|
|
friend |
Responsible for driving the SocketChannel instances (incoming TCP connections) by means of SocketChannel::socketPoll.
This isn't likely to scale particularly well as it polls all connected sockets whenever a single one wakes up, but it seems to work (as we never have that many connected clients).
Definition at line 78 of file ncp_session.cc.
◆ autoexit_
| bool NCPSession::autoexit_ |
|
private |
◆ baudRate_
| int NCPSession::baudRate_ |
|
private |
◆ cancellationPipe_
| int NCPSession::cancellationPipe_[2] = { -1, -1 } |
|
private |
◆ host_
| std::string NCPSession::host_ |
|
private |
◆ ncp_
| NCP* NCPSession::ncp_ = nullptr |
|
private |
◆ nverbose_
| unsigned short NCPSession::nverbose_ |
|
private |
◆ portNumber_
| int NCPSession::portNumber_ |
|
private |
◆ serialDevice_
| std::string NCPSession::serialDevice_ |
|
private |
◆ sessionMainThreadId_
| pthread_t NCPSession::sessionMainThreadId_ = 0 |
|
private |
◆ skt_
◆ socketChannelLock_
| std::mutex NCPSession::socketChannelLock_ |
|
private |
◆ socketChannels_
◆ socketChannelWatch_
| IOWatch NCPSession::socketChannelWatch_ |
|
private |
The documentation for this class was generated from the following files: