24#include <core/exceptions/system.h>
25#include <core/threading/mutex.h>
26#include <core/threading/wait_condition.h>
27#include <netcomm/fawkes/message_queue.h>
28#include <netcomm/fawkes/server_client_thread.h>
29#include <netcomm/fawkes/server_thread.h>
30#include <netcomm/fawkes/transceiver.h>
31#include <netcomm/socket/stream.h>
32#include <netcomm/utils/exceptions.h>
58 outbound_mutex_ =
new Mutex();
62 outbound_msgq_ = outbound_msgqs_[0];
68 for (
unsigned int i = 0; i < 2; ++i) {
69 while (!outbound_msgqs_[i]->empty()) {
72 outbound_msgqs_[i]->pop();
75 delete outbound_msgqs_[0];
76 delete outbound_msgqs_[1];
77 delete outbound_mutex_;
83 if (!parent_->
alive())
86 while (outbound_havemore_) {
87 outbound_mutex_->
lock();
88 outbound_havemore_ =
false;
90 outbound_active_ = 1 - outbound_active_;
91 outbound_msgq_ = outbound_msgqs_[outbound_active_];
115 outbound_mutex_->
lock();
116 outbound_msgq_->push(msg);
117 outbound_havemore_ =
true;
118 outbound_mutex_->
unlock();
142 Mutex * outbound_mutex_;
143 unsigned int outbound_active_;
144 bool outbound_havemore_;
167:
Thread(
"FawkesNetworkServerClientThread")
187 delete _inbound_queue;
214FawkesNetworkServerClientThread::recv()
219 _inbound_queue->
lock();
220 while (!_inbound_queue->empty()) {
225 _inbound_queue->pop();
230 }
catch (ConnectionDiedException &e) {
240 _send_slave->
start();
Thrown if the connection died during an operation.
A LockQueue of FawkesNetworkMessage to hold messages in inbound and outbound queues.
Representation of a message that is sent over the network.
void set_client_id(unsigned int clid)
Set client ID.
Sending thread for a Fawkes client connected to the server.
virtual void loop()
Code to execute in the thread.
FawkesNetworkServerClientSendThread(StreamSocket *s, FawkesNetworkServerClientThread *parent)
Constructor.
void wait_for_all_sent()
Wait until all data has been sent.
~FawkesNetworkServerClientSendThread()
Destructor.
void enqueue(FawkesNetworkMessage *msg)
Enqueue message to outbound queue.
virtual void run()
Stub to see name in backtrace for easier debugging.
Fawkes Network Client Thread for server.
virtual void loop()
Thread loop.
unsigned int clid() const
Get client ID.
void force_send()
Force sending of all pending outbound messages.
bool alive() const
Check aliveness of connection.
void set_clid(unsigned int client_id)
Set client ID.
void connection_died()
Connection died notification.
~FawkesNetworkServerClientThread()
Destructor.
void enqueue(FawkesNetworkMessage *msg)
Enqueue message to outbound queue.
FawkesNetworkServerClientThread(StreamSocket *s, FawkesNetworkServerThread *parent)
Constructor.
virtual void once()
Execute an action exactly once.
void dispatch(FawkesNetworkMessage *msg)
Dispatch messages.
static void send(StreamSocket *s, FawkesNetworkMessageQueue *msgq)
Send messages.
static void recv(StreamSocket *s, FawkesNetworkMessageQueue *msgq, unsigned int max_num_msgs=8)
Receive data.
The current system call has been interrupted (for instance by a signal).
void lock() const
Lock queue.
void unlock() const
Unlock list.
Mutex mutual exclusion lock.
void lock()
Lock this mutex.
void unlock()
Unlock the mutex.
void unref()
Decrement reference count and conditionally delete this instance.
static const short POLL_RDHUP
Stream socket peer closed connection, or shut down writing half of connection.
static const short POLL_HUP
Hang up.
static const short POLL_IN
Data can be read.
virtual short poll(int timeout=-1, short what=POLL_IN|POLL_HUP|POLL_PRI|POLL_RDHUP)
Wait for some event on socket.
static const short POLL_ERR
Error condition.
virtual void close()
Close socket.
TCP stream socket over IP.
Thread class encapsulation of pthreads.
void set_prepfin_conc_loop(bool concurrent=true)
Set concurrent execution of prepare_finalize() and loop().
Mutex * loop_mutex
Mutex that is used to protect a call to loop().
void start(bool wait=true)
Call this method to start the thread.
void join()
Join the thread.
void exit()
Exit the thread.
void wakeup()
Wake up thread.
void cancel()
Cancel a thread.
virtual void run()
Code to execute in the thread.
@ OPMODE_WAITFORWAKEUP
operate in wait-for-wakeup mode
Fawkes library namespace.