C++ Rest SDK
The C++ REST SDK is a Microsoft project for cloud-based client-server communication in native code using a modern asynchronous C++ API design. This project aims to help C++ developers connect to and interact with services.
Public Member Functions | List of all members
web::http::experimental::listener::http_listener Class Reference

A class for listening and processing HTTP requests at a specific URI. More...

#include <http_listener.h>

Public Member Functions

 http_listener (http::uri address)
 Create a listener from a URI. More...
 
 http_listener (http::uri address, http_listener_config config)
 Create a listener with specified URI and configuration. More...
 
 http_listener ()
 Default constructor. More...
 
_ASYNCRTIMP ~http_listener ()
 Destructor frees any held resources. More...
 
pplx::task< void > open ()
 Asynchronously open the listener, i.e. start accepting requests. More...
 
pplx::task< void > close ()
 Asynchronously stop accepting requests and close all connections. More...
 
void support (const std::function< void(http_request)> &handler)
 Add a general handler to support all requests. More...
 
void support (const http::method &method, const std::function< void(http_request)> &handler)
 Add support for a specific HTTP method. More...
 
const http::uriuri () const
 Get the URI of the listener. More...
 
const http_listener_configconfiguration () const
 Get the configuration of this listener. More...
 
 http_listener (http_listener &&other)
 Move constructor. More...
 
http_listeneroperator= (http_listener &&other)
 Move assignment operator. More...
 

Detailed Description

A class for listening and processing HTTP requests at a specific URI.

Constructor & Destructor Documentation

web::http::experimental::listener::http_listener::http_listener ( http::uri  address)
inline

Create a listener from a URI.

The listener will not have been opened when returned.

Parameters
addressURI at which the listener should accept requests.
web::http::experimental::listener::http_listener::http_listener ( http::uri  address,
http_listener_config  config 
)
inline

Create a listener with specified URI and configuration.

Parameters
addressURI at which the listener should accept requests.
configConfiguration to create listener with.
web::http::experimental::listener::http_listener::http_listener ( )
inline

Default constructor.

The resulting listener cannot be used for anything, but is useful to initialize a variable that will later be overwritten with a real listener instance.

_ASYNCRTIMP web::http::experimental::listener::http_listener::~http_listener ( )

Destructor frees any held resources.

Call close() before allowing a listener to be destroyed.

web::http::experimental::listener::http_listener::http_listener ( http_listener &&  other)
inline

Move constructor.

Parameters
otherhttp_listener instance to construct this one from.

Member Function Documentation

pplx::task<void> web::http::experimental::listener::http_listener::close ( )
inline

Asynchronously stop accepting requests and close all connections.

Returns
A task that will be completed once this listener is actually closed, no longer accepting requests.

This function will stop accepting requests and wait for all outstanding handler calls to finish before completing the task. Waiting on the task returned from close() within a handler and blocking waiting for its result will result in a deadlock.

Call close() before allowing a listener to be destroyed.

const http_listener_config& web::http::experimental::listener::http_listener::configuration ( ) const
inline

Get the configuration of this listener.

Returns
Configuration this listener was constructed with.
pplx::task<void> web::http::experimental::listener::http_listener::open ( )
inline

Asynchronously open the listener, i.e. start accepting requests.

Returns
A task that will be completed once this listener is actually opened, accepting requests.
http_listener& web::http::experimental::listener::http_listener::operator= ( http_listener &&  other)
inline

Move assignment operator.

Parameters
otherhttp_listener to replace this one with.
void web::http::experimental::listener::http_listener::support ( const std::function< void(http_request)> &  handler)
inline

Add a general handler to support all requests.

Parameters
handlerFunction object to be called for all requests.
void web::http::experimental::listener::http_listener::support ( const http::method method,
const std::function< void(http_request)> &  handler 
)
inline

Add support for a specific HTTP method.

Parameters
methodAn HTTP method.
handlerFunction object to be called for all requests for the given HTTP method.
const http::uri& web::http::experimental::listener::http_listener::uri ( ) const
inline

Get the URI of the listener.

Returns
The URI this listener is for.

The documentation for this class was generated from the following file: