24 #include <core/exceptions/system.h> 26 #include <netcomm/fawkes/server_client_thread.h> 27 #include <netcomm/fawkes/server_thread.h> 28 #include <netcomm/fawkes/message_queue.h> 29 #include <netcomm/fawkes/transceiver.h> 30 #include <netcomm/socket/stream.h> 31 #include <netcomm/utils/exceptions.h> 32 #include <core/threading/mutex.h> 33 #include <core/threading/wait_condition.h> 61 __outbound_mutex =
new Mutex();
64 __outbound_active = 0;
65 __outbound_msgq = __outbound_msgqs[0];
71 for (
unsigned int i = 0; i < 2; ++i) {
72 while ( ! __outbound_msgqs[i]->empty() ) {
75 __outbound_msgqs[i]->pop();
78 delete __outbound_msgqs[0];
79 delete __outbound_msgqs[1];
80 delete __outbound_mutex;
85 if ( ! __parent->
alive() )
return;
87 while ( __outbound_havemore ) {
88 __outbound_mutex->
lock();
89 __outbound_havemore =
false;
91 __outbound_active = 1 - __outbound_active;
92 __outbound_msgq = __outbound_msgqs[__outbound_active];
93 __outbound_mutex->
unlock();
116 __outbound_mutex->
lock();
117 __outbound_msgq->push(msg);
118 __outbound_havemore =
true;
119 __outbound_mutex->
unlock();
138 Mutex *__outbound_mutex;
139 unsigned int __outbound_active;
140 bool __outbound_havemore;
165 :
Thread(
"FawkesNetworkServerClientThread")
186 delete _inbound_queue;
216 FawkesNetworkServerClientThread::recv()
221 _inbound_queue->
lock();
222 while ( ! _inbound_queue->empty() ) {
227 _inbound_queue->pop();
243 _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.