Manage network sockets and connections.
More...
#include <UPnPsdk/port_sock.hpp>
#include <umock/unistd.hpp>
#include <openssl/ssl.h>
Go to the source code of this file.
|
struct | SOCKINFO |
| Additional socket information for connections and ssl. More...
|
|
|
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.
|
|
Manage network sockets and connections.
Definition in file sock.hpp.
◆ 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. |
◆ 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
-
Definition at line 85 of file sock.hpp.
◆ 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] | info | Socket Information Object. |
[in] | sockfd | Socket Descriptor. |
Definition at line 440 of file sock.cpp.
◆ 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] | info | Socket Information Object. |
[in] | sockfd | Socket Descriptor. |
[in] | foreign_sockaddr | Remote socket address. |
Definition at line 451 of file sock.cpp.
◆ sock_ssl_connect()
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] | info | Socket Information Object. |
Definition at line 469 of file sock.cpp.
◆ 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] | info | Socket Information Object. |
[in] | ShutdownMethod | How to shutdown the socket. Used by sockets's shutdown(). |
Definition at line 489 of file sock.cpp.
◆ 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] | info | Socket Information Object. |
[out] | buffer | Buffer to get data to. |
[in] | bufsize | Size of the buffer. |
[in,out] | timeoutSecs | timeout value. |
Definition at line 525 of file sock.cpp.
◆ 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] | info | Socket Information Object. |
[in] | buffer | Buffer to send data from. |
[in] | bufsize | Size of the buffer. |
[in,out] | timeoutSecs | timeout value. |
Definition at line 541 of file sock.cpp.
◆ 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.