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;
214 FawkesNetworkServerClientThread::recv()
219 _inbound_queue->
lock();
220 while (!_inbound_queue->empty()) {
225 _inbound_queue->pop();
230 }
catch (ConnectionDiedException &e) {
240 _send_slave->
start();
static const short POLL_ERR
Error condition.
virtual void close()
Close socket.
Fawkes Network Client Thread for server.
void set_client_id(unsigned int clid)
Set client ID.
A LockQueue of FawkesNetworkMessage to hold messages in inbound and outbound queues.
void unref()
Decrement reference count and conditionally delete this instance.
void dispatch(FawkesNetworkMessage *msg)
Dispatch messages.
void wait_for_all_sent()
Wait until all data has been sent.
void enqueue(FawkesNetworkMessage *msg)
Enqueue message to outbound queue.
void unlock() const
Unlock list.
Fawkes library namespace.
void unlock()
Unlock the mutex.
void force_send()
Force sending of all pending outbound messages.
static void recv(StreamSocket *s, FawkesNetworkMessageQueue *msgq, unsigned int max_num_msgs=8)
Receive data.
virtual void run()
Code to execute in the thread.
static const short POLL_IN
Data can be read.
Representation of a message that is sent over the network.
virtual void run()
Stub to see name in backtrace for easier debugging.
Thread class encapsulation of pthreads.
Sending thread for a Fawkes client connected to the server.
void set_prepfin_conc_loop(bool concurrent=true)
Set concurrent execution of prepare_finalize() and loop().
TCP stream socket over IP.
Mutex * loop_mutex
Mutex that is used to protect a call to loop().
virtual void loop()
Thread loop.
FawkesNetworkServerClientThread(StreamSocket *s, FawkesNetworkServerThread *parent)
Constructor.
virtual void once()
Execute an action exactly once.
void set_clid(unsigned int client_id)
Set client ID.
void wakeup()
Wake up thread.
The current system call has been interrupted (for instance by a signal).
bool alive() const
Check aliveness of connection.
FawkesNetworkServerClientSendThread(StreamSocket *s, FawkesNetworkServerClientThread *parent)
Constructor.
Thrown if the connection died during an operation.
void cancel()
Cancel a thread.
static const short POLL_RDHUP
Stream socket peer closed connection, or shut down writing half of connection.
virtual void loop()
Code to execute in the thread.
virtual short poll(int timeout=-1, short what=POLL_IN|POLL_HUP|POLL_PRI|POLL_RDHUP)
Wait for some event on socket.
~FawkesNetworkServerClientSendThread()
Destructor.
void lock() const
Lock queue.
~FawkesNetworkServerClientThread()
Destructor.
static void send(StreamSocket *s, FawkesNetworkMessageQueue *msgq)
Send messages.
static const short POLL_HUP
Hang up.
void join()
Join the thread.
void lock()
Lock this mutex.
void enqueue(FawkesNetworkMessage *msg)
Enqueue message to outbound queue.
operate in wait-for-wakeup mode
Mutex mutual exclusion lock.
void connection_died()
Connection died notification.
void exit()
Exit the thread.
unsigned int clid() const
Get client ID.
void start(bool wait=true)
Call this method to start the thread.