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

Manage network sockets and connections. More...

#include <sock.hpp>
#include <upnp.hpp>
#include <UPnPsdk/connection_common.hpp>
#include <UPnPsdk/socket.hpp>
#include <umock/sys_socket.hpp>
#include <umock/ssl.hpp>
+ Include dependency graph for sock.cpp:

Go to the source code of this file.

Functions

int sock_init (SOCKINFO *info, SOCKET sockfd)
 Assign the passed in socket descriptor to socket descriptor in the SOCKINFO structure.
 
int sock_init_with_ip (SOCKINFO *info, SOCKET sockfd, sockaddr *foreign_sockaddr)
 Calls the sock_init function and assigns the passed in IP address and port to the IP address and port in the SOCKINFO structure.
 
int sock_ssl_connect (SOCKINFO *info)
 Associates an SSL object with the socket and begins the client-side SSL/TLS handshake.
 
int sock_destroy (SOCKINFO *info, int ShutdownMethod)
 Shutsdown the socket using the ShutdownMethod to indicate whether sends and receives on the socket will be dis-allowed.
 
int sock_read (SOCKINFO *info, char *buffer, size_t bufsize, int *timeoutSecs)
 Reads data on socket in sockinfo.
 
int sock_write (SOCKINFO *info, const char *buffer, size_t bufsize, int *timeoutSecs)
 Writes data on the socket in sockinfo.
 
int sock_make_blocking (SOCKET sock)
 Make socket blocking.
 
int sock_make_no_blocking (SOCKET sock)
 Make socket non-blocking.
 
int UpnpInitSslContext (int initOpenSslLib, const SSL_METHOD *sslMethod)
 Initializes the OpenSSL library, and the OpenSSL context.
 
void freeSslCtx ()
 Free the OpenSSL context.
 
Scope restricted to file
int anonymous_namespace{sock.cpp}::sock_read_unprotected (const SOCKINFO *a_info, char *a_readbuf, const char *a_writebuf, const size_t a_bufsize, int *a_timeoutSecs)
 Read from a not SSL protected socket.
 
int anonymous_namespace{sock.cpp}::sock_write_unprotected (const SOCKINFO *a_info, char *a_readbuf, const char *a_writebuf, const size_t a_bufsize, int *a_timeoutSecs)
 Write to a not SSL protected socket.
 
int anonymous_namespace{sock.cpp}::sock_read_ssl (const SOCKINFO *a_info, char *a_readbuf, const char *a_writebuf, const size_t a_bufsize, int *a_timeoutSecs)
 Read from an SSL protected socket.
 
int anonymous_namespace{sock.cpp}::sock_write_ssl (const SOCKINFO *a_info, char *a_readbuf, const char *a_writebuf, const size_t a_bufsize, int *a_timeoutSecs)
 Write to an SSL protected socket.
 

Variables

SSL_CTX * anonymous_namespace{sock.cpp}::gSslCtx {nullptr}
 Pointer to an SSL Context.
 

Detailed Description

Manage network sockets and connections.

Definition in file sock.cpp.

Function Documentation

◆ sock_init()

int sock_init ( SOCKINFO info,
SOCKET  sockfd 
)

Assign the passed in socket descriptor to socket descriptor in the SOCKINFO structure.

Returns
Integer:
  • UPNP_E_SUCCESS
  • UPNP_E_OUTOF_MEMORY
  • UPNP_E_SOCKET_ERROR
Parameters
[out]infoSocket Information Object.
[in]sockfdSocket Descriptor.

Definition at line 440 of file sock.cpp.

+ Here is the caller graph for this function:

◆ sock_init_with_ip()

int sock_init_with_ip ( SOCKINFO info,
SOCKET  sockfd,
struct sockaddr *  foreign_sockaddr 
)

Calls the sock_init function and assigns the passed in IP address and port to the IP address and port in the SOCKINFO structure.

Returns
Integer:
  • UPNP_E_SUCCESS
  • UPNP_E_OUTOF_MEMORY
  • UPNP_E_SOCKET_ERROR
Parameters
[out]infoSocket Information Object.
[in]sockfdSocket Descriptor.
[in]foreign_sockaddrRemote socket address.

Definition at line 451 of file sock.cpp.

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

◆ sock_ssl_connect()

int sock_ssl_connect ( SOCKINFO info)

Associates an SSL object with the socket and begins the client-side SSL/TLS handshake.

Returns
Integer:
  • UPNP_E_SUCCESS
  • UPNP_E_SOCKET_ERROR
Parameters
[out]infoSocket Information Object.

Definition at line 469 of file sock.cpp.

+ Here is the caller graph for this function:

◆ sock_destroy()

int sock_destroy ( SOCKINFO info,
int  ShutdownMethod 
)

Shutsdown the socket using the ShutdownMethod to indicate whether sends and receives on the socket will be dis-allowed.

After shutting down the socket, closesocket is called to release system resources used by the socket calls.

Returns
Integer:
  • UPNP_E_SOCKET_ERROR on failure.
  • UPNP_E_SUCCESS on success.
Parameters
[in,out]infoSocket Information Object.
[in]ShutdownMethodHow to shutdown the socket. Used by sockets's shutdown().

Definition at line 489 of file sock.cpp.

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

◆ sock_read()

int sock_read ( SOCKINFO info,
char *  buffer,
size_t  bufsize,
int *  timeoutSecs 
)

Reads data on socket in sockinfo.

Returns
Integer:
  • numBytes - On Success, no of bytes received.
  • UPNP_E_TIMEDOUT - Timeout.
  • UPNP_E_SOCKET_ERROR - Error on socket calls.
Parameters
[in]infoSocket Information Object.
[out]bufferBuffer to get data to.
[in]bufsizeSize of the buffer.
[in,out]timeoutSecstimeout value.

Definition at line 525 of file sock.cpp.

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

◆ sock_write()

int sock_write ( SOCKINFO info,
const char *  buffer,
size_t  bufsize,
int *  timeoutSecs 
)

Writes data on the socket in sockinfo.

Returns
Integer:
  • numBytes - On Success, no of bytes sent.
  • UPNP_E_TIMEDOUT - Timeout.
  • UPNP_E_SOCKET_ERROR - Error on socket calls.
Parameters
[in]infoSocket Information Object.
[in]bufferBuffer to send data from.
[in]bufsizeSize of the buffer.
[in,out]timeoutSecstimeout value.

Definition at line 541 of file sock.cpp.

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

◆ sock_make_blocking()

int sock_make_blocking ( SOCKET  sock)

Make socket blocking.

Returns
0 if successful, SOCKET_ERROR otherwise.

Definition at line 557 of file sock.cpp.

◆ sock_make_no_blocking()

int sock_make_no_blocking ( SOCKET  sock)

Make socket non-blocking.

Returns
0 if successful, SOCKET_ERROR otherwise.

Definition at line 573 of file sock.cpp.

◆ freeSslCtx()

void freeSslCtx ( void  )

Free the OpenSSL context.

Note
This method is only available if the library is compiled with OpenSSL support.

Definition at line 610 of file sock.cpp.

+ Here is the caller graph for this function: