Qore Programming Language  1.12.2
QoreSocket.h
1 /* -*- mode: c++; indent-tabs-mode: nil -*- */
2 /*
3  QoreSocket.h
4 
5  IPv4, IPv6, unix socket class with SSL support
6 
7  Qore Programming Language
8 
9  Copyright (C) 2003 - 2022 Qore Technologies, s.r.o.
10 
11  will unlink (delete) UNIX domain socket files when closed
12 
13  Permission is hereby granted, free of charge, to any person obtaining a
14  copy of this software and associated documentation files (the "Software"),
15  to deal in the Software without restriction, including without limitation
16  the rights to use, copy, modify, merge, publish, distribute, sublicense,
17  and/or sell copies of the Software, and to permit persons to whom the
18  Software is furnished to do so, subject to the following conditions:
19 
20  The above copyright notice and this permission notice shall be included in
21  all copies or substantial portions of the Software.
22 
23  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
24  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
25  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
26  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
27  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
28  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
29  DEALINGS IN THE SOFTWARE.
30 
31  Note that the Qore library is released under a choice of three open-source
32  licenses: MIT (as above), LGPL 2+, or GPL 2+; see README-LICENSE for more
33  information.
34 */
35 
36 #ifndef _QORE_QORESOCKET_H
37 
38 #define _QORE_QORESOCKET_H
39 
40 #include <qore/Qore.h>
41 #include <qore/InputStream.h>
42 #include <qore/OutputStream.h>
43 #include <qore/AbstractPollState.h>
44 
45 #include <cctype>
46 #include <cstdlib>
47 #include <cstring>
48 #include <strings.h>
49 #include <sys/types.h>
50 #include <unistd.h>
51 
52 #include <openssl/ssl.h>
53 #include <openssl/err.h>
54 
55 #define QSE_MISC_ERR 0
56 #define QSE_RECV_ERR -1
57 #define QSE_NOT_OPEN -2
58 #define QSE_TIMEOUT -3
59 #define QSE_SSL_ERR -4
60 #define QSE_IN_OP -5
61 #define QSE_IN_OP_THREAD -6
62 
63 // forward reference
64 class Queue;
65 
67 
74 class SocketSource {
75  friend hashdecl qore_socket_private;
76 
77 private:
78  hashdecl qore_socketsource_private *priv; // private implementation
79 
81  DLLLOCAL SocketSource(const SocketSource&);
82 
84  DLLLOCAL SocketSource& operator=(const SocketSource&);
85 
86 public:
88  DLLEXPORT SocketSource();
89 
91  DLLEXPORT ~SocketSource();
92 
94 
97 
99 
102 
104 
106  DLLEXPORT const char* getAddress() const;
107 
109 
111  DLLEXPORT const char* getHostName() const;
112 
113  DLLLOCAL void setAll(QoreObject* o, ExceptionSink* xsink);
114 };
115 
117 
127 class QoreSocket {
128  friend hashdecl qore_socket_private;
129  friend hashdecl qore_httpclient_priv;
130  friend class QoreSocketObject;
131  friend class QoreFtpClient;
132  friend class HttpClientRecvHeaderPollState;
133  friend class HttpClientRecvChunkedPollState;
134  friend class HttpClientRecvUntilClosePollState;
135  friend class HttpClientConnectSendRecvPollOperation;
136  friend class my_socket_priv;
137 
138 public:
140  DLLEXPORT QoreSocket();
141 
143  DLLEXPORT ~QoreSocket();
144 
146 
156  DLLEXPORT AbstractPollState* startConnect(ExceptionSink* xsink, const char* name);
157 
159 
166  DLLEXPORT AbstractPollState* startSslConnect(ExceptionSink* xsink, X509* cert = nullptr, EVP_PKEY* pkey = nullptr);
167 
169 
178  DLLEXPORT AbstractPollState* startSend(ExceptionSink* xsink, const char* data, size_t size);
179 
181 
189  DLLEXPORT AbstractPollState* startRecv(ExceptionSink* xsink, size_t size);
190 
192 
202  DLLEXPORT AbstractPollState* startRecvUntilBytes(ExceptionSink* xsink, const char* pattern, size_t size);
203 
204 #if 0
206 
213  DLLEXPORT AbstractPollState* startAccept(ExceptionSink* xsink);
214 
216 
223  DLLEXPORT AbstractPollState* startSslAccept(ExceptionSink* xsink, X509* cert, EVP_PKEY* pkey);
224 #endif
225 
227 
238  DLLEXPORT int connect(const char* name, ExceptionSink* xsink = nullptr);
239 
241 
253  DLLEXPORT int connect(const char* name, int timeout_ms, ExceptionSink* xsink = nullptr);
254 
256 
266  DLLEXPORT int connectINET(const char* host, int prt, ExceptionSink* xsink = nullptr);
267 
269 
283  DLLEXPORT int connectINET2(const char* name, const char* service, int family = Q_AF_UNSPEC, int sock_type = Q_SOCK_STREAM, int protocol = 0, int timeout_ms = -1, ExceptionSink* xsink = nullptr);
284 
286 
297  DLLEXPORT int connectINET(const char* host, int prt, int timeout_ms, ExceptionSink* xsink = nullptr);
298 
300 
309  DLLEXPORT int connectUNIX(const char* p, ExceptionSink* xsink = nullptr);
310 
312 
323  DLLEXPORT int connectUNIX(const char* p, int socktype, int protocol = 0, ExceptionSink* xsink = nullptr);
324 
326 
341  DLLEXPORT int connectSSL(const char* name, X509* cert, EVP_PKEY* pkey, ExceptionSink* xsink);
342 
344 
360  DLLEXPORT int connectSSL(const char* name, int timeout_ms, X509* cert, EVP_PKEY* pkey, ExceptionSink* xsink);
361 
363 
377  DLLEXPORT int connectINETSSL(const char* host, int prt, X509* cert, EVP_PKEY* pkey, ExceptionSink* xsink);
378 
380 
395  DLLEXPORT int connectINETSSL(const char* host, int prt, int timeout_ms, X509* cert, EVP_PKEY* pkey, ExceptionSink* xsink);
396 
398 
414  DLLEXPORT int connectINET2SSL(const char* name, const char* service, int family, int sock_type, int protocol, int timeout_ms, X509* cert, EVP_PKEY* pkey, ExceptionSink* xsink = nullptr);
415 
417 
430  DLLEXPORT int connectUNIXSSL(const char* p, X509* cert, EVP_PKEY* pkey, ExceptionSink* xsink);
431 
433 
448  DLLEXPORT int connectUNIXSSL(const char* p, int socktype, int protocol, X509* cert, EVP_PKEY* pkey, ExceptionSink* xsink);
449 
451 
457  DLLEXPORT int bind(const char* name, bool reuseaddr = false);
458 
460 
465  DLLEXPORT int bind(int prt, bool reuseaddr);
466 
468 
474  DLLEXPORT int bind(const char* iface, int prt, bool reuseaddr = false);
475 
477 
484  DLLEXPORT int bind(const struct sockaddr *addr, int addr_size);
485 
487 
495  DLLEXPORT int bind(int family, const struct sockaddr *addr, int addr_size, int socktype = Q_SOCK_STREAM,
496  int protocol = 0);
497 
499 
507  DLLEXPORT int bindUNIX(const char* name, ExceptionSink* xsink = nullptr);
508 
510 
520  DLLEXPORT int bindUNIX(const char* name, int socktype, int protocol = 0, ExceptionSink* xsink = nullptr);
521 
523 
536  DLLEXPORT int bindINET(const char* name, const char* service, bool reuseaddr = true, int family = Q_AF_UNSPEC,
537  int socktype = Q_SOCK_STREAM, int protocol = 0, ExceptionSink* xsink = nullptr);
538 
540  DLLEXPORT int getPort();
541 
543 
555  DLLEXPORT QoreSocket* accept(SocketSource* source, ExceptionSink* xsink);
556 
558 
573  DLLEXPORT QoreSocket* acceptSSL(SocketSource* source, X509* cert, EVP_PKEY* pkey, ExceptionSink* xsink);
574 
576 
588  DLLEXPORT int acceptAndReplace(SocketSource* source);
589 
591 
602  DLLEXPORT QoreSocket* accept(int timeout_ms, ExceptionSink* xsink);
603 
605 
617  DLLEXPORT QoreSocket* acceptSSL(int timeout_ms, X509* cert, EVP_PKEY* pkey, ExceptionSink* xsink);
618 
620 
631  DLLEXPORT int acceptAndReplace(int timeout_ms, ExceptionSink* xsink);
632 
634 
637  DLLEXPORT int listen();
638 
640 
646  DLLEXPORT int listen(int backlog);
647 
649 
655  DLLEXPORT int send(const char* buf, size_t size);
656 
658 
665  DLLEXPORT int send(const char* buf, size_t size, ExceptionSink* xsink);
666 
668 
676  DLLEXPORT int send(const char* buf, size_t size, int timeout_ms, ExceptionSink* xsink);
677 
679 
685  DLLEXPORT int send(const QoreString *msg, ExceptionSink* xsink);
686 
688 
695  DLLEXPORT int send(const QoreString *msg, int timeout_ms, ExceptionSink* xsink);
696 
698 
707  DLLEXPORT int send(const QoreStringNode& msg, int timeout_ms, ExceptionSink* xsink);
708 
710 
715  DLLEXPORT int send(const BinaryNode* msg);
716 
718 
724  DLLEXPORT int send(const BinaryNode* msg, ExceptionSink* xsink);
725 
727 
734  DLLEXPORT int send(const BinaryNode* msg, int timeout_ms, ExceptionSink* xsink);
735 
737 
743  DLLEXPORT int send(int fd, qore_offset_t size = -1);
744 
746 
756  DLLEXPORT int send(int fd, qore_offset_t size, int timeout_ms, ExceptionSink* xsink);
757 
759 
763  DLLEXPORT int sendi1(char i);
764 
766 
771  DLLEXPORT int sendi2(short i);
772 
774 
779  DLLEXPORT int sendi4(int i);
780 
782 
787  DLLEXPORT int sendi8(int64 i);
788 
790 
796  DLLEXPORT int sendi2LSB(short i);
797 
799 
805  DLLEXPORT int sendi4LSB(int i);
806 
808 
814  DLLEXPORT int sendi8LSB(int64 i);
815 
817 
825  DLLEXPORT int sendi1(char i, int timeout_ms, ExceptionSink* xsink);
826 
828 
837  DLLEXPORT int sendi2(short i, int timeout_ms, ExceptionSink* xsink);
838 
840 
849  DLLEXPORT int sendi4(int i, int timeout_ms, ExceptionSink* xsink);
850 
852 
861  DLLEXPORT int sendi8(int64 i, int timeout_ms, ExceptionSink* xsink);
862 
864 
874  DLLEXPORT int sendi2LSB(short i, int timeout_ms, ExceptionSink* xsink);
875 
877 
887  DLLEXPORT int sendi4LSB(int i, int timeout_ms, ExceptionSink* xsink);
888 
890 
900  DLLEXPORT int sendi8LSB(int64 i, int timeout_ms, ExceptionSink* xsink);
901 
903 
912  DLLEXPORT int recvi1(int timeout_ms, char* val);
913 
915 
925  DLLEXPORT int recvi2(int timeout_ms, short *val);
926 
928 
938  DLLEXPORT int recvi4(int timeout_ms, int* val);
939 
941 
951  DLLEXPORT int recvi8(int timeout_ms, int64 *val);
952 
954 
965  DLLEXPORT int recvi2LSB(int timeout_ms, short *val);
966 
968 
979  DLLEXPORT int recvi4LSB(int timeout_ms, int* val);
980 
982 
991  DLLEXPORT int recvi8LSB(int timeout_ms, int64 *val);
992 
994 
1002  DLLEXPORT int recvu1(int timeout_ms, unsigned char* val);
1003 
1005 
1015  DLLEXPORT int recvu2(int timeout_ms, unsigned short *val);
1016 
1018 
1028  DLLEXPORT int recvu4(int timeout_ms, unsigned int* val);
1029 
1031 
1043  DLLEXPORT int recvu2LSB(int timeout_ms, unsigned short *val);
1044 
1046 
1058  DLLEXPORT int recvu4LSB(int timeout_ms, unsigned int* val);
1059 
1061 
1071  DLLEXPORT int64 recvi1(int timeout_ms, char* val, ExceptionSink* xsink);
1072 
1074 
1085  DLLEXPORT int64 recvi2(int timeout_ms, short *val, ExceptionSink* xsink);
1086 
1088 
1100  DLLEXPORT int64 recvi4(int timeout_ms, int* val, ExceptionSink* xsink);
1101 
1103 
1114  DLLEXPORT int64 recvi8(int timeout_ms, int64 *val, ExceptionSink* xsink);
1115 
1117 
1130  DLLEXPORT int64 recvi2LSB(int timeout_ms, short *val, ExceptionSink* xsink);
1131 
1133 
1146  DLLEXPORT int64 recvi4LSB(int timeout_ms, int* val, ExceptionSink* xsink);
1147 
1149 
1160  DLLEXPORT int64 recvi8LSB(int timeout_ms, int64 *val, ExceptionSink* xsink);
1161 
1163 
1173  DLLEXPORT int64 recvu1(int timeout_ms, unsigned char* val, ExceptionSink* xsink);
1174 
1176 
1188  DLLEXPORT int64 recvu2(int timeout_ms, unsigned short *val, ExceptionSink* xsink);
1189 
1191 
1203  DLLEXPORT int64 recvu4(int timeout_ms, unsigned int* val, ExceptionSink* xsink);
1204 
1206 
1220  DLLEXPORT int64 recvu2LSB(int timeout_ms, unsigned short *val, ExceptionSink* xsink);
1221 
1223 
1237  DLLEXPORT int64 recvu4LSB(int timeout_ms, unsigned int* val, ExceptionSink* xsink);
1238 
1240 
1249  DLLEXPORT QoreStringNode* recv(qore_offset_t bufsize, int timeout_ms, int* prc);
1250 
1252 
1261  DLLEXPORT QoreStringNode* recv(qore_offset_t bufsize, int timeout_ms, ExceptionSink* xsink);
1262 
1264 
1271  DLLEXPORT BinaryNode* recvBinary(qore_offset_t bufsize, int timeout_ms, int* prc);
1272 
1274 
1281  DLLEXPORT BinaryNode* recvBinary(qore_offset_t bufsize, int timeout_ms, ExceptionSink* xsink);
1282 
1284 
1295  DLLEXPORT QoreStringNode* recv(int timeout_ms, int* prc);
1296 
1298 
1309  DLLEXPORT QoreStringNode* recv(int timeout_ms, ExceptionSink* xsink);
1310 
1312 
1322  DLLEXPORT BinaryNode* recvBinary(int timeout_ms, int* prc);
1323 
1325 
1335  DLLEXPORT BinaryNode* recvBinary(int timeout_ms, ExceptionSink* xsink);
1336 
1338 
1348  DLLEXPORT int recv(int fd, qore_offset_t size, int timeout_ms);
1349 
1351 
1364  DLLEXPORT int recv(int fd, qore_offset_t size, int timeout_ms, ExceptionSink* xsink);
1365 
1367 
1378  DLLEXPORT int sendHTTPMessage(const char* method, const char* path, const char* http_version, const QoreHashNode* headers, const void* data, size_t size, int source = QORE_SOURCE_SOCKET);
1379 
1381 
1393  DLLEXPORT int sendHTTPMessage(QoreHashNode* info, const char* method, const char* path, const char* http_version, const QoreHashNode* headers, const void* data, size_t size, int source = QORE_SOURCE_SOCKET);
1394 
1396 
1410  DLLEXPORT int sendHTTPMessage(ExceptionSink* xsink, QoreHashNode* info, const char* method, const char* path, const char* http_version, const QoreHashNode* headers, const void* data, size_t size, int source = QORE_SOURCE_SOCKET);
1411 
1413 
1428  DLLEXPORT int sendHTTPMessage(ExceptionSink* xsink, QoreHashNode* info, const char* method, const char* path, const char* http_version, const QoreHashNode* headers, const void* data, size_t size, int source, int timeout_ms);
1429 
1431 
1445  DLLEXPORT int sendHTTPMessageWithCallback(ExceptionSink* xsink, QoreHashNode* info, const char* method, const char* path, const char* http_version, const QoreHashNode* headers, const ResolvedCallReferenceNode& send_callback, int source, int timeout_ms);
1446 
1448 
1460  DLLEXPORT int sendHTTPResponse(int code, const char* desc, const char* http_version, const QoreHashNode* headers, const void* data, size_t size, int source = QORE_SOURCE_SOCKET);
1461 
1463 
1476  DLLEXPORT int sendHTTPResponse(ExceptionSink* xsink, int code, const char* desc, const char* http_version, const QoreHashNode* headers, const void* data, size_t size, int source = QORE_SOURCE_SOCKET);
1477 
1479 
1493  DLLEXPORT int sendHTTPResponse(ExceptionSink* xsink, int code, const char* desc, const char* http_version, const QoreHashNode* headers, const void* data, size_t size, int source, int timeout_ms);
1494 
1496 
1513  DLLEXPORT int sendHTTPResponse(ExceptionSink* xsink, QoreHashNode* info, int code, const char* desc,
1514  const char* http_version, const QoreHashNode* headers, const void* data, size_t size, int source,
1515  int timeout_ms);
1516 
1518 
1527  DLLEXPORT AbstractQoreNode* readHTTPHeader(int timeout_ms, int* prc, int source = QORE_SOURCE_SOCKET);
1528 
1530 
1540  DLLEXPORT AbstractQoreNode* readHTTPHeader(QoreHashNode* info, int timeout_ms, int* prc, int source = QORE_SOURCE_SOCKET);
1541 
1543 
1554  DLLEXPORT QoreHashNode* readHTTPHeader(ExceptionSink* xsink, QoreHashNode* info, int timeout_ms, int source = QORE_SOURCE_SOCKET);
1555 
1557 
1567  DLLEXPORT QoreStringNode* readHTTPHeaderString(ExceptionSink* xsink, int timeout_ms, int source = QORE_SOURCE_SOCKET);
1568 
1570 
1582  DLLEXPORT QoreHashNode* readHTTPChunkedBodyBinary(int timeout_ms, ExceptionSink* xsink, int source = QORE_SOURCE_SOCKET);
1583 
1585 
1597  DLLEXPORT QoreHashNode* readHTTPChunkedBody(int timeout_ms, ExceptionSink* xsink, int source = QORE_SOURCE_SOCKET);
1598 
1600  DLLEXPORT int setSendTimeout(int ms);
1601 
1603  DLLEXPORT int setRecvTimeout(int ms);
1604 
1606  DLLEXPORT int getSendTimeout() const;
1607 
1609  DLLEXPORT int getRecvTimeout() const;
1610 
1612 
1623  DLLEXPORT bool isDataAvailable(int timeout_ms = 0) const;
1624 
1626 
1640  DLLEXPORT bool isDataAvailable(ExceptionSink* xsink, int timeout_ms = 0) const;
1641 
1643 
1655  DLLEXPORT int asyncIoWait(int timeout_ms, bool read, bool write) const;
1656 
1658 
1662  DLLEXPORT int close();
1663 
1665 
1674  DLLEXPORT int shutdown();
1675 
1677 
1683  DLLEXPORT int shutdownSSL(ExceptionSink* xsink);
1684 
1686 
1688  DLLEXPORT int getSocket() const;
1689 
1691 
1693  DLLEXPORT const QoreEncoding *getEncoding() const;
1694 
1696 
1698  DLLEXPORT void setEncoding(const QoreEncoding *id);
1699 
1701 
1703  DLLEXPORT bool isOpen() const;
1704 
1706 
1708  DLLEXPORT const char* getSSLCipherName() const;
1709 
1711 
1713  DLLEXPORT const char* getSSLCipherVersion() const;
1714 
1716 
1718  DLLEXPORT bool isSecure() const;
1719 
1721  DLLEXPORT long verifyPeerCertificate() const;
1722 
1724 
1732  DLLEXPORT int upgradeClientToSSL(X509* cert, EVP_PKEY* pkey, ExceptionSink* xsink);
1733 
1735 
1744  DLLEXPORT int upgradeServerToSSL(X509* cert, EVP_PKEY* pkey, int timeout_ms, ExceptionSink* xsink);
1745 
1747 
1756  DLLEXPORT int upgradeClientToSSL(X509* cert, EVP_PKEY* pkey, int timeout_ms, ExceptionSink* xsink);
1757 
1759 
1767  DLLEXPORT int upgradeServerToSSL(X509* cert, EVP_PKEY* pkey, ExceptionSink* xsink);
1768 
1770 
1779  DLLEXPORT bool isWriteFinished(int timeout_ms = 0) const;
1780 
1782 
1792  DLLEXPORT bool isWriteFinished(ExceptionSink* xsink, int timeout_ms = 0) const;
1793 
1795 
1807  DLLEXPORT QoreHashNode* getPeerInfo(ExceptionSink* xsink) const;
1808 
1810 
1824  DLLEXPORT QoreHashNode* getPeerInfo(ExceptionSink* xsink, bool host_lookup) const;
1825 
1827 
1840  DLLEXPORT QoreHashNode* getSocketInfo(ExceptionSink* xsink) const;
1841 
1843 
1857  DLLEXPORT QoreHashNode* getSocketInfo(ExceptionSink* xsink, bool host_lookup) const;
1858 
1859  DLLEXPORT void clearWarningQueue(ExceptionSink* xsink);
1860  DLLEXPORT void setWarningQueue(ExceptionSink* xsink, int64 warning_ms, int64 warning_bs, Queue* wq, QoreValue arg, int64 min_ms = 1000);
1861  DLLEXPORT QoreHashNode* getUsageInfo() const;
1862  DLLEXPORT void clearStats();
1863 
1865  DLLEXPORT void cleanup(ExceptionSink* xsink);
1866 
1868  DLLEXPORT bool pendingHttpChunkedBody() const;
1869 
1871 
1877  DLLEXPORT void setSslVerifyMode(int mode);
1878 
1880 
1884  DLLEXPORT int getSslVerifyMode() const;
1885 
1887 
1891  DLLEXPORT void acceptAllCertificates(bool accept_all = true);
1892 
1894 
1898  DLLEXPORT bool getAcceptAllCertificates() const;
1899 
1901 
1909  DLLEXPORT bool captureRemoteCertificates(bool set);
1910 
1912 
1918  DLLEXPORT QoreObject* getRemoteCertificate() const;
1919 
1921 
1925  DLLEXPORT int64 getConnectionId() const;
1926 
1927  DLLLOCAL static void doException(int rc, const char* meth, int timeout_ms, ExceptionSink* xsink);
1928 
1930  DLLLOCAL void setEventQueue(ExceptionSink* xsink, Queue* q, QoreValue arg, bool with_data);
1931 
1933  DLLLOCAL Queue* getQueue();
1934 
1936  DLLLOCAL int64 getObjectIDForEvents() const;
1937 
1938  DLLLOCAL int setNoDelay(int nodelay);
1939  DLLLOCAL int getNoDelay() const;
1940 
1942  DLLLOCAL void setAccept(QoreObject* o);
1943 
1944 private:
1946  hashdecl qore_socket_private *priv;
1947 
1949  DLLLOCAL QoreSocket(int n_sock, int n_sfamily, int n_stype, int s_prot, const QoreEncoding* csid);
1950 
1951  DLLLOCAL static void convertHeaderToHash(QoreHashNode* h, char* p);
1952 
1953  DLLLOCAL QoreSocket(const QoreSocket&) = delete;
1954  DLLLOCAL QoreSocket& operator=(const QoreSocket&) = delete;
1955 };
1956 
1957 class QoreSocketTimeoutHelper {
1958 protected:
1959  class PrivateQoreSocketTimeoutHelper* priv;
1960 public:
1961  DLLEXPORT QoreSocketTimeoutHelper(QoreSocket& s, const char* op);
1962  DLLEXPORT ~QoreSocketTimeoutHelper();
1963 };
1964 
1965 class QoreSocketThroughputHelper {
1966 protected:
1967  class PrivateQoreSocketThroughputHelper* priv;
1968 public:
1969  DLLEXPORT QoreSocketThroughputHelper(QoreSocket& s, bool snd);
1970  DLLEXPORT ~QoreSocketThroughputHelper();
1971  DLLEXPORT void finalize(int64 bytes);
1972 };
1973 
1974 #endif // _QORE_QORESOCKET_H
The base class for all value and parse types in Qore expression trees.
Definition: AbstractQoreNode.h:57
holds arbitrary binary data
Definition: BinaryNode.h:41
container for holding Qore-language exception information and also for registering a "thread_exit" ca...
Definition: ExceptionSink.h:48
defines string encoding functions in Qore
Definition: QoreEncoding.h:83
provides thread-safe access to FTP servers through Qore data structures
Definition: QoreFtpClient.h:71
This is the hash or associative list container type in Qore, dynamically allocated only,...
Definition: QoreHashNode.h:50
the implementation of Qore's object data type, reference counted, dynamically-allocated only
Definition: QoreObject.h:60
provides access to sockets using Qore data structures
Definition: QoreSocket.h:127
DLLEXPORT bool captureRemoteCertificates(bool set)
sets the capture SSL certificate flag
DLLEXPORT int getRecvTimeout() const
get recv timeout in milliseconds
DLLEXPORT int recvi2LSB(int timeout_ms, short *val)
reads a 2-byte signed integer in LSB (Most Significant Byte first, little endian) format from the soc...
DLLEXPORT int send(const char *buf, size_t size)
sends binary data on a connected socket
DLLEXPORT int recvi8LSB(int timeout_ms, int64 *val)
reads an 8-byte signed integer in LSB (Most Significant Byte first, little endian) format from the so...
DLLEXPORT void setSslVerifyMode(int mode)
sets the SSL verification mode
DLLEXPORT QoreSocket * acceptSSL(SocketSource *source, X509 *cert, EVP_PKEY *pkey, ExceptionSink *xsink)
accepts a new connection on a listening socket, negotiates an SSL connection, and returns a new QoreS...
DLLEXPORT AbstractPollState * startSslConnect(ExceptionSink *xsink, X509 *cert=nullptr, EVP_PKEY *pkey=nullptr)
Starts a non-blocking upgrade to an SSL connection on a connected client connection.
DLLEXPORT void setEncoding(const QoreEncoding *id)
sets the character encoding for strings sent and received with this socket
DLLEXPORT int setSendTimeout(int ms)
set send timeout in milliseconds
DLLEXPORT int upgradeClientToSSL(X509 *cert, EVP_PKEY *pkey, ExceptionSink *xsink)
negotiates an SSL connection from the client side
DLLEXPORT int connectUNIXSSL(const char *p, X509 *cert, EVP_PKEY *pkey, ExceptionSink *xsink)
connects to a UNIX domain socket, negotiates an SSL connection, and returns a status code,...
DLLEXPORT bool pendingHttpChunkedBody() const
returns true if a HTTP header was read indicating chunked transfer encoding, but no chunked body has ...
DLLEXPORT bool getAcceptAllCertificates() const
returns the current value of the "accept all certificates" flag
DLLEXPORT int connectINET(const char *host, int prt, ExceptionSink *xsink=nullptr)
connects to an INET socket by hostname and port number and returns a status code, Qore-language excep...
DLLEXPORT int close()
closes the socket
DLLEXPORT QoreStringNode * readHTTPHeaderString(ExceptionSink *xsink, int timeout_ms, int source=QORE_SOURCE_SOCKET)
read a HTTP header, caller owns QoreStringNode reference count returned
DLLEXPORT int connectINETSSL(const char *host, int prt, X509 *cert, EVP_PKEY *pkey, ExceptionSink *xsink)
connects to an INET socket by hostname and port number, negotiates an SSL connection,...
DLLEXPORT int recvu4(int timeout_ms, unsigned int *val)
reads a 4-byte unsigned integer in MSB (Most Significant Byte first, big endian, network) format from...
DLLEXPORT int upgradeServerToSSL(X509 *cert, EVP_PKEY *pkey, int timeout_ms, ExceptionSink *xsink)
negotiates an SSL connection from the client side
DLLEXPORT long verifyPeerCertificate() const
returns the peer certificate verification code if an SSL connection is in progress
DLLLOCAL Queue * getQueue()
returns the event queue (not part of the library's public API)
DLLEXPORT QoreSocket()
creates an empty, unconnected socket
DLLEXPORT BinaryNode * recvBinary(qore_offset_t bufsize, int timeout_ms, int *prc)
receive a certain number of bytes with a timeout value and return a BinaryNode, caller owns the refer...
DLLEXPORT AbstractPollState * startRecv(ExceptionSink *xsink, size_t size)
Starts a non-blocking receive operation on a connected socket.
DLLEXPORT int asyncIoWait(int timeout_ms, bool read, bool write) const
returns 1 if the event was satisfied in the timeout period, 0 if not (= timeout), or -1 in case of an...
DLLEXPORT int sendHTTPMessageWithCallback(ExceptionSink *xsink, QoreHashNode *info, const char *method, const char *path, const char *http_version, const QoreHashNode *headers, const ResolvedCallReferenceNode &send_callback, int source, int timeout_ms)
send an HTTP request message on the socket with a timeout value with a chunked message body using a c...
DLLEXPORT int getPort()
returns the TCP port number, also assigns the interal port number if it must be discovered
DLLEXPORT int acceptAndReplace(SocketSource *source)
accepts a new connection on a listening socket and replaces the current socket with the new connectio...
DLLEXPORT int connectSSL(const char *name, X509 *cert, EVP_PKEY *pkey, ExceptionSink *xsink)
connects to a socket, negotiates an SSL connection, and returns a status code, Qore-language exceptio...
DLLEXPORT bool isSecure() const
returns true if an SSL connection is active
DLLLOCAL int64 getObjectIDForEvents() const
returns a unique ID for the socket to be used in event messages
DLLEXPORT int sendi2LSB(short i)
sends a 2-byte (16bit) binary integer in LSB (Least Significant Byte first, little endian) format thr...
DLLEXPORT int connect(const char *name, ExceptionSink *xsink=nullptr)
connects to a socket and returns a status code, Qore-language exceptions are raised in the case of an...
DLLEXPORT AbstractPollState * startConnect(ExceptionSink *xsink, const char *name)
Starts a non-blocking connection to a socket and returns a status code.
DLLEXPORT void acceptAllCertificates(bool accept_all=true)
with peer verification enabled, all certificates are accepted regardless of the validity of the Certi...
DLLEXPORT int sendi1(char i)
sends a 1-byte binary integer data to a connected socket
DLLEXPORT bool isDataAvailable(int timeout_ms=0) const
returns true if data is available on the socket in the timeout period in milliseconds
DLLEXPORT QoreHashNode * readHTTPChunkedBody(int timeout_ms, ExceptionSink *xsink, int source=QORE_SOURCE_SOCKET)
receive a string message in HTTP chunked transfer encoding, caller owns QoreHashNode reference count ...
DLLLOCAL void setEventQueue(ExceptionSink *xsink, Queue *q, QoreValue arg, bool with_data)
sets the event queue (not part of the library's pubilc API), must be already referenced before call
DLLEXPORT AbstractPollState * startRecvUntilBytes(ExceptionSink *xsink, const char *pattern, size_t size)
Starts a non-blocking receive operation on a connected socket.
DLLEXPORT bool isWriteFinished(int timeout_ms=0) const
returns true if all write data has been written within the timeout period in milliseconds
DLLEXPORT QoreHashNode * getPeerInfo(ExceptionSink *xsink) const
returns peer information for a connected socket
DLLEXPORT int getSslVerifyMode() const
returns the SSL verification mode
DLLEXPORT int shutdownSSL(ExceptionSink *xsink)
shuts down an active SSL connection
DLLEXPORT int recvu2LSB(int timeout_ms, unsigned short *val)
reads a 2-byte unsigned integer in LSB (Most Significant Byte first, little endian) format from the s...
DLLEXPORT QoreHashNode * readHTTPChunkedBodyBinary(int timeout_ms, ExceptionSink *xsink, int source=QORE_SOURCE_SOCKET)
receive a binary message in HTTP chunked transfer encoding, caller owns QoreHashNode reference count ...
DLLEXPORT void cleanup(ExceptionSink *xsink)
posts deleted message and removes any event queue
DLLEXPORT int bind(const char *name, bool reuseaddr=false)
binds to a UNIX domain socket or INET interface:port using TCP and returns a status code
DLLEXPORT int recvi1(int timeout_ms, char *val)
reads a 1-byte signed integer from the socket with a timeout value and returns the value read as an o...
DLLEXPORT int sendi8(int64 i)
sends an 8-byte (64bit) binary integer in MSB (Most Significant Byte first, big endian,...
DLLEXPORT int getSocket() const
returns the file descriptor associated with this socket
DLLEXPORT int connectUNIX(const char *p, ExceptionSink *xsink=nullptr)
connects to a UNIX domain socket and returns a status code, Qore-language exceptions are raised in th...
DLLEXPORT QoreSocket * accept(SocketSource *source, ExceptionSink *xsink)
accepts a new connection on a listening socket and returns a new QoreSocket object for the new connec...
DLLLOCAL void setAccept(QoreObject *o)
sets backwards-compatible members on accept in a new object - will be removed in a future version of ...
DLLEXPORT const QoreEncoding * getEncoding() const
returns the character encoding associated with this socket
DLLEXPORT const char * getSSLCipherName() const
returns the name of the SSL Cipher for the currently-connected control connection,...
DLLEXPORT QoreHashNode * getSocketInfo(ExceptionSink *xsink) const
returns information for the current socket; the socket must be open
DLLEXPORT int recvi4LSB(int timeout_ms, int *val)
reads a 4-byte signed integer in LSB (Most Significant Byte first, little endian) format from the soc...
DLLEXPORT int recvu2(int timeout_ms, unsigned short *val)
reads a 2-byte unsigned integer in MSB (Most Significant Byte first, big endian, network) format from...
DLLEXPORT bool isOpen() const
returns true if the socket is open
DLLEXPORT int connectINET2(const char *name, const char *service, int family=Q_AF_UNSPEC, int sock_type=Q_SOCK_STREAM, int protocol=0, int timeout_ms=-1, ExceptionSink *xsink=nullptr)
connects to an INET or INET6 socket by hostname and port number or service name and returns a status ...
DLLEXPORT int sendi4(int i)
sends a 4-byte (32bit) binary integer in MSB (Most Significant Byte first, big endian,...
DLLEXPORT int sendHTTPMessage(const char *method, const char *path, const char *http_version, const QoreHashNode *headers, const void *data, size_t size, int source=QORE_SOURCE_SOCKET)
send an HTTP request message on the socket
DLLEXPORT AbstractPollState * startSend(ExceptionSink *xsink, const char *data, size_t size)
Starts a non-blocking send operation on a connected socket.
DLLEXPORT int recvi8(int timeout_ms, int64 *val)
reads an 8-byte signed integer in MSB (Most Significant Byte first, big endian, network) format from ...
DLLEXPORT const char * getSSLCipherVersion() const
returns the version string of the SSL Cipher for the currently-connected control connection,...
DLLEXPORT int recvu4LSB(int timeout_ms, unsigned int *val)
reads a 4-byte unsigned integer in LSB (Most Significant Byte first, little endian) format from the s...
DLLEXPORT int recvu1(int timeout_ms, unsigned char *val)
reads a 1-byte unsigned integer from the socket with a timeout value and returns the value read as an...
DLLEXPORT int listen()
sets an open socket to the listening state
DLLEXPORT int recvi4(int timeout_ms, int *val)
reads a 4-byte signed integer in MSB (Most Significant Byte first, big endian, network) format from t...
DLLEXPORT int bindINET(const char *name, const char *service, bool reuseaddr=true, int family=Q_AF_UNSPEC, int socktype=Q_SOCK_STREAM, int protocol=0, ExceptionSink *xsink=nullptr)
binds an INET or INET6 TCP socket to a specific socket address
DLLEXPORT int setRecvTimeout(int ms)
set recv timeout in milliseconds
DLLEXPORT AbstractQoreNode * readHTTPHeader(int timeout_ms, int *prc, int source=QORE_SOURCE_SOCKET)
read and parse HTTP header, caller owns AbstractQoreNode reference count returned
DLLEXPORT int getSendTimeout() const
get send timeout in milliseconds
DLLEXPORT int sendHTTPResponse(int code, const char *desc, const char *http_version, const QoreHashNode *headers, const void *data, size_t size, int source=QORE_SOURCE_SOCKET)
send an HTTP response message on the socket
DLLEXPORT int connectINET2SSL(const char *name, const char *service, int family, int sock_type, int protocol, int timeout_ms, X509 *cert, EVP_PKEY *pkey, ExceptionSink *xsink=nullptr)
connects to an INET or INET6 socket by hostname and port number or service name and returns a status ...
DLLEXPORT QoreStringNode * recv(qore_offset_t bufsize, int timeout_ms, int *prc)
receive a certain number of bytes with a timeout value and return a QoreStringNode,...
DLLEXPORT ~QoreSocket()
disconnects if necessary, frees all data, and destroys the socket
DLLEXPORT QoreObject * getRemoteCertificate() const
returns a remote certificate if available
DLLEXPORT int sendi2(short i)
sends a 2-byte (16bit) binary integer in MSB (Most Significant Byte first, big endian,...
DLLEXPORT int64 getConnectionId() const
returns a connection ID to help identifying when new connections are made
DLLEXPORT int bindUNIX(const char *name, ExceptionSink *xsink=nullptr)
binds to a UNIX domain socket and returns a status code
DLLEXPORT int sendi4LSB(int i)
sends a 4-byte (32bit) binary integer in LSB (Least Significant Byte first, little endian) format thr...
DLLEXPORT int shutdown()
calls shutdown on the socket
DLLEXPORT int sendi8LSB(int64 i)
sends an 8-byte (64bit) binary integer in LSB (Least Significant Byte first, little endian) format th...
DLLEXPORT int recvi2(int timeout_ms, short *val)
reads a 2-byte signed integer in MSB (Most Significant Byte first, big endian, network) format from t...
Qore's string type supported by the QoreEncoding class.
Definition: QoreString.h:93
Qore's string value type, reference counted, dynamically-allocated only.
Definition: QoreStringNode.h:50
base class for resolved call references
Definition: CallReferenceNode.h:109
a helper class for getting socket origination information
Definition: QoreSocket.h:74
DLLEXPORT QoreStringNode * takeHostName()
returns the hostname string field and leaves the object's hostname field empty; the caller owns the Q...
DLLEXPORT const char * getHostName() const
returns the hostname string as a C string
DLLEXPORT ~SocketSource()
destroys the object and frees all memory
DLLEXPORT const char * getAddress() const
returns the host address string as a C string
DLLEXPORT SocketSource()
creates an empty object
DLLEXPORT QoreStringNode * takeAddress()
returns the host address string field and leaves the object's host address field empty; the caller ow...
#define Q_AF_UNSPEC
cross-platform define for AF_UNSPEC
Definition: common.h:58
#define Q_SOCK_STREAM
platform-independent define for SOCK_STREAM
Definition: common.h:67
intptr_t qore_offset_t
used for offsets that could be negative
Definition: common.h:76
long long int64
64bit integer type, cannot use int64_t here since it breaks the API on some 64-bit systems due to equ...
Definition: common.h:260
The main value class in Qore, designed to be passed by value.
Definition: QoreValue.h:275