| Qore Programming Language - C/C++ Library 1.0.8

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 - 2019 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
44 #include <cctype>
45 #include <cstdlib>
46 #include <cstring>
47 #include <strings.h>
48 #include <sys/types.h>
49 #include <unistd.h>
50
51 #include <openssl/ssl.h>
52 #include <openssl/err.h>
53
54 #define QSE_MISC_ERR 0
55 #define QSE_RECV_ERR -1
56 #define QSE_NOT_OPEN -2
57 #define QSE_TIMEOUT -3
58 #define QSE_SSL_ERR -4
59 #define QSE_IN_OP -5
60 #define QSE_IN_OP_THREAD -6
61
62 // forward reference
63 class Queue;
64
66
73 class SocketSource {
74 friend struct qore_socket_private;
75
76 private:
77 struct qore_socketsource_private *priv; // private implementation
78
80 DLLLOCAL SocketSource(const SocketSource&);
81
83 DLLLOCAL SocketSource& operator=(const SocketSource&);
84
85 public:
87 DLLEXPORT SocketSource();
88
90 DLLEXPORT ~SocketSource();
91
93
95 DLLEXPORT QoreStringNode* takeAddress();
96
98
100 DLLEXPORT QoreStringNode* takeHostName();
101
103
105 DLLEXPORT const char* getAddress() const;
106
108
110 DLLEXPORT const char* getHostName() const;
111
112 DLLLOCAL void setAll(QoreObject* o, ExceptionSink* xsink);
113 };
114
116
126 class QoreSocket {
127 friend struct qore_socket_private;
128 friend struct qore_httpclient_priv;
129 friend class QoreSocketObject;
130 friend class QoreFtpClient;
131
132 private:
134 struct qore_socket_private *priv;
135
137 DLLLOCAL QoreSocket(int n_sock, int n_sfamily, int n_stype, int s_prot, const QoreEncoding *csid);
138
139 DLLLOCAL static void convertHeaderToHash(QoreHashNode* h, char* p);
140
142 DLLLOCAL QoreSocket(const QoreSocket&);
143
145 DLLLOCAL QoreSocket& operator=(const QoreSocket&);
146
147 public:
149 DLLEXPORT QoreSocket();
150
152 DLLEXPORT ~QoreSocket();
153
155
166 DLLEXPORT int connect(const char* name, ExceptionSink* xsink = 0);
167
169
181 DLLEXPORT int connect(const char* name, int timeout_ms, ExceptionSink* xsink = 0);
182
184
194 DLLEXPORT int connectINET(const char* host, int prt, ExceptionSink* xsink = 0);
195
197
211 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 = 0);
212
214
225 DLLEXPORT int connectINET(const char* host, int prt, int timeout_ms, ExceptionSink* xsink = 0);
226
228
237 DLLEXPORT int connectUNIX(const char* p, ExceptionSink* xsink = 0);
238
240
251 DLLEXPORT int connectUNIX(const char* p, int socktype, int protocol = 0, ExceptionSink* xsink = 0);
252
254
269 DLLEXPORT int connectSSL(const char* name, X509* cert, EVP_PKEY* pkey, ExceptionSink* xsink);
270
272
288 DLLEXPORT int connectSSL(const char* name, int timeout_ms, X509* cert, EVP_PKEY* pkey, ExceptionSink* xsink);
289
291
305 DLLEXPORT int connectINETSSL(const char* host, int prt, X509* cert, EVP_PKEY* pkey, ExceptionSink* xsink);
306
308
323 DLLEXPORT int connectINETSSL(const char* host, int prt, int timeout_ms, X509* cert, EVP_PKEY* pkey, ExceptionSink* xsink);
324
326
342 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 = 0);
343
345
358 DLLEXPORT int connectUNIXSSL(const char* p, X509* cert, EVP_PKEY* pkey, ExceptionSink* xsink);
359
361
376 DLLEXPORT int connectUNIXSSL(const char* p, int socktype, int protocol, X509* cert, EVP_PKEY* pkey, ExceptionSink* xsink);
377
379
385 DLLEXPORT int bind(const char* name, bool reuseaddr = false);
386
388
393 DLLEXPORT int bind(int prt, bool reuseaddr);
394
396
402 DLLEXPORT int bind(const char* iface, int prt, bool reuseaddr = false);
403
405
412 DLLEXPORT int bind(const struct sockaddr *addr, int addr_size);
413
415
423 DLLEXPORT int bind(int family, const struct sockaddr *addr, int addr_size, int socktype = Q_SOCK_STREAM, int protocol = 0);
424
426
434 DLLEXPORT int bindUNIX(const char* name, ExceptionSink* xsink = 0);
435
437
447 DLLEXPORT int bindUNIX(const char* name, int socktype, int protocol = 0, ExceptionSink* xsink = 0);
448
450
462 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 = 0);
463
465 DLLEXPORT int getPort();
466
468
480 DLLEXPORT QoreSocket* accept(SocketSource* source, ExceptionSink* xsink);
481
483
498 DLLEXPORT QoreSocket* acceptSSL(SocketSource* source, X509* cert, EVP_PKEY* pkey, ExceptionSink* xsink);
499
501
513 DLLEXPORT int acceptAndReplace(SocketSource* source);
514
516
527 DLLEXPORT QoreSocket* accept(int timeout_ms, ExceptionSink* xsink);
528
530
542 DLLEXPORT QoreSocket* acceptSSL(int timeout_ms, X509* cert, EVP_PKEY* pkey, ExceptionSink* xsink);
543
545
556 DLLEXPORT int acceptAndReplace(int timeout_ms, ExceptionSink* xsink);
557
559
562 DLLEXPORT int listen();
563
565
571 DLLEXPORT int listen(int backlog);
572
574
580 DLLEXPORT int send(const char* buf, size_t size);
581
583
590 DLLEXPORT int send(const char* buf, size_t size, ExceptionSink* xsink);
591
593
601 DLLEXPORT int send(const char* buf, size_t size, int timeout_ms, ExceptionSink* xsink);
602
604
610 DLLEXPORT int send(const QoreString *msg, ExceptionSink* xsink);
611
613
620 DLLEXPORT int send(const QoreString *msg, int timeout_ms, ExceptionSink* xsink);
621
623
632 DLLEXPORT int send(const QoreStringNode& msg, int timeout_ms, ExceptionSink* xsink);
633
635
640 DLLEXPORT int send(const BinaryNode* msg);
641
643
649 DLLEXPORT int send(const BinaryNode* msg, ExceptionSink* xsink);
650
652
659 DLLEXPORT int send(const BinaryNode* msg, int timeout_ms, ExceptionSink* xsink);
660
662
668 DLLEXPORT int send(int fd, qore_offset_t size = -1);
669
671
681 DLLEXPORT int send(int fd, qore_offset_t size, int timeout_ms, ExceptionSink* xsink);
682
684
688 DLLEXPORT int sendi1(char i);
689
691
696 DLLEXPORT int sendi2(short i);
697
699
704 DLLEXPORT int sendi4(int i);
705
707
712 DLLEXPORT int sendi8(int64 i);
713
715
721 DLLEXPORT int sendi2LSB(short i);
722
724
730 DLLEXPORT int sendi4LSB(int i);
731
733
739 DLLEXPORT int sendi8LSB(int64 i);
740
742
750 DLLEXPORT int sendi1(char i, int timeout_ms, ExceptionSink* xsink);
751
753
762 DLLEXPORT int sendi2(short i, int timeout_ms, ExceptionSink* xsink);
763
765
774 DLLEXPORT int sendi4(int i, int timeout_ms, ExceptionSink* xsink);
775
777
786 DLLEXPORT int sendi8(int64 i, int timeout_ms, ExceptionSink* xsink);
787
789
799 DLLEXPORT int sendi2LSB(short i, int timeout_ms, ExceptionSink* xsink);
800
802
812 DLLEXPORT int sendi4LSB(int i, int timeout_ms, ExceptionSink* xsink);
813
815
825 DLLEXPORT int sendi8LSB(int64 i, int timeout_ms, ExceptionSink* xsink);
826
828
837 DLLEXPORT int recvi1(int timeout_ms, char* val);
838
840
848 DLLEXPORT int recvi2(int timeout_ms, short *val);
849
851
859 DLLEXPORT int recvi4(int timeout_ms, int* val);
860
862
870 DLLEXPORT int recvi8(int timeout_ms, int64 *val);
871
873
882 DLLEXPORT int recvi2LSB(int timeout_ms, short *val);
883
885
894 DLLEXPORT int recvi4LSB(int timeout_ms, int* val);
895
897
904 DLLEXPORT int recvi8LSB(int timeout_ms, int64 *val);
905
907
913 DLLEXPORT int recvu1(int timeout_ms, unsigned char* val);
914
916
924 DLLEXPORT int recvu2(int timeout_ms, unsigned short *val);
925
927
935 DLLEXPORT int recvu4(int timeout_ms, unsigned int* val);
936
938
947 DLLEXPORT int recvu2LSB(int timeout_ms, unsigned short *val);
948
950
959 DLLEXPORT int recvu4LSB(int timeout_ms, unsigned int* val);
960
962
972 DLLEXPORT int64 recvi1(int timeout_ms, char* val, ExceptionSink* xsink);
973
975
986 DLLEXPORT int64 recvi2(int timeout_ms, short *val, ExceptionSink* xsink);
987
989
1001 DLLEXPORT int64 recvi4(int timeout_ms, int* val, ExceptionSink* xsink);
1002
1004
1015 DLLEXPORT int64 recvi8(int timeout_ms, int64 *val, ExceptionSink* xsink);
1016
1018
1030 DLLEXPORT int64 recvi2LSB(int timeout_ms, short *val, ExceptionSink* xsink);
1031
1033
1045 DLLEXPORT int64 recvi4LSB(int timeout_ms, int* val, ExceptionSink* xsink);
1046
1048
1059 DLLEXPORT int64 recvi8LSB(int timeout_ms, int64 *val, ExceptionSink* xsink);
1060
1062
1072 DLLEXPORT int64 recvu1(int timeout_ms, unsigned char* val, ExceptionSink* xsink);
1073
1075
1087 DLLEXPORT int64 recvu2(int timeout_ms, unsigned short *val, ExceptionSink* xsink);
1088
1090
1102 DLLEXPORT int64 recvu4(int timeout_ms, unsigned int* val, ExceptionSink* xsink);
1103
1105
1119 DLLEXPORT int64 recvu2LSB(int timeout_ms, unsigned short *val, ExceptionSink* xsink);
1120
1122
1136 DLLEXPORT int64 recvu4LSB(int timeout_ms, unsigned int* val, ExceptionSink* xsink);
1137
1139
1146 DLLEXPORT QoreStringNode* recv(qore_offset_t bufsize, int timeout_ms, int* prc);
1147
1149
1156 DLLEXPORT QoreStringNode* recv(qore_offset_t bufsize, int timeout_ms, ExceptionSink* xsink);
1157
1159
1165 DLLEXPORT BinaryNode* recvBinary(qore_offset_t bufsize, int timeout_ms, int* prc);
1166
1168
1174 DLLEXPORT BinaryNode* recvBinary(qore_offset_t bufsize, int timeout_ms, ExceptionSink* xsink);
1175
1177
1186 DLLEXPORT QoreStringNode* recv(int timeout_ms, int* prc);
1187
1189
1198 DLLEXPORT QoreStringNode* recv(int timeout_ms, ExceptionSink* xsink);
1199
1201
1209 DLLEXPORT BinaryNode* recvBinary(int timeout_ms, int* prc);
1210
1212
1220 DLLEXPORT BinaryNode* recvBinary(int timeout_ms, ExceptionSink* xsink);
1221
1223
1233 DLLEXPORT int recv(int fd, qore_offset_t size, int timeout_ms);
1234
1236
1249 DLLEXPORT int recv(int fd, qore_offset_t size, int timeout_ms, ExceptionSink* xsink);
1250
1252
1262 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);
1263
1265
1276 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);
1277
1279
1293 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);
1294
1296
1311 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);
1312
1314
1328 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);
1329
1331
1343 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);
1344
1346
1359 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);
1360
1362
1376 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);
1377
1379
1396 DLLEXPORT int sendHTTPResponse(ExceptionSink* xsink, QoreHashNode* info, int code, const char* desc,
1397 const char* http_version, const QoreHashNode* headers, const void* data, size_t size, int source,
1398 int timeout_ms);
1399
1401
1408 DLLEXPORT AbstractQoreNode* readHTTPHeader(int timeout_ms, int* prc, int source = QORE_SOURCE_SOCKET);
1409
1411
1419 DLLEXPORT AbstractQoreNode* readHTTPHeader(QoreHashNode* info, int timeout_ms, int* prc, int source = QORE_SOURCE_SOCKET);
1420
1422
1433 DLLEXPORT QoreHashNode* readHTTPHeader(ExceptionSink* xsink, QoreHashNode* info, int timeout_ms, int source = QORE_SOURCE_SOCKET);
1434
1436
1446 DLLEXPORT QoreStringNode* readHTTPHeaderString(ExceptionSink* xsink, int timeout_ms, int source = QORE_SOURCE_SOCKET);
1447
1449
1458 DLLEXPORT QoreHashNode* readHTTPChunkedBodyBinary(int timeout_ms, ExceptionSink* xsink, int source = QORE_SOURCE_SOCKET);
1459
1461
1472 DLLEXPORT QoreHashNode* readHTTPChunkedBody(int timeout_ms, ExceptionSink* xsink, int source = QORE_SOURCE_SOCKET);
1473
1475 DLLEXPORT int setSendTimeout(int ms);
1476
1478 DLLEXPORT int setRecvTimeout(int ms);
1479
1481 DLLEXPORT int getSendTimeout() const;
1482
1484 DLLEXPORT int getRecvTimeout() const;
1485
1487
1498 DLLEXPORT bool isDataAvailable(int timeout_ms = 0) const;
1499
1501
1515 DLLEXPORT bool isDataAvailable(ExceptionSink* xsink, int timeout_ms = 0) const;
1516
1518
1530 DLLEXPORT int asyncIoWait(int timeout_ms, bool read, bool write) const;
1531
1533
1537 DLLEXPORT int close();
1538
1540
1546 DLLEXPORT int shutdown();
1547
1549
1553 DLLEXPORT int shutdownSSL(ExceptionSink* xsink);
1554
1556
1558 DLLEXPORT int getSocket() const;
1559
1561
1563 DLLEXPORT const QoreEncoding *getEncoding() const;
1564
1566
1568 DLLEXPORT void setEncoding(const QoreEncoding *id);
1569
1571
1573 DLLEXPORT bool isOpen() const;
1574
1576
1578 DLLEXPORT const char* getSSLCipherName() const;
1579
1581
1583 DLLEXPORT const char* getSSLCipherVersion() const;
1584
1586
1588 DLLEXPORT bool isSecure() const;
1589
1591 DLLEXPORT long verifyPeerCertificate() const;
1592
1594
1602 DLLEXPORT int upgradeClientToSSL(X509* cert, EVP_PKEY* pkey, ExceptionSink* xsink);
1603
1605
1614 DLLEXPORT int upgradeServerToSSL(X509* cert, EVP_PKEY* pkey, int timeout_ms, ExceptionSink* xsink);
1615
1617
1626 DLLEXPORT int upgradeClientToSSL(X509* cert, EVP_PKEY* pkey, int timeout_ms, ExceptionSink* xsink);
1627
1629
1637 DLLEXPORT int upgradeServerToSSL(X509* cert, EVP_PKEY* pkey, ExceptionSink* xsink);
1638
1640
1649 DLLEXPORT bool isWriteFinished(int timeout_ms = 0) const;
1650
1652
1661 DLLEXPORT bool isWriteFinished(ExceptionSink* xsink, int timeout_ms = 0) const;
1662
1664
1675 DLLEXPORT QoreHashNode* getPeerInfo(ExceptionSink* xsink) const;
1676
1678
1691 DLLEXPORT QoreHashNode* getPeerInfo(ExceptionSink* xsink, bool host_lookup) const;
1692
1694
1706 DLLEXPORT QoreHashNode* getSocketInfo(ExceptionSink* xsink) const;
1707
1709
1722 DLLEXPORT QoreHashNode* getSocketInfo(ExceptionSink* xsink, bool host_lookup) const;
1723
1724 DLLEXPORT void clearWarningQueue(ExceptionSink* xsink);
1725 DLLEXPORT void setWarningQueue(ExceptionSink* xsink, int64 warning_ms, int64 warning_bs, Queue* wq, QoreValue arg, int64 min_ms = 1000);
1726 DLLEXPORT QoreHashNode* getUsageInfo() const;
1727 DLLEXPORT void clearStats();
1728
1730 DLLEXPORT void cleanup(ExceptionSink* xsink);
1731
1733 DLLEXPORT bool pendingHttpChunkedBody() const;
1734
1736
1742 DLLEXPORT void setSslVerifyMode(int mode);
1743
1745
1749 DLLEXPORT int getSslVerifyMode() const;
1750
1752
1756 DLLEXPORT void acceptAllCertificates(bool accept_all = true);
1757
1759
1763 DLLEXPORT bool getAcceptAllCertificates() const;
1764
1766
1774 DLLEXPORT bool captureRemoteCertificates(bool set);
1775
1777
1783 DLLEXPORT QoreObject* getRemoteCertificate() const;
1784
1786
1790 DLLEXPORT int64 getConnectionId() const;
1791
1792 DLLLOCAL static void doException(int rc, const char* meth, int timeout_ms, ExceptionSink* xsink);
1793
1795 DLLLOCAL void setEventQueue(ExceptionSink* xsink, Queue* q, QoreValue arg, bool with_data);
1796
1798 DLLLOCAL Queue* getQueue();
1799
1801 DLLLOCAL int64 getObjectIDForEvents() const;
1802
1803 DLLLOCAL int setNoDelay(int nodelay);
1804 DLLLOCAL int getNoDelay() const;
1805
1807 DLLLOCAL void setAccept(QoreObject* o);
1808 };
1809
1810 class QoreSocketTimeoutHelper {
1811 protected:
1812 class PrivateQoreSocketTimeoutHelper* priv;
1813 public:
1814 DLLEXPORT QoreSocketTimeoutHelper(QoreSocket& s, const char* op);
1815 DLLEXPORT ~QoreSocketTimeoutHelper();
1816 };
1817
1818 class QoreSocketThroughputHelper {
1819 protected:
1820 class PrivateQoreSocketThroughputHelper* priv;
1821 public:
1822 DLLEXPORT QoreSocketThroughputHelper(QoreSocket& s, bool snd);
1823 DLLEXPORT ~QoreSocketThroughputHelper();
1824 DLLEXPORT void finalize(int64 bytes);
1825 };
1826
1827 #endif // _QORE_QORESOCKET_H
Q_SOCK_STREAM
#define Q_SOCK_STREAM
platform-independent define for SOCK_STREAM
Definition: common.h:67
QoreSocket::readHTTPHeaderString
DLLEXPORT QoreStringNode * readHTTPHeaderString(ExceptionSink *xsink, int timeout_ms, int source=QORE_SOURCE_SOCKET)
read a HTTP header, caller owns QoreStringNode reference count returned
QoreSocket::sendHTTPResponse
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
SocketSource::SocketSource
DLLEXPORT SocketSource()
creates an empty object
QoreEncoding
defines string encoding functions in Qore
Definition: QoreEncoding.h:83
QoreSocket::sendHTTPMessage
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
QoreSocket::asyncIoWait
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...
SocketSource
a helper class for getting socket origination information
Definition: QoreSocket.h:73
QoreSocket::getObjectIDForEvents
DLLLOCAL int64 getObjectIDForEvents() const
returns a unique ID for the socket to be used in event messages
QoreSocket::acceptAndReplace
DLLEXPORT int acceptAndReplace(SocketSource *source)
accepts a new connection on a listening socket and replaces the current socket with the new connectio...
QoreSocket::sendi8LSB
DLLEXPORT int sendi8LSB(int64 i)
sends an 8-byte (64bit) binary integer in LSB (Least Significant Byte first, little endian) format th...
QoreSocket::sendi1
DLLEXPORT int sendi1(char i)
sends a 1-byte binary integer data to a connected socket
QoreHashNode
This is the hash or associative list container type in Qore, dynamically allocated only...
Definition: QoreHashNode.h:50
QoreSocket::bind
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 ...
QoreSocket::getQueue
DLLLOCAL Queue * getQueue()
returns the event queue (not part of the library&#39;s public API)
QoreSocket::isSecure
DLLEXPORT bool isSecure() const
returns true if an SSL connection is active
QoreSocket::captureRemoteCertificates
DLLEXPORT bool captureRemoteCertificates(bool set)
sets the capture SSL certificate flag
QoreSocket::QoreSocket
DLLEXPORT QoreSocket()
creates an empty, unconnected socket
QoreSocket::readHTTPChunkedBody
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 ...
QoreSocket::recvu1
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...
QoreSocket::readHTTPHeader
DLLEXPORT AbstractQoreNode * readHTTPHeader(int timeout_ms, int *prc, int source=QORE_SOURCE_SOCKET)
read and parse HTTP header, caller owns AbstractQoreNode reference count returned ...
QoreSocket::connectUNIX
DLLEXPORT int connectUNIX(const char *p, ExceptionSink *xsink=0)
connects to a UNIX domain socket and returns a status code, Qore-language exceptions are raised in th...
QoreSocket::setAccept
DLLLOCAL void setAccept(QoreObject *o)
sets backwards-compatible members on accept in a new object - will be removed in a future version of ...
QoreSocket::recvi2
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...
QoreSocket::acceptSSL
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...
AbstractQoreNode
The base class for all value and parse types in Qore expression trees.
Definition: AbstractQoreNode.h:57
QoreSocket::bindUNIX
DLLEXPORT int bindUNIX(const char *name, ExceptionSink *xsink=0)
binds to a UNIX domain socket and returns a status code
QoreSocket::sendi2LSB
DLLEXPORT int sendi2LSB(short i)
sends a 2-byte (16bit) binary integer in LSB (Least Significant Byte first, little endian) format thr...
QoreSocket::readHTTPChunkedBodyBinary
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 ...
QoreSocket::upgradeClientToSSL
DLLEXPORT int upgradeClientToSSL(X509 *cert, EVP_PKEY *pkey, ExceptionSink *xsink)
negotiates an SSL connection from the client side
QoreFtpClient
provides thread-safe access to FTP servers through Qore data structures
Definition: QoreFtpClient.h:71
QoreSocket::getEncoding
DLLEXPORT const QoreEncoding * getEncoding() const
returns the character encoding associated with this socket
QoreSocket::getSocket
DLLEXPORT int getSocket() const
returns the file descriptor associated with this socket
QoreSocket::shutdown
DLLEXPORT int shutdown()
calls shutdown on the socket
QoreSocket::verifyPeerCertificate
DLLEXPORT long verifyPeerCertificate() const
returns the peer certificate verification code if an SSL connection is in progress ...
QoreSocket::isDataAvailable
DLLEXPORT bool isDataAvailable(int timeout_ms=0) const
returns true if data is available on the socket in the timeout period in milliseconds ...
QoreSocket::pendingHttpChunkedBody
DLLEXPORT bool pendingHttpChunkedBody() const
returns true if a HTTP header was read indicating chunked transfer encoding, but no chunked body has ...
QoreSocket::bindINET
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=0)
binds an INET or INET6 TCP socket to a specific socket address
QoreSocket::getRemoteCertificate
DLLEXPORT QoreObject * getRemoteCertificate() const
returns a remote certificate if available
QoreSocket::recvu2LSB
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...
QoreString
Qore&#39;s string type supported by the QoreEncoding class.
Definition: QoreString.h:81
QoreStringNode
Qore&#39;s string value type, reference counted, dynamically-allocated only.
Definition: QoreStringNode.h:50
QoreSocket::send
DLLEXPORT int send(const char *buf, size_t size)
sends binary data on a connected socket
QoreSocket::setSslVerifyMode
DLLEXPORT void setSslVerifyMode(int mode)
sets the SSL verification mode
QoreSocket::getSocketInfo
DLLEXPORT QoreHashNode * getSocketInfo(ExceptionSink *xsink) const
returns information for the current socket; the socket must be open
QoreSocket::accept
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...
QoreSocket::recv
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, caller owns the reference count returned
QoreSocket::getSSLCipherName
DLLEXPORT const char * getSSLCipherName() const
returns the name of the SSL Cipher for the currently-connected control connection, or 0 if there is none
QoreSocket::cleanup
DLLEXPORT void cleanup(ExceptionSink *xsink)
posts deleted message and removes any event queue
QoreSocket::getSendTimeout
DLLEXPORT int getSendTimeout() const
get send timeout in milliseconds
QoreSocket::~QoreSocket
DLLEXPORT ~QoreSocket()
disconnects if necessary, frees all data, and destroys the socket
QoreSocket::connectINET2SSL
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=0)
connects to an INET or INET6 socket by hostname and port number or service name and returns a status ...
QoreSocket::sendi8
DLLEXPORT int sendi8(int64 i)
sends an 8-byte (64bit) binary integer in MSB (Most Significant Byte first, big endian, network) format through a connected socket
QoreSocket::recvi4LSB
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...
QoreSocket::isWriteFinished
DLLEXPORT bool isWriteFinished(int timeout_ms=0) const
returns true if all write data has been written within the timeout period in milliseconds ...
QoreSocket::recvi2LSB
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...
QoreSocket::recvu4LSB
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...
QoreSocket::getSslVerifyMode
DLLEXPORT int getSslVerifyMode() const
returns the SSL verification mode
QoreSocket::connectUNIXSSL
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...
QoreSocket::isOpen
DLLEXPORT bool isOpen() const
returns true if the socket is open
QoreSocket::sendi4
DLLEXPORT int sendi4(int i)
sends a 4-byte (32bit) binary integer in MSB (Most Significant Byte first, big endian, network) format through a connected socket
QoreSocket::connectSSL
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...
QoreSocket::acceptAllCertificates
DLLEXPORT void acceptAllCertificates(bool accept_all=true)
with peer verification enabled, all certificates are accepted regardless of the validity of the Certi...
SocketSource::getAddress
DLLEXPORT const char * getAddress() const
returns the host address string as a C string
QoreSocket::listen
DLLEXPORT int listen()
sets an open socket to the listening state
QoreValue
The main value class in Qore, designed to be passed by value.
Definition: QoreValue.h:267
SocketSource::~SocketSource
DLLEXPORT ~SocketSource()
destroys the object and frees all memory
QoreSocket::setEncoding
DLLEXPORT void setEncoding(const QoreEncoding *id)
sets the character encoding for strings sent and received with this socket
SocketSource::takeHostName
DLLEXPORT QoreStringNode * takeHostName()
returns the hostname string field and leaves the object&#39;s hostname field empty; the caller owns the Q...
QoreSocket::getSSLCipherVersion
DLLEXPORT const char * getSSLCipherVersion() const
returns the version string of the SSL Cipher for the currently-connected control connection, or 0 if there is none
QoreSocket
provides access to sockets using Qore data structures
Definition: QoreSocket.h:126
QoreObject
the implementation of Qore&#39;s object data type, reference counted, dynamically-allocated only ...
Definition: QoreObject.h:60
QoreSocket::connect
DLLEXPORT int connect(const char *name, ExceptionSink *xsink=0)
connects to a socket and returns a status code, Qore-language exceptions are raised in the case of an...
ExceptionSink
container for holding Qore-language exception information and also for registering a "thread_exit" ca...
Definition: ExceptionSink.h:48
QoreSocket::upgradeServerToSSL
DLLEXPORT int upgradeServerToSSL(X509 *cert, EVP_PKEY *pkey, int timeout_ms, ExceptionSink *xsink)
negotiates an SSL connection from the client side
Qore.h
QoreSocket::recvi4
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...
QoreSocket::recvBinary
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...
QoreSocket::connectINET2
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=0)
connects to an INET or INET6 socket by hostname and port number or service name and returns a status ...
QoreSocket::getConnectionId
DLLEXPORT int64 getConnectionId() const
returns a connection ID to help identifying when new connections are made
QoreSocket::recvu4
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...
QoreSocket::shutdownSSL
DLLEXPORT int shutdownSSL(ExceptionSink *xsink)
shuts down an active SSL connection
QoreSocket::connectINETSSL
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, and returns a status code, Qore-language exceptions are raised in the case of any errors
int64
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
qore_offset_t
intptr_t qore_offset_t
used for offsets that could be negative
Definition: common.h:76
QoreSocket::sendi2
DLLEXPORT int sendi2(short i)
sends a 2-byte (16bit) binary integer in MSB (Most Significant Byte first, big endian, network) format through a connected socket
QoreSocket::connectINET
DLLEXPORT int connectINET(const char *host, int prt, ExceptionSink *xsink=0)
connects to an INET socket by hostname and port number and returns a status code, Qore-language excep...
ResolvedCallReferenceNode
base class for resolved call references
Definition: CallReferenceNode.h:109
SocketSource::takeAddress
DLLEXPORT QoreStringNode * takeAddress()
returns the host address string field and leaves the object&#39;s host address field empty; the caller ow...
QoreSocket::recvi8LSB
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...
QoreSocket::getPort
DLLEXPORT int getPort()
returns the TCP port number, also assigns the interal port number if it must be discovered ...
QoreSocket::setSendTimeout
DLLEXPORT int setSendTimeout(int ms)
set send timeout in milliseconds
QoreSocket::recvi8
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 ...
QoreSocket::setRecvTimeout
DLLEXPORT int setRecvTimeout(int ms)
set recv timeout in milliseconds
QoreSocket::close
DLLEXPORT int close()
closes the socket
QoreSocket::recvi1
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...
QoreSocket::getRecvTimeout
DLLEXPORT int getRecvTimeout() const
get recv timeout in milliseconds
QoreSocket::recvu2
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...
Q_AF_UNSPEC
#define Q_AF_UNSPEC
cross-platform define for AF_UNSPEC
Definition: common.h:58
QoreSocket::getAcceptAllCertificates
DLLEXPORT bool getAcceptAllCertificates() const
returns the current value of the "accept all certificates" flag
QoreSocket::setEventQueue
DLLLOCAL void setEventQueue(ExceptionSink *xsink, Queue *q, QoreValue arg, bool with_data)
sets the event queue (not part of the library&#39;s pubilc API), must be already referenced before call ...
QoreSocket::sendi4LSB
DLLEXPORT int sendi4LSB(int i)
sends a 4-byte (32bit) binary integer in LSB (Least Significant Byte first, little endian) format thr...
QoreSocket::sendHTTPMessageWithCallback
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...
QoreSocket::getPeerInfo
DLLEXPORT QoreHashNode * getPeerInfo(ExceptionSink *xsink) const
returns peer information for a connected socket
BinaryNode
holds arbitrary binary data
Definition: BinaryNode.h:41
SocketSource::getHostName
DLLEXPORT const char * getHostName() const
returns the hostname string as a C string