Fawkes network client send thread. More...
Public Member Functions | |
FawkesNetworkClientSendThread (StreamSocket *s, FawkesNetworkClient *parent) | |
Constructor. | |
~FawkesNetworkClientSendThread () | |
Destructor. | |
virtual void | once () |
Execute an action exactly once. | |
virtual void | loop () |
Code to execute in the thread. | |
void | force_send () |
Force sending of messages. | |
void | enqueue (FawkesNetworkMessage *message) |
Enqueue message to send and take ownership. | |
Protected Member Functions | |
virtual void | run () |
Stub to see name in backtrace for easier debugging. |
Fawkes network client send thread.
Spawned by the FawkesNetworkClient to handle outgoing traffic.
Definition at line 65 of file client.cpp.
fawkes::FawkesNetworkClientSendThread::FawkesNetworkClientSendThread | ( | StreamSocket * | s, | |
FawkesNetworkClient * | parent | |||
) | [inline] |
Constructor.
s | client stream socket | |
parent | parent FawkesNetworkClient instance |
Definition at line 73 of file client.cpp.
fawkes::FawkesNetworkClientSendThread::~FawkesNetworkClientSendThread | ( | ) | [inline] |
void fawkes::FawkesNetworkClientSendThread::enqueue | ( | FawkesNetworkMessage * | message | ) | [inline] |
Enqueue message to send and take ownership.
This method takes ownership of the message. If you want to use the message after enqueing you must reference:
message->ref();
send_slave->enqueue(message);
// message can now still be used
Without extra referencing the message may not be used after enqueuing.
message | message to send |
Definition at line 150 of file client.cpp.
References fawkes::Mutex::lock(), fawkes::Mutex::unlock(), and fawkes::Thread::wakeup().
Referenced by fawkes::FawkesNetworkClient::enqueue(), and fawkes::FawkesNetworkClient::enqueue_and_wait().
void fawkes::FawkesNetworkClientSendThread::force_send | ( | ) | [inline] |
Force sending of messages.
All messages are sent out immediately, if loop is not running already anyway.
Definition at line 131 of file client.cpp.
References loop(), fawkes::Thread::loop_mutex, fawkes::Mutex::try_lock(), and fawkes::Mutex::unlock().
Referenced by fawkes::FawkesNetworkClient::disconnect().
virtual void fawkes::FawkesNetworkClientSendThread::loop | ( | ) | [inline, virtual] |
Code to execute in the thread.
Implement this method to hold the code you want to be executed continously. If you do not implement this method, the default is that the thread will exit. This is useful if you choose to only implement once().
Reimplemented from fawkes::Thread.
Definition at line 105 of file client.cpp.
References fawkes::FawkesNetworkClient::connected(), fawkes::Thread::exit(), fawkes::Mutex::lock(), fawkes::FawkesNetworkTransceiver::send(), and fawkes::Mutex::unlock().
Referenced by force_send().
virtual void fawkes::FawkesNetworkClientSendThread::once | ( | ) | [inline, 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 100 of file client.cpp.
virtual void fawkes::FawkesNetworkClientSendThread::run | ( | ) | [inline, protected, virtual] |
Stub to see name in backtrace for easier debugging.
Reimplemented from fawkes::Thread.
Definition at line 160 of file client.cpp.