Into

Modules

Documentation

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 protocol to communicate with clients.

Calls stop() and waits for the thread to exit, if it is still running.

Public member functions

virtual bool
(
  • double percentage
)

Returns false if the thread has been stopped with the interrupt flag set to true.

Get the controller.

int

Get the maximum wait time (milliseconds).

void
( )

Set the controller.

void
(
  • int maxIdleTime
)

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
(
  • PiiNetwork::StopMode mode = PiiNetwork::WaitClients
)

Sends a stop signal to the thread.

Protected member functions

void
( )

Function details

  • PiiNetworkServerThread

    ( )

    Create a new worker thread that uses protocol to communicate with clients.

    If protocol is stateful (PiiNetworkProtocol::hasState() return true), 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 false if the thread has been stopped with the interrupt flag set to true.

    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. If WaitClients, the thread will wait until the client finishes cleanly.

  • void run

    ()
    [protected]
Notes (0)

Add a note

Not a single note added yet. Be the first, add yours.