UPnPsdk 0.1
Universal Plug and Play +, Software Development Kit
 
Loading...
Searching...
No Matches
sock_if.hpp
1
2#ifndef INTERFACE_PUPNP_SOCK_HPP
3#define INTERFACE_PUPNP_SOCK_HPP
4// Copyright (C) 2023+ GPL 3 and higher by Ingo Höft, <Ingo@Hoeft-online.de>
5// Redistribution only with this Copyright remark. Last modified: 2025-06-11
6
7// Not used at time but have it available for later use. It was too much typing
8// to just throw it away.
9
10#include <sock.hpp>
11
12// Interface for the sock module
13// =============================
14// clang-format off
15
16class UPnPsdk_VIS SockInterface {
17 public:
18 virtual ~SockInterface();
19
20 virtual int sock_init(
21 SOCKINFO* info, SOCKET sockfd) = 0;
22 virtual int sock_init_with_ip(
23 SOCKINFO* info, SOCKET sockfd, struct sockaddr* foreign_sockaddr) = 0;
24#ifdef UPnPsdk_HAVE_OPENSSL
25 virtual int sock_ssl_connect(
26 SOCKINFO* info) = 0;
27#endif
28 virtual int sock_destroy(
29 SOCKINFO* info, int ShutdownMethod) = 0;
30 virtual int sock_read(
31 SOCKINFO* info, char* buffer, size_t bufsize, int* timeoutSecs) = 0;
32 virtual int sock_write(
33 SOCKINFO* info, const char* buffer, size_t bufsize, int* timeoutSecs) = 0;
34 virtual int sock_make_blocking(
35 SOCKET sock) = 0;
36 virtual int sock_make_no_blocking(
37 SOCKET sock) = 0;
38 virtual int sock_close(
39 SOCKET sock) = 0;
40};
41// clang-format on
42
43#endif // INTERFACE_PUPNP_SOCK_HPP
44
45
46#define INCLUDE_COMPA_SOCK_HPP
47// Copyright (C) 2023+ GPL 3 and higher by Ingo Höft, <Ingo@Hoeft-online.de>
48// Redistribution only with this Copyright remark. Last modified: 2023-09-13
49
50#include <interface/pupnp-sock.hpp>
51
52namespace compa {
53
54// Declarations for the sock module using the interface
55// ====================================================
56// clang-format off
57
58class UPNPLIB_API Csock : public ::SockInterface {
59 public:
60 virtual ~Csock() override = default;
61
62 UPNPLIB_LOCAL int sock_init(SOCKINFO* info, SOCKET sockfd) override {
63 return ::sock_init(info, sockfd); }
64 UPNPLIB_LOCAL int sock_init_with_ip( SOCKINFO* info, SOCKET sockfd, struct sockaddr* foreign_sockaddr) override {
65 return ::sock_init_with_ip(info, sockfd, foreign_sockaddr); }
66#ifdef UPNP_ENABLE_OPEN_SSL
67 int sock_ssl_connect( SOCKINFO* info) override;
68#endif
69 UPNPLIB_LOCAL int sock_destroy(SOCKINFO* info, int ShutdownMethod) override {
70 return ::sock_destroy(info, ShutdownMethod); }
71 UPNPLIB_LOCAL int sock_read(SOCKINFO* info, char* buffer, size_t bufsize, int* timeoutSecs) override {
72 return ::sock_read(info, buffer, bufsize, timeoutSecs); }
73 UPNPLIB_LOCAL int sock_write(SOCKINFO* info, const char* buffer, size_t bufsize, int* timeoutSecs) override {
74 return ::sock_write(info, buffer, bufsize, timeoutSecs); }
75 UPNPLIB_LOCAL int sock_make_blocking(SOCKET sock) override {
76 return ::sock_make_blocking(sock); }
77 UPNPLIB_LOCAL int sock_make_no_blocking(SOCKET sock) override {
78 return ::sock_make_no_blocking(sock); }
79 UPNPLIB_LOCAL int sock_close(SOCKET sock) override {
80 return ::sock_close(sock); }
81};
82// clang-format on
83
84} // namespace compa
85
86#endif // INCLUDE_COMPA_SOCK_HPP
87
88
89// Copyright (C) 2023+ GPL 3 and higher by Ingo Höft, <Ingo@Hoeft-online.de>
90// Redistribution only with this Copyright remark. Last modified: 2025-05-21
91
92#include <interface/pupnp-sock.hpp>
93
94// Interface for the sock module
95// =============================
96
97// This destructor can also be defined direct in the header file as usual but
98// then the symbol is included and not linked. We have to decorate the symbol
99// with __declspec(dllexport) on Microsoft Windows in a header file that
100// normaly import symbols. It does not conform to the visibility macro
101// UPnPsdk_VIS and would require other advanced special handling. So we link
102// the symbol with this source file so it do the right think with it. --Ingo
103SockInterface::~SockInterface() = default;
104
Refactored pupnp program code that is compatible to the original pupnp code.
int sock_make_blocking(SOCKET sock)
Make socket blocking.
Definition sock.cpp:557
int sock_ssl_connect(SOCKINFO *info)
Associates an SSL object with the socket and begins the client-side SSL/TLS handshake.
Definition sock.cpp:469
int sock_make_no_blocking(SOCKET sock)
Make socket non-blocking.
Definition sock.cpp:573
int sock_destroy(SOCKINFO *info, int ShutdownMethod)
Shutsdown the socket using the ShutdownMethod to indicate whether sends and receives on the socket wi...
Definition sock.cpp:489
int sock_read(SOCKINFO *info, char *buffer, size_t bufsize, int *timeoutSecs)
Reads data on socket in sockinfo.
Definition sock.cpp:525
int sock_write(SOCKINFO *info, const char *buffer, size_t bufsize, int *timeoutSecs)
Writes data on the socket in sockinfo.
Definition sock.cpp:541
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...
Definition sock.cpp:451
int sock_init(SOCKINFO *info, SOCKET sockfd)
Assign the passed in socket descriptor to socket descriptor in the SOCKINFO structure.
Definition sock.cpp:440
Manage network sockets and connections.
int sock_close(SOCKET sock)
Closes the socket if it is different from -1.
Definition sock.hpp:85
Additional socket information for connections and ssl.
Definition sock.hpp:65
#define UPnPsdk_VIS
Prefix to export symbol for external use.