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

Manage network sockets and connections. More...

#include <UPnPsdk/port_sock.hpp>
#include <umock/unistd.hpp>
#include <openssl/ssl.h>
+ Include dependency graph for sock.hpp:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  SOCKINFO
 Additional socket information for connections and ssl. More...
 

Functions

int sock_close (SOCKET sock)
 Closes the socket if it is different from -1.
 
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, 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.
 
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 (void)
 Free the OpenSSL context.
 

Detailed Description

Manage network sockets and connections.

Definition in file sock.hpp.


Class Documentation

◆ SOCKINFO

struct SOCKINFO

Additional socket information for connections and ssl.

Todo:
Cleanup constants: In <sys/socket.h> are defined SHUT_RD, SHUT_WR, SHUT_RDWR with 0, 1, 2, according to man 2 shutdown.

Definition at line 65 of file sock.hpp.

Class Members
SOCKET socket Handle/descriptor to a socket.
sockaddr_storage foreign_sockaddr Socket address of the remote node only filled in incoming requests.
SSL * ssl Information about an ssl connection only filled in incoming requests.
void * ssl Alternative unused member if OpenSSL isn't compiled in.

Function Documentation

◆ sock_close()

int sock_close ( SOCKET  sock)
inline

Closes the socket if it is different from -1.

Returns
-1 if an error occurred or if the socket is -1.
Parameters
sockSocket descriptor.

Definition at line 85 of file sock.hpp.

+ Here is the caller graph for this function:

◆ 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.

◆ UpnpInitSslContext()

int UpnpInitSslContext ( int  initOpenSslLib,
const SSL_METHOD *  sslMethod 
)

Initializes the OpenSSL library, and the OpenSSL context.

Note
This method is only available if the library is compiled with OpenSSL support.
Returns
An integer representing one of the following:
  • UPNP_E_SUCCESS: The operation completed successfully.
  • UPNP_E_INIT: The SDK is already initialized.
  • UPNP_E_INIT_FAILED: The SDK initialization failed. Is OpenSSL available?
Parameters
initOpenSslLibThis argument is ignored and only provided for compatibility. It can be set to any value. The library is initialzed automatically.
sslMethodThe SSL_METHOD to use to create the context. See OpenSSL docs for more info, that recommends to use TLS_method(), TLS_server_method() (for client and server), or TLS_client_method() since OpenSSL 1.1.0 because other methods are deprecated.

Definition at line 590 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: