Fawkes API
Fawkes Development Version
|
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>
46 class FawkesNetworkServerClientSendThread :
public Thread
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_) {
88 outbound_havemore_ =
false;
90 outbound_active_ = 1 - outbound_active_;
91 outbound_msgq_ = outbound_msgqs_[outbound_active_];
113 enqueue(FawkesNetworkMessage *msg)
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();
240 _send_slave->
start();
void lock()
Lock this mutex.
void unref()
Decrement reference count and conditionally delete this instance.
void set_prepfin_conc_loop(bool concurrent=true)
Set concurrent execution of prepare_finalize() and loop().
static const short POLL_HUP
Hang up.
void connection_died()
Connection died notification.
virtual void once()
Execute an action exactly once.
void wakeup()
Wake up thread.
void dispatch(FawkesNetworkMessage *msg)
Dispatch messages.
static const short POLL_RDHUP
Stream socket peer closed connection, or shut down writing half of connection.
void force_send()
Force sending of all pending outbound messages.
void unlock()
Unlock the mutex.
static const short POLL_ERR
Error condition.
virtual void close()
Close socket.
void wait_for_all_sent()
Wait until all data has been sent.
~FawkesNetworkServerClientSendThread()
Destructor.
virtual short poll(int timeout=-1, short what=POLL_IN|POLL_HUP|POLL_PRI|POLL_RDHUP)
Wait for some event on socket.
static void recv(StreamSocket *s, FawkesNetworkMessageQueue *msgq, unsigned int max_num_msgs=8)
Receive data.
static void send(StreamSocket *s, FawkesNetworkMessageQueue *msgq)
Send messages.
void exit()
Exit the thread.
@ OPMODE_WAITFORWAKEUP
operate in wait-for-wakeup mode
static const short POLL_IN
Data can be read.
~FawkesNetworkServerClientThread()
Destructor.
virtual void loop()
Thread loop.
FawkesNetworkServerClientSendThread(StreamSocket *s, FawkesNetworkServerClientThread *parent)
Constructor.
FawkesNetworkServerClientThread(StreamSocket *s, FawkesNetworkServerThread *parent)
Constructor.
void enqueue(FawkesNetworkMessage *msg)
Enqueue message to outbound queue.
void set_clid(unsigned int client_id)
Set client ID.
void lock() const
Lock queue.
virtual void run()
Code to execute in the thread.
unsigned int clid() const
Get client ID.
void start(bool wait=true)
Call this method to start the thread.
void cancel()
Cancel a thread.
void set_client_id(unsigned int clid)
Set client ID.
bool alive() const
Check aliveness of connection.
void enqueue(FawkesNetworkMessage *msg)
Enqueue message to outbound queue.
void join()
Join the thread.
virtual void loop()
Code to execute in the thread.
virtual void run()
Stub to see name in backtrace for easier debugging.
void unlock() const
Unlock list.