libUPnP 1.14.19
|
Implements the functionality and utility functions used by the Miniserver module. More...
#include "config.h"
#include "miniserver.h"
#include "ThreadPool.h"
#include "httpreadwrite.h"
#include "ithread.h"
#include "ssdplib.h"
#include "statcodes.h"
#include "unixutil.h"
#include "upnpapi.h"
#include "upnputil.h"
#include <assert.h>
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
Data Structures | |
struct | mserv_request_t |
Macros | |
#define | APPLICATION_LISTENING_PORT 49152 |
Enumerations | |
enum | MiniServerState { MSERV_IDLE , MSERV_RUNNING , MSERV_STOPPING } |
Functions | |
static UPNP_INLINE void | fdset_if_valid (SOCKET sock, fd_set *set) |
static void | web_server_accept (SOCKET lsock, fd_set *set) |
static void | ssdp_read (SOCKET *rsock, fd_set *set) |
static int | receive_from_stopSock (SOCKET ssock, fd_set *set) |
static void | RunMiniServer (MiniServerSockArray *miniSock) |
Run the miniserver. | |
static int | get_port (SOCKET sockfd, uint16_t *port) |
Returns port to which socket, sockfd, is bound. | |
static int | get_miniserver_stopsock (MiniServerSockArray *out) |
Creates the miniserver STOP socket. This socket is created and listened on to know when it is time to stop the Miniserver. | |
static UPNP_INLINE void | InitMiniServerSockArray (MiniServerSockArray *miniSocket) |
int | StartMiniServer (uint16_t *listen_port4, uint16_t *listen_port6, uint16_t *listen_port6UlaGua) |
Initialize the sockets functionality for the Miniserver. | |
int | StopMiniServer () |
Stop and Shutdown the MiniServer and free socket resources. | |
Variables | |
uint16_t | miniStopSockPort |
static MiniServerState | gMServState = MSERV_IDLE |
Implements the functionality and utility functions used by the Miniserver module.
The miniserver is a central point for processing all network requests. It is made of:
#define APPLICATION_LISTENING_PORT 49152 |
enum MiniServerState |
|
static |
Creates the miniserver STOP socket. This socket is created and listened on to know when it is time to stop the Miniserver.
UPNP_E_OUTOF_SOCKET:
Failed to create a socket. UPNP_E_SOCKET_BIND:
Bind() failed. UPNP_E_INTERNAL_ERROR:
Port returned by the socket layer is < 0. UPNP_E_SUCCESS:
Success. [in] | out | Miniserver Socket Array. |
References get_port(), INVALID_SOCKET, MServerSockArray::miniServerStopSock, miniStopSockPort, sock_close(), SOCKET_ERROR, UPNP_E_INTERNAL_ERROR, UPNP_E_OUTOF_SOCKET, UPNP_E_SOCKET_BIND, UPNP_E_SUCCESS, and UpnpPrintf().
Referenced by StartMiniServer().
|
static |
Returns port to which socket, sockfd, is bound.
[in] | sockfd | Socket descriptor. |
[out] | port | The port value if successful, otherwise, untouched. |
References UpnpPrintf().
Referenced by get_miniserver_stopsock().
|
static |
Run the miniserver.
The MiniServer accepts a new request and schedules a thread to handle the new request. Checks for socket state and invokes appropriate read and shutdown actions for the Miniserver and SSDP sockets.
[in] | miniSock | Socket Array. |
References gMServState, MServerSockArray::miniServerSock4, MServerSockArray::miniServerSock6, MServerSockArray::miniServerSock6UlaGua, MServerSockArray::miniServerStopSock, MSERV_IDLE, MSERV_RUNNING, sock_close(), SOCKET_ERROR, MServerSockArray::ssdpReqSock4, MServerSockArray::ssdpReqSock6, MServerSockArray::ssdpSock4, MServerSockArray::ssdpSock6, MServerSockArray::ssdpSock6UlaGua, and UpnpPrintf().
Referenced by StartMiniServer().
int StartMiniServer | ( | uint16_t * | listen_port4, |
uint16_t * | listen_port6, | ||
uint16_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 listen port is 0, port is dynamically picked.
Use timer mechanism to start the MiniServer, failure to meet the allowed delay aborts the attempt to launch the MiniServer.
[in,out] | listen_port4 | Port on which the server listens for incoming IPv4 connections. |
[in,out] | listen_port6 | Port on which the server listens for incoming IPv6 LLA connections. |
[in,out] | listen_port6UlaGua | Port on which the server listens for incoming IPv6 ULA or GUA connections. |
References get_miniserver_stopsock(), get_ssdp_sockets(), gMiniServerThreadPool, gMServState, MServerSockArray::miniServerSock4, MServerSockArray::miniServerSock6, MServerSockArray::miniServerSock6UlaGua, MServerSockArray::miniServerStopSock, MSERV_IDLE, MSERV_RUNNING, RunMiniServer(), sock_close(), MServerSockArray::ssdpReqSock4, MServerSockArray::ssdpReqSock6, MServerSockArray::ssdpSock4, MServerSockArray::ssdpSock6, MServerSockArray::ssdpSock6UlaGua, ThreadPoolAddPersistent(), TPJobInit(), TPJobSetFreeFunction(), TPJobSetPriority(), UPNP_E_INTERNAL_ERROR, UPNP_E_OUTOF_MEMORY, and UPNP_E_SUCCESS.
Referenced by UpnpInitStartServers().
int StopMiniServer | ( | ) |
Stop and Shutdown the MiniServer and free socket resources.
References gMServState, INVALID_SOCKET, miniStopSockPort, MSERV_IDLE, MSERV_RUNNING, MSERV_STOPPING, sock_close(), and UpnpPrintf().
Referenced by UpnpFinish().
|
static |
module vars
Referenced by RunMiniServer(), StartMiniServer(), and StopMiniServer().
uint16_t miniStopSockPort |
Referenced by get_miniserver_stopsock(), and StopMiniServer().