classPiiNetworkServerThread
#include <PiiNetworkServerThread.h>
A worker thread that handles an incoming network connection.
Inherits QThread, PiiProgressController
Description
The thread sleeps if there are no clients to be handled and will be finally killed by PiiNetworkServer. An idle thread can be assigned to a new client once the old one has been handled.
Classes
| class |
An intereface for thread controllers. |
Constructors and destructor
|
Create a new worker thread that uses |
|
|
Calls stop() and waits for the thread to exit, if it is still running. |
Public member functions
|
virtual bool
|
(
Returns |
|
( )
Get the controller. |
|
|
int
|
( )
Get the maximum wait time (milliseconds). |
|
void
|
Set the controller. |
|
void
|
(
Set the maximum number of milliseconds the thread will wait for a new client before terminating itself. |
|
void
|
Start handling of an incoming network request. |
|
void
|
(
Sends a stop signal to the thread. |
Protected member functions
|
void
|
( )
|
Function details
-
PiiNetworkServerThread
Create a new worker thread that uses
protocolto communicate with clients.If
protocolis stateful (PiiNetworkProtocol::hasState() returntrue), the thread assumes the ownership of the pointer. Otherwise, the pointer must remain valid during the lifetime of the thread. -
~PiiNetworkServerThread
()Calls stop() and waits for the thread to exit, if it is still running.
Then deletes the protocol if it is stateful.
-
virtual bool canContinue
(- double percentage
[virtual]Returns
falseif the thread has been stopped with theinterruptflag set totrue.Otherwise returns
true.Reimplemented from PiiProgressController.
-
Controller * controller
()Get the controller.
-
int maxIdleTime
()Get the maximum wait time (milliseconds).
-
void setController
Set the controller.
The controller must be set before startRequest() is called.
-
void setMaxIdleTime
(- int maxIdleTime
Set the maximum number of milliseconds the thread will wait for a new client before terminating itself.
-
void startRequest
Start handling of an incoming network request.
This function stores the socket descriptor and either starts or wakes up the thread.
Parameters
- socketDescriptor
-
the socket descriptor of a connected socket.
-
void stop
(- PiiNetwork::StopMode mode = PiiNetwork::WaitClients
Sends a stop signal to the thread.
The thread will later exit asynchronously.
Parameters
- mode
-
InterruptClients, the protocol will be interrupted even if it is not done with the client yet. IfWaitClients, the thread will wait until the client finishes cleanly.
-
void run
()[protected]
Add a note
Not a single note added yet. Be the first, add yours.