#include <transferthread.h>
Public Member Functions | |
TransferThread (Server *pcServer) | |
TransferThread Constructor. Initializes the TransferThread creating its pipes, locks and curl objects. | |
~TransferThread () | |
TransferThread Deconstructor. This deletes the lock for this thread and cleans up curl data. | |
int32 | Run () |
The main loop of the thread. | |
int | Lock () |
Lock the Thread. This is used to lock the thread from further access until any operations being performed are complete. | |
int | Unlock () |
Unlock the Thread. This unlocks the thread for further operations. | |
int | SendMessage (int nCode) |
Wrapper for sending messages with numerical codes. This creates a Message object using nCode as a parameter. | |
int | SendMessage (Message *pcMsg) |
Send a message to the thread. The message will be deleted by the thread once it is processed, so it should be created via new Message( code ). | |
Private Member Functions | |
void | _Notify () |
Notify() writes a piece of data to the pipe to wake the transfer thread from its select() sleep. This is called from gui threads. | |
void | _ProcessMessages () |
Checks for messages from other threads and carries out the appropriate action (adding handles to curl_multi_handle, etc). | |
void | _Schedule () |
Assign queued transfers to idle curl handles. This schedules a transfer for one of the curl handles. | |
void | _CleanupNode (int nNode) |
_CleanupNode() cleans up and deletes a finished QueueNode. | |
Private Attributes | |
Server * | m_pcServer |
Our server object. | |
int | m_nReadPipe |
int | m_nWritePipe |
std::queue< Message * > | m_apcMessages |
Locker * | m_pcLock |
A mutex lock for the thread. | |
CURLM * | m_pCurlMultiHandle |
std::vector< CurlHandle_s * > | m_asHandles |
Friends | |
class | Server |
TransferThread::TransferThread | ( | Server * | pcServer | ) |
TransferThread Constructor. Initializes the TransferThread creating its pipes, locks and curl objects.
pcServer | The server that this thread is working for. |
TransferThread::~TransferThread | ( | ) |
TransferThread Deconstructor. This deletes the lock for this thread and cleans up curl data.
int TransferThread::SendMessage | ( | int | nCode | ) |
Wrapper for sending messages with numerical codes. This creates a Message object using nCode as a parameter.
nCode | The code to send for the message. |
int TransferThread::SendMessage | ( | Message * | pcMsg | ) |
Send a message to the thread. The message will be deleted by the thread once it is processed, so it should be created via new Message( code ).
void TransferThread::_ProcessMessages | ( | ) | [private] |
Checks for messages from other threads and carries out the appropriate action (adding handles to curl_multi_handle, etc).
void TransferThread::_CleanupNode | ( | int | nNode | ) | [private] |
_CleanupNode() cleans up and deletes a finished QueueNode.
nNode | The QueueNode ID to remove. |
int TransferThread::m_nReadPipe [private] |
Read pipe for communication. See pipe function in unistd.h.
int TransferThread::m_nWritePipe [private] |
Write pipe for communication. See pipe function in unistd.h.
std::queue< Message* > TransferThread::m_apcMessages [private] |
Stores the queue of messages for this thread.
CURLM* TransferThread::m_pCurlMultiHandle [private] |
Our CURLM handle. Contains a pointer to our curl_multi_init() handle.
std::vector< CurlHandle_s* > TransferThread::m_asHandles [private] |
List of all the curl handles we own, and the corresponding queue nodes.