UPnPsdk 0.1
Universal Plug and Play +, Software Development Kit
 
Loading...
Searching...
No Matches
miniserver.hpp File Reference

Manage "Step 0: Addressing" of the UPnP+™ specification. More...

#include <httpparser.hpp>
#include <sock.hpp>
#include <UPnPsdk/socket.hpp>
+ Include dependency graph for miniserver.hpp:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  MiniServerSockArray
 Provides sockets for all network communications. More...
 

Typedefs

typedef void(* MiniServerCallback) (http_parser_t *parser, http_message_t *request, SOCKINFO *info)
 For a miniserver callback function.
 

Functions

void SetSoapCallback (MiniServerCallback callback)
 Set SOAP Callback.
 
void SetGenaCallback (MiniServerCallback callback)
 Set GENA Callback.
 
int StartMiniServer (in_port_t *listen_port4, in_port_t *listen_port6, in_port_t *listen_port6UlaGua)
 Initialize the sockets functionality for the Miniserver.
 
int StopMiniServer ()
 Stop and Shutdown the MiniServer and free socket resources.
 

Variables

MiniServerCallback gGetCallback {nullptr}
 HTTP server callback.
 

Detailed Description

Manage "Step 0: Addressing" of the UPnP+™ specification.

The minserver program module is encapsulated in this file and has only some public available structures and functions. All other internals are restricted to file scope using the anonymous namespace. The miniserver is started with StartMiniServer(). It mainly initializes and manages the needed network sockets, starts a new thread and runs the miniserver in it with locking and unlocking mutexes. All constructed resources with StartMiniServer() are freed with StopMiniServer(). The miniserver is stopped through a separate stop socket that sends a regular network stop message to localhost for the running miniserver in its thread. This way the blocking ::select() listing will always be triggered and can shutdown the miniserver.

Definition in file miniserver.hpp.


Class Documentation

◆ MiniServerSockArray

struct MiniServerSockArray

Provides sockets for all network communications.

Definition at line 64 of file miniserver.hpp.

+ Collaboration diagram for MiniServerSockArray:
Class Members
SOCKET miniServerSock4 IPv4 socket for listening for miniserver requests.
SOCKET miniServerSock6 IPv6 LLA Socket for listening for miniserver requests.
SOCKET miniServerSock6UlaGua IPv6 ULA or GUA Socket for listening for miniserver requests.
SOCKET miniServerStopSock Datagram Socket for stopping miniserver.
SOCKET ssdpSock4 IPv4 SSDP datagram Socket for incoming advertisments and search requests.
SOCKET ssdpSock6 IPv6 LLA SSDP Socket for incoming advertisments and search requests.
SOCKET ssdpSock6UlaGua IPv6 ULA or GUA SSDP Socket for incoming advertisments and search requests.
in_port_t stopPort Corresponding port to miniServerStopSock. This is set with miniStopSockPort but never used.
in_port_t miniServerPort4 Corresponding port to miniServerSock4.
in_port_t miniServerPort6 Corresponding port to miniServerSock6.
in_port_t miniServerPort6UlaGua Corresponding port to miniServerSock6UlaGua.
CSocket * pSockLlaObj
CSocket * pSockGuaObj
CSocket * pSockIp4Obj
SOCKET ssdpReqSock4 IPv4 SSDP socket for sending search requests and receiving search replies.
SOCKET ssdpReqSock6 IPv6 SSDP socket for sending search requests and receiving search replies.

Typedef Documentation

◆ MiniServerCallback

typedef void(* MiniServerCallback) (http_parser_t *parser, http_message_t *request, SOCKINFO *info)

For a miniserver callback function.

Definition at line 111 of file miniserver.hpp.

Function Documentation

◆ SetSoapCallback()

void SetSoapCallback ( MiniServerCallback  callback)

Set SOAP Callback.

Parameters
[in]callbackSOAP Callback to be invoked.

Definition at line 1029 of file miniserver.cpp.

+ Here is the caller graph for this function:

◆ SetGenaCallback()

void SetGenaCallback ( MiniServerCallback  callback)

Set GENA Callback.

Parameters
[in]callbackGENA Callback to be invoked.

Definition at line 1036 of file miniserver.cpp.

+ Here is the caller graph for this function:

◆ StartMiniServer()

int StartMiniServer ( in_port_t *  listen_port4,
in_port_t *  listen_port6,
in_port_t *  listen_port6UlaGua 
)

Initialize the sockets functionality for the Miniserver.

Initialize a thread pool job to run the MiniServer and the job to the thread pool. If a listening port is specified to 0, then the port number is dynamically picked. Use timer mechanism to start the MiniServer, failure to meet the allowed delay aborts the attempt to launch the MiniServer.

The three parameter are only used if we have also a webserver built in. The miniserver does not need them.

I use a simple random number generator for unspecified port numbers. This is needed because I do not reuse addresses before TIME_WAIT has expired (socket option SO_REUSEADDR = false). I must use different socket addresses to be able to restart a device immediately without TIME_WAIT and that is already given with different port numbers on the same ip address.

Returns
  • On success: UPNP_E_SUCCESS
  • On error: UPNP_E_*
Parameters
[in,out]listen_port4Port on which the server listens for incoming IPv4 connections.
[in,out]listen_port6Port on which the server listens for incoming IPv6 LLA connections.
[in,out]listen_port6UlaGuaPort on which the server listens for incoming IPv6 ULA or GUA connections.

Definition at line 1042 of file miniserver.cpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ StopMiniServer()

int StopMiniServer ( )

Stop and Shutdown the MiniServer and free socket resources.

Returns
Always returns 0.

Definition at line 1156 of file miniserver.cpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Variable Documentation

◆ gGetCallback

MiniServerCallback gGetCallback {nullptr}
inline

HTTP server callback.

Definition at line 115 of file miniserver.hpp.