66 lout <<
"ncp: restarting\n";
93 std::vector<SocketChannel *> socketChannels;
98 for (
auto &socketChannel : socketChannels) {
99 socketChannel->socketPoll();
110 if (!socketChannel->shouldTerminate()) {
113 delete socketChannel;
134 lout <<
"New socket connection from " << peer << endl;
139 bool didAddSocket =
false;
163 a.addStringT(
"No Psion Connected\n");
167 lout <<
"rejected" << endl;
175 lerr <<
"listen on " << session->
host_ <<
":" << session->
portNumber_ <<
": " << strerror(errno) << endl;
186 pthread_t thr_a, thr_b;
187 if (pthread_create(&thr_a, NULL,
link_thread, session) != 0) {
188 lerr <<
"Could not create Link thread" << endl;
192 lerr <<
"Could not create Socket thread" << endl;
198 linf <<
_(
"terminating") << endl;
200 pthread_join(thr_a, &ret);
201 linf <<
_(
"joined Link thread") << endl;
202 pthread_join(thr_b, &ret);
203 linf <<
_(
"joined Socket thread") << endl;
204 delete session->
ncp_;
205 linf <<
_(
"shut down NCP") << endl;
207 linf <<
_(
"socket closed") << endl;
241 struct timeval t = {0, 0};
void addIO(const int fd)
Adds a file descriptor to the set of descriptors.
bool watch(const long secs, const long usecs)
Performs a select() call.
Responsible for orchestrating the high-level life cycle of a daemon-side NCP server and multiplexing ...
IOWatch socketChannelWatch_
Used to watch all active SocketChannel instances (stored in socketChannels_) to see if they're readab...
void cancel()
Mark the session as cancelled.
std::string serialDevice_
std::mutex socketChannelLock_
pthread_t sessionMainThreadId_
void wait()
Wait for the session to terminate.
std::vector< SocketChannel * > socketChannels_
int start()
Creates and manages all the threads necessary to run a full session for communicating with a Psion an...
friend void * ncp_session_main_thread(void *arg)
A class for dealing with sockets.
bool closeSocket(void)
Closes the connection.
void setWatch(IOWatch *watch)
Registers an IOWatch for this socket.
virtual bool listen(const char *const Host, int Port)
Starts listening.
int getBufferStore(bufferStore &a, bool wait=true)
Receive data into a bufferStore .
bool sendBufferStore(const bufferStore &a)
Sends data from a bufferStore .
TCPSocket * accept(std::string *Peer)
Accept a connection; blocking, non-cancellable.
bool dataToGet(int sec, int usec) const
Check and optionally wait for incoming data.
A generic container for an array of bytes.
void check_for_new_socket_connection(NCPSession *session)
void * link_thread(void *arg)
void * socket_connection_polling_thread(void *arg)
Responsible for driving the SocketChannel instances (incoming TCP connections) by means of SocketChan...
void * ncp_session_main_thread(void *arg)