Fawkes API
Fawkes Development Version
|
Fawkes Network Client Thread for server. More...
#include <netcomm/fawkes/server_client_thread.h>
Public Member Functions | |
FawkesNetworkServerClientThread (StreamSocket *s, FawkesNetworkServerThread *parent) | |
Constructor. | |
~FawkesNetworkServerClientThread () | |
Destructor. | |
virtual void | once () |
Execute an action exactly once. | |
virtual void | loop () |
Thread loop. | |
unsigned int | clid () const |
Get client ID. | |
void | set_clid (unsigned int client_id) |
Set client ID. | |
bool | alive () const |
Check aliveness of connection. | |
void | enqueue (FawkesNetworkMessage *msg) |
Enqueue message to outbound queue. | |
void | force_send () |
Force sending of all pending outbound messages. | |
void | connection_died () |
Connection died notification. | |
Protected Member Functions | |
virtual void | run () |
Stub to see name in backtrace for easier debugging. |
Fawkes Network Client Thread for server.
The FawkesNetworkServerThread spawns an instance of this class for every incoming connection. It is then used to handle the client. The thread will start another thread, an instance of FawkesNetworkServerClientSendThread. This will be used to handle all outgoing traffic.
fawkes::FawkesNetworkServerClientThread::FawkesNetworkServerClientThread | ( | StreamSocket * | s, |
FawkesNetworkServerThread * | parent | ||
) |
Constructor.
s | socket to client |
parent | parent network thread |
Definition at line 163 of file server_client_thread.cpp.
References fawkes::Thread::set_prepfin_conc_loop().
fawkes::FawkesNetworkServerClientThread::~FawkesNetworkServerClientThread | ( | ) |
Destructor.
Definition at line 180 of file server_client_thread.cpp.
References fawkes::Thread::cancel(), and fawkes::Thread::join().
bool fawkes::FawkesNetworkServerClientThread::alive | ( | ) | const |
Check aliveness of connection.
Definition at line 302 of file server_client_thread.cpp.
Referenced by fawkes::FawkesNetworkServerClientSendThread::loop().
unsigned int fawkes::FawkesNetworkServerClientThread::clid | ( | ) | const |
Get client ID.
The client ID can be used to send replies.
Definition at line 195 of file server_client_thread.cpp.
void fawkes::FawkesNetworkServerClientThread::connection_died | ( | ) |
Connection died notification.
To be called only be the send slave thread.
Definition at line 324 of file server_client_thread.cpp.
References fawkes::Thread::wakeup().
Referenced by fawkes::FawkesNetworkServerClientSendThread::loop().
void fawkes::FawkesNetworkServerClientThread::enqueue | ( | FawkesNetworkMessage * | msg | ) |
Enqueue message to outbound queue.
This enqueues the given message to the outbound queue. The message will be send in the next loop iteration.
msg | message to enqueue |
Definition at line 292 of file server_client_thread.cpp.
References fawkes::FawkesNetworkServerClientSendThread::enqueue().
void fawkes::FawkesNetworkServerClientThread::force_send | ( | ) |
Force sending of all pending outbound messages.
This is a blocking operation. The current poll will be interrupted by sending a signal to this thread (and ignoring it) and then wait for the sending to finish.
Definition at line 314 of file server_client_thread.cpp.
References fawkes::FawkesNetworkServerClientSendThread::wait_for_all_sent().
void fawkes::FawkesNetworkServerClientThread::loop | ( | ) | [virtual] |
Thread loop.
The client thread loop polls on the socket for 10 ms (wait for events on the socket like closed connection or data that can be read). If any event occurs it is processed. If the connection died or any other error occured the thread is cancelled and the parent FawkesNetworkThread is woken up to carry out any action that is needed when a client dies. If data is available for reading thedata is received and dispatched via recv(). Afterwards the outbound message queue is processed and alle messages are sent. This is also done if the operation could block (POLL_OUT is not honored).
Reimplemented from fawkes::Thread.
Definition at line 260 of file server_client_thread.cpp.
References fawkes::Socket::poll(), fawkes::Socket::POLL_ERR, fawkes::Socket::POLL_HUP, fawkes::Socket::POLL_RDHUP, fawkes::Thread::wakeup(), and fawkes::Socket::POLL_IN.
void fawkes::FawkesNetworkServerClientThread::once | ( | ) | [virtual] |
Execute an action exactly once.
This code is executed once and only once right after the thread is started before loop() is called. This is useful if you want to implement an one-shot background job. Just implement once() and leave once() untouched. Start the thread and detach it and it will just do its job and then die automatically. If you use set_delete_on_exit(true) even the Thread instance will be automatically deleted.
Reimplemented from fawkes::Thread.
Definition at line 241 of file server_client_thread.cpp.
References fawkes::Thread::start().
virtual void fawkes::FawkesNetworkServerClientThread::run | ( | ) | [inline, protected, virtual] |
Stub to see name in backtrace for easier debugging.
Reimplemented from fawkes::Thread.
Definition at line 59 of file server_client_thread.h.
void fawkes::FawkesNetworkServerClientThread::set_clid | ( | unsigned int | client_id | ) |
Set client ID.
client_id | new client ID |
Definition at line 205 of file server_client_thread.cpp.
Referenced by fawkes::FawkesNetworkServerThread::add_connection().