CTR Pia  4.11.3
Game Communication Engine
nn::pia::transport::ThreadStreamManager Class Reference

Provides a unified interface for managing sending and receiving threads. More...

+ Inheritance diagram for nn::pia::transport::ThreadStreamManager:

Public Member Functions

void ClearReceiveThreadReceiveDataSize (void)
 Clears the counter tracking the amount of data received. More...
 
void ClearReceiveThreadReceivePacketNum (void)
 Clears the received packet count. More...
 
void ClearSendThreadSendDataSize (void)
 Clears the counter tracking the amount of data sent. More...
 
void ClearSendThreadSendPacketNum (void)
 Clears the sent packet count. More...
 
s32 GetReceiveThreadPacketLossRatio (void) const
 Gets the packet loss rate to emulate on the receive thread. More...
 
s32 GetReceiveThreadPriority (void) const
 Gets the priority of the receive thread. More...
 
u64 GetReceiveThreadReceiveDataSize (void) const
 Gets the total amount of data successfully received in the receive thread. More...
 
size_t GetReceiveThreadReceivePacketNum (void) const
 Gets the number of times the receive thread has successfully received packets. More...
 
u32 GetReceiveThreadSleepTimeSpan (void) const
 Gets the sleep interval of the receive thread. More...
 
s32 GetSendThreadPacketLossRatio (void) const
 Gets the packet loss rate emulated on the send thread. More...
 
s32 GetSendThreadPriority (void) const
 Gets the priority of the send thread. More...
 
u64 GetSendThreadSendDataSize (void) const
 Gets the total amount of data that the send thread attempted to send. More...
 
size_t GetSendThreadSendPacketNum (void) const
 Gets the number of times the send thread attempted to send packets. More...
 
u32 GetSendThreadSleepTimeSpan (void) const
 Gets the sleep interval of the send thread. More...
 
nn::Result SetReceiveThreadLatencyEmulation (s32 minLatency, s32 maxLatency)
 Sets the receive latency time to emulate. More...
 
nn::Result SetReceiveThreadPacketLossRatio (s32 lossPercentage)
 Sets the packet loss rate to emulate on the receive thread. More...
 
void SetReceiveThreadPriority (s32 prio)
 Sets the priority of the receive thread. More...
 
void SetReceiveThreadSleepTimeSpan (u32 span)
 Sets the sleep interval of the receive thread. More...
 
nn::Result SetSendThreadLatencyEmulation (s32 minLatency, s32 maxLatency)
 Sets the send latency time to emulate. More...
 
nn::Result SetSendThreadPacketLossRatio (s32 lossPercentage)
 Sets the packet loss rate to emulate on the send thread. More...
 
void SetSendThreadPriority (s32 prio)
 Sets the priority of the send thread. More...
 
void SetSendThreadSleepTimeSpan (u32 span)
 Sets the sleep interval of the send thread. More...
 
virtual void Trace (u64 flag) const
 Prints information that is useful for debugging. More...
 

Static Public Member Functions

static ThreadStreamManagerGetInstance (void)
 Gets the ThreadStreamManager class instance (singleton pattern). More...
 

Static Public Attributes

static const s32 RECEIVE_THREAD_DEFAULT_PRIORITY = 10
 Specifies the default priority for receiving threads.
 
static const s32 RECEIVE_THREAD_DEFAULT_SLEEP_SPAN = 5
 Specifies the default sleep duration (span) of receiving threads. The value is in milliseconds.
 
static const s32 SEND_THREAD_DEFAULT_PRIORITY = 10
 Specifies the default priority for sending threads.
 
static const s32 SEND_THREAD_DEFAULT_SLEEP_SPAN = 5
 Specifies the default sleep duration (span) of sending threads. The value is in milliseconds.
 

Detailed Description

Provides a unified interface for managing sending and receiving threads.

This class manages sending and receiving threads, including their creation and destruction. It also provides functions for setting priority levels for sending or receiving threads and sleep intervals, and functions that have latency emulation features. An instance of this class is created when the Transport class is initialized.

Revision History:

2014-09-18 Changed the specifications so that ResultAlreadyExists is returned if you call CreateInstance when an instance already exists.

2014-04-02 Changed the specifications of the SetSendThreadPacketLossRatio and SetReceiveThreadPacketLossRatio functions. ResultInvalidState is returned when the packet loss emulation feature is not enabled.

2014-04-02 Changed the specifications of the CreateInstance function. You can now specify whether to enable or disable packet loss emulation.

2014-04-02 Revised the reference. The reference now refers to Transport::DebugSetting for details about the buffer size for latency emulation.

2013-10-18 Fixed errors in the descriptions of GetSendThreadSendDataSize and ClearSendThreadSendDataSize.

2013-10-18 Fixed errors in the descriptions of GetSendThreadSendPacketNum and ClearSendThreadSendPacketNum.

2013-10-15 Added a feature to analyze and tabulate the data in sent and received packets.

2013-09-02 Added functions to get and clear the send and receive data size.

2012-08-24 Added a function for packet-loss emulation.

2012-08-08 Added functions to get and clear the number of send and receive packets.

2012-07-11 Added a description of how to set the priority for sending and receiving threads.

2012-07-05 Added the SetSendThreadLatencyEmulation and SetReceiveThreadLatencyEmulation functions.

2012-06-28 Clearly indicated which functions are thread-safe.

2012-05-24 Initial version.

Member Function Documentation

void nn::pia::transport::ThreadStreamManager::ClearReceiveThreadReceiveDataSize ( void  )

Clears the counter tracking the amount of data received.

This functions clears the counter representing the amount of data successfully received. You can use the GetReceiveThreadSendDataSize function to get the value of this counter.

See also
GetReceiveThreadReceiveDataSize
void nn::pia::transport::ThreadStreamManager::ClearReceiveThreadReceivePacketNum ( void  )

Clears the received packet count.

This functions clears the counter representing the number of packets successfully received. You can use the GetReceiveThreadReceivePacketNum function to get the value of this counter.

See also
GetReceiveThreadReceivePacketNum
void nn::pia::transport::ThreadStreamManager::ClearSendThreadSendDataSize ( void  )

Clears the counter tracking the amount of data sent.

This function clears the counter representing the amount of data that the thread attempted to send. You can use the GetSendThreadSendDataSize function to get the value of this counter.

See also
GetSendThreadSendDataSize
void nn::pia::transport::ThreadStreamManager::ClearSendThreadSendPacketNum ( void  )

Clears the sent packet count.

This function clears the counter representing the number of packets that the thread attempted to send. You can use the GetSendThreadSendPacketNum function to get the value of this counter.

See also
GetSendThreadSendPacketNum
static ThreadStreamManager* nn::pia::transport::ThreadStreamManager::GetInstance ( void  )
inlinestatic

Gets the ThreadStreamManager class instance (singleton pattern).

This function returns a NULL pointer if an instance has not already been created.

Returns
Returns a pointer to the ThreadStreamManager instance.
s32 nn::pia::transport::ThreadStreamManager::GetReceiveThreadPacketLossRatio ( void  ) const

Gets the packet loss rate to emulate on the receive thread.

Returns
Returns the packet loss rate set for the receive thread. The value is in the range from 0 through 100.
See also
SetReceiveThreadPacketLossRatio
s32 nn::pia::transport::ThreadStreamManager::GetReceiveThreadPriority ( void  ) const

Gets the priority of the receive thread.

This function is thread-safe.

Returns
Returns the priority of the receive thread.
See also
SetReceiveThreadPriority
u64 nn::pia::transport::ThreadStreamManager::GetReceiveThreadReceiveDataSize ( void  ) const

Gets the total amount of data successfully received in the receive thread.

The receive thread maintains a count of the amount of data it successfully receives. This function returns that count.

Returns
Returns the total amount of data that has been received successfully. The value is in bytes.
See also
ClearReceiveThreadReceiveDataSize
size_t nn::pia::transport::ThreadStreamManager::GetReceiveThreadReceivePacketNum ( void  ) const

Gets the number of times the receive thread has successfully received packets.

The receive thread maintains a count of the packets that it successfully receives. This function returns that count.

Returns
Returns the total number of packets that have been received successfully.
See also
ClearReceiveThreadReceivePacketNum
u32 nn::pia::transport::ThreadStreamManager::GetReceiveThreadSleepTimeSpan ( void  ) const

Gets the sleep interval of the receive thread.

This function is thread-safe.

Returns
Returns the sleep interval of the receive thread. The value is in milliseconds.
See also
SetReceiveThreadSleepTimeSpan
s32 nn::pia::transport::ThreadStreamManager::GetSendThreadPacketLossRatio ( void  ) const

Gets the packet loss rate emulated on the send thread.

Returns
Returns the packet loss rate set for the send thread. The value is in the range from 0 through 100.
See also
SetSendThreadPacketLossRatio
s32 nn::pia::transport::ThreadStreamManager::GetSendThreadPriority ( void  ) const

Gets the priority of the send thread.

This function is thread-safe.

Returns
Returns the priority of the send thread.
See also
SetSendThreadPriority
u64 nn::pia::transport::ThreadStreamManager::GetSendThreadSendDataSize ( void  ) const

Gets the total amount of data that the send thread attempted to send.

The send thread maintains a count of the amount of data it attempted to send. This function returns that count.

Returns
Returns the total amount of data that the thread attempted to send. The value is in bytes.
See also
ClearSendThreadSendDataSize
size_t nn::pia::transport::ThreadStreamManager::GetSendThreadSendPacketNum ( void  ) const

Gets the number of times the send thread attempted to send packets.

The send thread maintains a count of the packets that it attempted to send. This function returns that count.

Returns
Returns the total number of packets that the thread attempted to send.
See also
ClearSendThreadSendPacketNum
u32 nn::pia::transport::ThreadStreamManager::GetSendThreadSleepTimeSpan ( void  ) const

Gets the sleep interval of the send thread.

This function is thread-safe.

Returns
Returns the sleep interval of the send thread. The value is in milliseconds.
See also
SetSendThreadSleepTimeSpan
nn::Result nn::pia::transport::ThreadStreamManager::SetReceiveThreadLatencyEmulation ( s32  minLatency,
s32  maxLatency 
)

Sets the receive latency time to emulate.

The receiving latency emulation feature does not immediately pass the received packets to higher layers, but instead temporarily saves them to a buffer. After the prescribed amount of time passes, it then passes the saved packets to the higher layers. For this reason, if you increase the maximum delay time without preparing a buffer of an appropriate size, the buffer overflows and packets appear to be lost frequently. For more information about setting the buffer size, see the Transport::DebugSetting structure.

Parameters
[in]minLatencySpecifies the minimum latency. The value is in milliseconds.
[in]maxLatencySpecifies the maximum latency. The value is in milliseconds.
Returns
Returns a Result value for which the IsSuccess function returns true if execution succeeds.
Error Return Values:

ResultInvalidArgument Specifies that one or more arguments are invalid. Programming error. Fix your program so that this error is not returned.

ResultInvalidState Indicates that the latency emulation feature may be disabled. Programming error. Fix your program so that this error is not returned.

See also
SetSendThreadLatencyEmulation, Transport::DebugSetting
nn::Result nn::pia::transport::ThreadStreamManager::SetReceiveThreadPacketLossRatio ( s32  lossPercentage)

Sets the packet loss rate to emulate on the receive thread.

You can use this packet loss emulation feature to emulate cases in which incoming packets were lost for some reason. Setting a value other than 0% in the argument will emulate that rate of packet loss by having the receiving thread drop the specified percentage of packets. By default, the packet loss rate on the receive thread is set to 0%.

Parameters
[in]lossPercentageSpecifies a value in the range from 0 through 100.
Returns
Returns a Result value for which the IsSuccess function returns true if execution succeeds.
Error Return Values:

ResultInvalidArgument Specifies that one or more arguments are invalid. Programming error. Fix your program so that this error is not returned.

ResultInvalidState The packet loss emulation feature is not set to enabled. Programming error. Fix your program so that this error is not returned.

See also
GetReceiveThreadPacketLossRatio, Transport::SetDebugSetting
void nn::pia::transport::ThreadStreamManager::SetReceiveThreadPriority ( s32  prio)

Sets the priority of the receive thread.

In normal use, set the priority of the receiving thread higher than that of the thread in which the application calls the common::Scheduler::Dispatch function.

Parameters
[in]prioSpecifies the priority of the receive thread. We recommend adjusting these values to suit your application's specifications.
See also
GetReceiveThreadPriority, common::Scheduler::Dispatch
void nn::pia::transport::ThreadStreamManager::SetReceiveThreadSleepTimeSpan ( u32  span)

Sets the sleep interval of the receive thread.

The receive thread sleeps periodically. This function sets the sleep interval.

Parameters
[in]spanSpecifies the sleep interval for the receive thread. The value is in milliseconds. We recommend adjusting these values to suit your application's specifications.
See also
GetReceiveThreadSleepTimeSpan
nn::Result nn::pia::transport::ThreadStreamManager::SetSendThreadLatencyEmulation ( s32  minLatency,
s32  maxLatency 
)

Sets the send latency time to emulate.

The sending latency emulation feature does not immediately send the packets that are created, but instead temporarily saves them to a buffer. After the prescribed amount of time passes, it then sends the saved packets. For this reason, if you increase the maximum delay time without preparing a buffer of an appropriate size, the buffer overflows and packets appear to be lost frequently. For more information about setting the buffer size, see the Transport::DebugSetting structure.

Parameters
[in]minLatencySpecifies the minimum latency. The value is in milliseconds.
[in]maxLatencySpecifies the maximum latency. The value is in milliseconds.
Returns
Returns a Result value for which the IsSuccess function returns true if execution succeeds.
Error Return Values:

ResultInvalidArgument Specifies that one or more arguments are invalid. Programming error. Fix your program so that this error is not returned.

ResultInvalidState Indicates that the latency emulation feature may be disabled. Programming error. Fix your program so that this error is not returned.

See also
SetReceiveThreadLatencyEmulation, Transport::DebugSetting
nn::Result nn::pia::transport::ThreadStreamManager::SetSendThreadPacketLossRatio ( s32  lossPercentage)

Sets the packet loss rate to emulate on the send thread.

You can use this packet loss emulation feature to emulate cases in which packets were sent successfully, but were later lost for some reason. Setting a value other than 0% in the argument emulates that rate of packet loss by having the sending thread drop the specified percentage of packets. By default, the packet loss rate on the send thread is set to 0%.

Parameters
[in]lossPercentageSpecifies a value in the range from 0 through 100.
Returns
Returns a Result value for which the IsSuccess function returns true if execution succeeds.
Error Return Values:

ResultInvalidArgument Specifies that one or more arguments are invalid. Programming error. Fix your program so that this error is not returned.

ResultInvalidState The packet loss emulation feature is not set to enabled. Programming error. Fix your program so that this error is not returned.

See also
GetSendThreadPacketLossRatio, Transport::SetDebugSetting
void nn::pia::transport::ThreadStreamManager::SetSendThreadPriority ( s32  prio)

Sets the priority of the send thread.

In normal use, set the priority of the sending thread higher than that of the thread in which the application calls the common::Scheduler::Dispatch function.

Parameters
[in]prioSpecifies the priority of the send thread. We recommend adjusting these values to suit your application's specifications.
See also
GetSendThreadPriority, common::Scheduler::Dispatch
void nn::pia::transport::ThreadStreamManager::SetSendThreadSleepTimeSpan ( u32  span)

Sets the sleep interval of the send thread.

The send thread sleeps periodically. This function sets the sleep interval.

Parameters
[in]spanSpecifies the periodic interval at which to make the send thread sleep. The value is in milliseconds. We recommend adjusting these values to suit your application's specifications.
See also
GetSendThreadSleepTimeSpan
virtual void nn::pia::transport::ThreadStreamManager::Trace ( u64  flag) const
virtual

Prints information that is useful for debugging.

Parameters
[in]flagSpecifies the bitwise OR of trace flags. For more information, see the TraceFlag type.