QOSSetFlow function

The QOSSetFlow function is called by an application to request the QOS subsystem to prioritize the application's packets and change the flow traffic. This function is also used to notify the QoS subsystem of a flow change: for example, if the flow rate is changed in order to account for network congestion, or if the QoS priority value requires adjustment for transferring or streaming different types of content over a single persistent socket connection.


ExternC BOOL QOSSetFlow(
  HANDLE       QOSHandle,
  QOS_FLOWID   FlowId,
  QOS_SET_FLOW Operation,
  ULONG        Size,
  PVOID        Buffer,
  DWORD        Flags,



Handle to the QOS subsystem returned by QOSCreateHandle.


A flow identifier. A QOS_FLOWID is an unsigned 32-bit integer.


A QOS_SET_FLOW enumerated type that identifies what will be changed in the flow. This parameter specifies what structure the Buffer will contain.

Value Meaning
The traffic type of the flow will be changed. The Buffer will contain a pointer to a QOS_TRAFFIC_TYPE constant.
The flow rate will be changed. The Buffer will contain a pointer to a QOS_FLOWRATE_OUTGOING structure.
Windows 7, Windows Server 2008 R2, and later: The outgoing DSCP value will be changed. The Buffer will contain a pointer to a DWORD value that defines the arbitrary DSCP value.
Note  This setting requires the calling application be a member of the Administrators or the Network Configuration Operators group.


The size of the Buffer parameter, in bytes.


Pointer to the structure specified by the value of the Operation parameter.


Reserved for future use. This parameter must be set to 0.


Pointer to an OVERLAPPED structure used for asynchronous output. This must be set to NULL if this function is not being called asynchronously.

Return value

If the function succeeds, the return value is nonzero.

If the function fails, the return value is 0. To get extended error information, call GetLastError. Some possible error codes follow.

Return code Description
The QoS subsystem is currently configured by policy to not allow this operation on the network path between this host and the destination host. For example, the default policy prevents qWAVE experiments from running to off-link destinations.
The update flow request was successfully received. Results will be returned during overlapped completion.
The calling application does not have sufficient privileges for the requested operation.
The QOSHandle parameter is invalid.
The FlowId parameter is invalid.
The requested flow properties were not available on this path.
The FlowId parameter specified cannot be found.
A memory allocation failed.
The operation being performed requires information that the QoS subsystem does not have. Obtaining this information on this network is currently not supported. For example, bandwidth estimations cannot be obtained on a network path where the destination host is off-link.
There are insufficient resources to carry out the operation.
The request could not be performed because of an I/O device error.
The indicated device requires reinitialization due to hardware errors. The application should clean up and call QOSCreateHandle again.
A network adapter hardware error occurred.
The network location cannot be reached.
There is currently insufficient data about networking conditions to answer the query. This is typically a transient state where qWAVE has erred on the side of caution as it awaits more data before ascertaining the state of the network.
The network connection with the remote host failed.


If QOSStartTrackingClient has not already been called, calling QOSSetFlow will cause the QOS subsystem to perform the following.

  • Discover whether the end-to-end network path supports prioritization.
  • Track end-to-end network characteristics by way of network experiments. These experiments do not place any noteworthy stress on the network.

If QOSSetFlow returns ERROR_NETWORK_BUSY there is insufficient bandwidth for the specified flow rate and network priority cannot be granted. The application can still transmit a data stream but the flow will not receive priority marking. Ideally an application would not attempt to stream at the requested rate if there is insufficient bandwidth. If ERROR_NETWORK_BUSY is returned the following safe strategy is available:

  1. Query the QoS subsystem with QOSNotifyFlow in order to determine the current available bandwidth and begin to stream at the received lower rate with priority if the network supports it.
  2. Request notification with QOSNotifyFlow for when the originally desired amount of bandwidth is available. When notification is received call QOSSetFlow with the new bandwidth request and send at the new rate again with prioritization if supported.

This function may optionally be called asynchronously.


The following code snippet demonstrates the use of QOSSetFlow in an application. Input parameters QOSHandle, FlowId, FlowId, QOSSetOutgoingRate, and sizeof(QoSOutgoingFlowrate) must be previously initialized by other QoS functions and calculations within the application.

Other QoS function examples that show initialization of parameters include QOSCreateHandle, QOSAddSocketToFlow, and QOSQueryFlow.

See the Windows SDK for a complete sample code listing. SDK folder: Samples\NetDs\GQos\Qos2

if( QOSSetFlow( QOSHandle,
        QOSSetOutgoingRate,           // Operation 
        sizeof(QoSOutgoingFlowrate),  // Size
        &QoSOutgoingFlowrate,         // Buffer
        0,                            // Flags (Must be set to 0 with QoS Version 1.0)
        NULL)                         // Overlapped
        == 0 )
    if( ERROR_INVALID_PARAMETER == GetLastError())
        std::cerr << __FILE__ <<" Line: " << __LINE__ ;
        std::cerr << " - QOSSetFlow failed. Exception code: "; 
        std::cerr << GetLastError() << " - Invalid parameter"; 
        std::cerr << std::endl;
        std::cerr << __FILE__ <<" Line: " << __LINE__ ;
        std::cerr << " - QOSSetFlow failed. Exception code: "; 
        std::cerr << GetLastError() << std::endl;
    std::cout << "QOSSetFlow set outgoing flowrate bandwidth to "; 
    std::cout << QoSOutgoingFlowrate.Bandwidth;
    std::cerr << std::endl;


Minimum supported client Windows Vista [desktop apps only]
Minimum supported server Windows Server 2008 [desktop apps only]
Target Platform Windows
Header qos2.h (include Qos2.h)
Library Qwave.lib
DLL Qwave.dll

See also

Quality Windows Audio/Video Experience (qWAVE)