Qore Programming Language - C/C++ Library  0.8.12.2
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
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 - 2016 David Nichols
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 
42 #include <sys/types.h>
43 #include <unistd.h>
44 #include <strings.h>
45 #include <string.h>
46 #include <stdlib.h>
47 #include <ctype.h>
48 #include <unistd.h>
49 
50 #include <openssl/ssl.h>
51 #include <openssl/err.h>
52 
53 #define QSE_MISC_ERR 0
54 #define QSE_RECV_ERR -1
55 #define QSE_NOT_OPEN -2
56 #define QSE_TIMEOUT -3
57 #define QSE_SSL_ERR -4
58 #define QSE_IN_OP -5
59 #define QSE_IN_OP_THREAD -6
60 
61 class Queue;
62 
64 
71 class SocketSource {
72  friend struct qore_socket_private;
73 
74 private:
75  struct qore_socketsource_private *priv; // private implementation
76 
78  DLLLOCAL SocketSource(const SocketSource&);
79 
81  DLLLOCAL SocketSource& operator=(const SocketSource&);
82 
83 public:
85  DLLEXPORT SocketSource();
86 
88  DLLEXPORT ~SocketSource();
89 
91 
93  DLLEXPORT QoreStringNode* takeAddress();
94 
96 
98  DLLEXPORT QoreStringNode* takeHostName();
99 
101 
103  DLLEXPORT const char* getAddress() const;
104 
106 
108  DLLEXPORT const char* getHostName() const;
109 
110  DLLLOCAL void setAll(QoreObject* o, ExceptionSink* xsink);
111 };
112 
114 
124 class QoreSocket {
125  friend struct qore_socket_private;
126  friend struct qore_httpclient_priv;
127  friend class QoreSocketObject;
128 
129 private:
131  struct qore_socket_private *priv;
132 
134  DLLLOCAL QoreSocket(int n_sock, int n_sfamily, int n_stype, int s_prot, const QoreEncoding *csid);
135 
136  DLLLOCAL static void convertHeaderToHash(QoreHashNode* h, char* p);
137 
139  DLLLOCAL QoreSocket(const QoreSocket&);
140 
142  DLLLOCAL QoreSocket& operator=(const QoreSocket&);
143 
144 public:
146  DLLEXPORT QoreSocket();
147 
149  DLLEXPORT ~QoreSocket();
150 
152 
163  DLLEXPORT int connect(const char* name, ExceptionSink* xsink = 0);
164 
166 
178  DLLEXPORT int connect(const char* name, int timeout_ms, ExceptionSink* xsink = 0);
179 
181 
191  DLLEXPORT int connectINET(const char* host, int prt, ExceptionSink* xsink = 0);
192 
194 
208  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);
209 
211 
222  DLLEXPORT int connectINET(const char* host, int prt, int timeout_ms, ExceptionSink* xsink = 0);
223 
225 
234  DLLEXPORT int connectUNIX(const char* p, ExceptionSink* xsink = 0);
235 
237 
248  DLLEXPORT int connectUNIX(const char* p, int socktype, int protocol = 0, ExceptionSink* xsink = 0);
249 
251 
266  DLLEXPORT int connectSSL(const char* name, X509* cert, EVP_PKEY* pkey, ExceptionSink* xsink);
267 
269 
285  DLLEXPORT int connectSSL(const char* name, int timeout_ms, X509* cert, EVP_PKEY* pkey, ExceptionSink* xsink);
286 
288 
302  DLLEXPORT int connectINETSSL(const char* host, int prt, X509* cert, EVP_PKEY* pkey, ExceptionSink* xsink);
303 
305 
320  DLLEXPORT int connectINETSSL(const char* host, int prt, int timeout_ms, X509* cert, EVP_PKEY* pkey, ExceptionSink* xsink);
321 
323 
339  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);
340 
342 
355  DLLEXPORT int connectUNIXSSL(const char* p, X509* cert, EVP_PKEY* pkey, ExceptionSink* xsink);
356 
358 
373  DLLEXPORT int connectUNIXSSL(const char* p, int socktype, int protocol, X509* cert, EVP_PKEY* pkey, ExceptionSink* xsink);
374 
376 
382  DLLEXPORT int bind(const char* name, bool reuseaddr = false);
383 
385 
390  DLLEXPORT int bind(int prt, bool reuseaddr);
391 
393 
399  DLLEXPORT int bind(const char* iface, int prt, bool reuseaddr = false);
400 
402 
409  DLLEXPORT int bind(const struct sockaddr *addr, int addr_size);
410 
412 
420  DLLEXPORT int bind(int family, const struct sockaddr *addr, int addr_size, int socktype = Q_SOCK_STREAM, int protocol = 0);
421 
423 
431  DLLEXPORT int bindUNIX(const char* name, ExceptionSink* xsink = 0);
432 
434 
444  DLLEXPORT int bindUNIX(const char* name, int socktype, int protocol = 0, ExceptionSink* xsink = 0);
445 
447 
459  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);
460 
462  DLLEXPORT int getPort();
463 
465 
477  DLLEXPORT QoreSocket* accept(SocketSource* source, ExceptionSink* xsink);
478 
480 
495  DLLEXPORT QoreSocket* acceptSSL(SocketSource* source, X509* cert, EVP_PKEY* pkey, ExceptionSink* xsink);
496 
498 
510  DLLEXPORT int acceptAndReplace(SocketSource* source);
511 
513 
524  DLLEXPORT QoreSocket* accept(int timeout_ms, ExceptionSink* xsink);
525 
527 
539  DLLEXPORT QoreSocket* acceptSSL(int timeout_ms, X509* cert, EVP_PKEY* pkey, ExceptionSink* xsink);
540 
542 
553  DLLEXPORT int acceptAndReplace(int timeout_ms, ExceptionSink* xsink);
554 
556 
559  DLLEXPORT int listen();
560 
562 
568  DLLEXPORT int listen(int backlog);
569 
571 
577  DLLEXPORT int send(const char* buf, qore_size_t size);
578 
580 
587  DLLEXPORT int send(const char* buf, qore_size_t size, ExceptionSink* xsink);
588 
590 
598  DLLEXPORT int send(const char* buf, qore_size_t size, int timeout_ms, ExceptionSink* xsink);
599 
601 
607  DLLEXPORT int send(const QoreString *msg, ExceptionSink* xsink);
608 
610 
617  DLLEXPORT int send(const QoreString *msg, int timeout_ms, ExceptionSink* xsink);
618 
620 
625  DLLEXPORT int send(const BinaryNode* msg);
626 
628 
634  DLLEXPORT int send(const BinaryNode* msg, ExceptionSink* xsink);
635 
637 
644  DLLEXPORT int send(const BinaryNode* msg, int timeout_ms, ExceptionSink* xsink);
645 
647 
653  DLLEXPORT int send(int fd, qore_offset_t size = -1);
654 
656 
660  DLLEXPORT int sendi1(char i);
661 
663 
668  DLLEXPORT int sendi2(short i);
669 
671 
676  DLLEXPORT int sendi4(int i);
677 
679 
684  DLLEXPORT int sendi8(int64 i);
685 
687 
693  DLLEXPORT int sendi2LSB(short i);
694 
696 
702  DLLEXPORT int sendi4LSB(int i);
703 
705 
711  DLLEXPORT int sendi8LSB(int64 i);
712 
714 
722  DLLEXPORT int sendi1(char i, int timeout_ms, ExceptionSink* xsink);
723 
725 
734  DLLEXPORT int sendi2(short i, int timeout_ms, ExceptionSink* xsink);
735 
737 
746  DLLEXPORT int sendi4(int i, int timeout_ms, ExceptionSink* xsink);
747 
749 
758  DLLEXPORT int sendi8(int64 i, int timeout_ms, ExceptionSink* xsink);
759 
761 
771  DLLEXPORT int sendi2LSB(short i, int timeout_ms, ExceptionSink* xsink);
772 
774 
784  DLLEXPORT int sendi4LSB(int i, int timeout_ms, ExceptionSink* xsink);
785 
787 
797  DLLEXPORT int sendi8LSB(int64 i, int timeout_ms, ExceptionSink* xsink);
798 
800 
809  DLLEXPORT int recvi1(int timeout_ms, char* val);
810 
812 
820  DLLEXPORT int recvi2(int timeout_ms, short *val);
821 
823 
831  DLLEXPORT int recvi4(int timeout_ms, int* val);
832 
834 
842  DLLEXPORT int recvi8(int timeout_ms, int64 *val);
843 
845 
854  DLLEXPORT int recvi2LSB(int timeout_ms, short *val);
855 
857 
866  DLLEXPORT int recvi4LSB(int timeout_ms, int* val);
867 
869 
876  DLLEXPORT int recvi8LSB(int timeout_ms, int64 *val);
877 
879 
885  DLLEXPORT int recvu1(int timeout_ms, unsigned char* val);
886 
888 
896  DLLEXPORT int recvu2(int timeout_ms, unsigned short *val);
897 
899 
907  DLLEXPORT int recvu4(int timeout_ms, unsigned int* val);
908 
910 
919  DLLEXPORT int recvu2LSB(int timeout_ms, unsigned short *val);
920 
922 
931  DLLEXPORT int recvu4LSB(int timeout_ms, unsigned int* val);
932 
934 
944  DLLEXPORT int64 recvi1(int timeout_ms, char* val, ExceptionSink* xsink);
945 
947 
958  DLLEXPORT int64 recvi2(int timeout_ms, short *val, ExceptionSink* xsink);
959 
961 
973  DLLEXPORT int64 recvi4(int timeout_ms, int* val, ExceptionSink* xsink);
974 
976 
987  DLLEXPORT int64 recvi8(int timeout_ms, int64 *val, ExceptionSink* xsink);
988 
990 
1002  DLLEXPORT int64 recvi2LSB(int timeout_ms, short *val, ExceptionSink* xsink);
1003 
1005 
1017  DLLEXPORT int64 recvi4LSB(int timeout_ms, int* val, ExceptionSink* xsink);
1018 
1020 
1031  DLLEXPORT int64 recvi8LSB(int timeout_ms, int64 *val, ExceptionSink* xsink);
1032 
1034 
1044  DLLEXPORT int64 recvu1(int timeout_ms, unsigned char* val, ExceptionSink* xsink);
1045 
1047 
1059  DLLEXPORT int64 recvu2(int timeout_ms, unsigned short *val, ExceptionSink* xsink);
1060 
1062 
1074  DLLEXPORT int64 recvu4(int timeout_ms, unsigned int* val, ExceptionSink* xsink);
1075 
1077 
1091  DLLEXPORT int64 recvu2LSB(int timeout_ms, unsigned short *val, ExceptionSink* xsink);
1092 
1094 
1108  DLLEXPORT int64 recvu4LSB(int timeout_ms, unsigned int* val, ExceptionSink* xsink);
1109 
1111 
1118  DLLEXPORT QoreStringNode* recv(qore_offset_t bufsize, int timeout_ms, int* prc);
1119 
1121 
1128  DLLEXPORT QoreStringNode* recv(qore_offset_t bufsize, int timeout_ms, ExceptionSink* xsink);
1129 
1131 
1137  DLLEXPORT BinaryNode* recvBinary(qore_offset_t bufsize, int timeout_ms, int* prc);
1138 
1140 
1146  DLLEXPORT BinaryNode* recvBinary(qore_offset_t bufsize, int timeout_ms, ExceptionSink* xsink);
1147 
1149 
1158  DLLEXPORT QoreStringNode* recv(int timeout_ms, int* prc);
1159 
1161 
1170  DLLEXPORT QoreStringNode* recv(int timeout_ms, ExceptionSink* xsink);
1171 
1173 
1181  DLLEXPORT BinaryNode* recvBinary(int timeout_ms, int* prc);
1182 
1184 
1192  DLLEXPORT BinaryNode* recvBinary(int timeout_ms, ExceptionSink* xsink);
1193 
1195 
1202  DLLEXPORT int recv(int fd, qore_offset_t size, int timeout_ms);
1203 
1205 
1215  DLLEXPORT int sendHTTPMessage(const char* method, const char* path, const char* http_version, const QoreHashNode* headers, const void* data, qore_size_t size, int source = QORE_SOURCE_SOCKET);
1216 
1218 
1229  DLLEXPORT int sendHTTPMessage(QoreHashNode* info, const char* method, const char* path, const char* http_version, const QoreHashNode* headers, const void* data, qore_size_t size, int source = QORE_SOURCE_SOCKET);
1230 
1232 
1246  DLLEXPORT int sendHTTPMessage(ExceptionSink* xsink, QoreHashNode* info, const char* method, const char* path, const char* http_version, const QoreHashNode* headers, const void* data, qore_size_t size, int source = QORE_SOURCE_SOCKET);
1247 
1249 
1264  DLLEXPORT int sendHTTPMessage(ExceptionSink* xsink, QoreHashNode* info, const char* method, const char* path, const char* http_version, const QoreHashNode* headers, const void* data, qore_size_t size, int source, int timeout_ms);
1265 
1267 
1281  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);
1282 
1284 
1296  DLLEXPORT int sendHTTPResponse(int code, const char* desc, const char* http_version, const QoreHashNode* headers, const void* data, qore_size_t size, int source = QORE_SOURCE_SOCKET);
1297 
1299 
1312  DLLEXPORT int sendHTTPResponse(ExceptionSink* xsink, int code, const char* desc, const char* http_version, const QoreHashNode* headers, const void* data, qore_size_t size, int source = QORE_SOURCE_SOCKET);
1313 
1315 
1329  DLLEXPORT int sendHTTPResponse(ExceptionSink* xsink, int code, const char* desc, const char* http_version, const QoreHashNode* headers, const void* data, qore_size_t size, int source, int timeout_ms);
1330 
1332 
1345  DLLEXPORT int sendHTTPResponseWithCallback(ExceptionSink* xsink, int code, const char* desc, const char* http_version, const QoreHashNode* headers, const ResolvedCallReferenceNode& send_callback, int source, int timeout_ms);
1346 
1348 
1355  DLLEXPORT AbstractQoreNode* readHTTPHeader(int timeout_ms, int* prc, int source = QORE_SOURCE_SOCKET);
1356 
1358 
1366  DLLEXPORT AbstractQoreNode* readHTTPHeader(QoreHashNode* info, int timeout_ms, int* prc, int source = QORE_SOURCE_SOCKET);
1367 
1369 
1380  DLLEXPORT QoreHashNode* readHTTPHeader(ExceptionSink* xsink, QoreHashNode* info, int timeout_ms, int source = QORE_SOURCE_SOCKET);
1381 
1383 
1393  DLLEXPORT QoreStringNode* readHTTPHeaderString(ExceptionSink* xsink, int timeout_ms, int source = QORE_SOURCE_SOCKET);
1394 
1396 
1405  DLLEXPORT QoreHashNode* readHTTPChunkedBodyBinary(int timeout_ms, ExceptionSink* xsink, int source = QORE_SOURCE_SOCKET);
1406 
1408 
1419  DLLEXPORT QoreHashNode* readHTTPChunkedBody(int timeout_ms, ExceptionSink* xsink, int source = QORE_SOURCE_SOCKET);
1420 
1422  DLLEXPORT int setSendTimeout(int ms);
1423 
1425  DLLEXPORT int setRecvTimeout(int ms);
1426 
1428  DLLEXPORT int getSendTimeout() const;
1429 
1431  DLLEXPORT int getRecvTimeout() const;
1432 
1434 
1445  DLLEXPORT bool isDataAvailable(int timeout_ms = 0) const;
1446 
1448 
1462  DLLEXPORT bool isDataAvailable(ExceptionSink* xsink, int timeout_ms = 0) const;
1463 
1465 
1477  DLLEXPORT int asyncIoWait(int timeout_ms, bool read, bool write) const;
1478 
1480 
1484  DLLEXPORT int close();
1485 
1487 
1493  DLLEXPORT int shutdown();
1494 
1496 
1500  DLLEXPORT int shutdownSSL(ExceptionSink* xsink);
1501 
1503 
1505  DLLEXPORT int getSocket() const;
1506 
1508 
1510  DLLEXPORT const QoreEncoding *getEncoding() const;
1511 
1513 
1515  DLLEXPORT void setEncoding(const QoreEncoding *id);
1516 
1518 
1520  DLLEXPORT bool isOpen() const;
1521 
1523 
1525  DLLEXPORT const char* getSSLCipherName() const;
1526 
1528 
1530  DLLEXPORT const char* getSSLCipherVersion() const;
1531 
1533 
1535  DLLEXPORT bool isSecure() const;
1536 
1538  DLLEXPORT long verifyPeerCertificate() const;
1539 
1541 
1549  DLLEXPORT int upgradeClientToSSL(X509* cert, EVP_PKEY* pkey, ExceptionSink* xsink);
1550 
1552 
1561  DLLEXPORT int upgradeServerToSSL(X509* cert, EVP_PKEY* pkey, int timeout_ms, ExceptionSink* xsink);
1562 
1564 
1573  DLLEXPORT int upgradeClientToSSL(X509* cert, EVP_PKEY* pkey, int timeout_ms, ExceptionSink* xsink);
1574 
1576 
1584  DLLEXPORT int upgradeServerToSSL(X509* cert, EVP_PKEY* pkey, ExceptionSink* xsink);
1585 
1587 
1596  DLLEXPORT bool isWriteFinished(int timeout_ms = 0) const;
1597 
1599 
1608  DLLEXPORT bool isWriteFinished(ExceptionSink* xsink, int timeout_ms = 0) const;
1609 
1611 
1622  DLLEXPORT QoreHashNode* getPeerInfo(ExceptionSink* xsink) const;
1623 
1625 
1638  DLLEXPORT QoreHashNode* getPeerInfo(ExceptionSink* xsink, bool host_lookup) const;
1639 
1641 
1653  DLLEXPORT QoreHashNode* getSocketInfo(ExceptionSink* xsink) const;
1654 
1656 
1669  DLLEXPORT QoreHashNode* getSocketInfo(ExceptionSink* xsink, bool host_lookup) const;
1670 
1671  DLLEXPORT void clearWarningQueue(ExceptionSink* xsink);
1672  DLLEXPORT void setWarningQueue(ExceptionSink* xsink, int64 warning_ms, int64 warning_bs, class Queue* wq, AbstractQoreNode* arg, int64 min_ms = 1000);
1673  DLLEXPORT QoreHashNode* getUsageInfo() const;
1674  DLLEXPORT void clearStats();
1675 
1677  DLLEXPORT void cleanup(ExceptionSink* xsink);
1678 
1680  DLLEXPORT bool pendingHttpChunkedBody() const;
1681 
1682  DLLLOCAL static void doException(int rc, const char* meth, int timeout_ms, ExceptionSink* xsink);
1683 
1685  DLLLOCAL void setEventQueue(Queue* cbq, ExceptionSink* xsink);
1686 
1688  DLLLOCAL Queue* getQueue();
1689 
1691  DLLLOCAL int64 getObjectIDForEvents() const;
1692 
1693  DLLLOCAL int setNoDelay(int nodelay);
1694  DLLLOCAL int getNoDelay() const;
1695 
1697  DLLLOCAL void setAccept(QoreObject* o);
1698 };
1699 
1700 class QoreSocketTimeoutHelper {
1701 protected:
1702  class PrivateQoreSocketTimeoutHelper* priv;
1703 public:
1704  DLLEXPORT QoreSocketTimeoutHelper(QoreSocket& s, const char* op);
1705  DLLEXPORT ~QoreSocketTimeoutHelper();
1706 };
1707 
1708 class QoreSocketThroughputHelper {
1709 protected:
1710  class PrivateQoreSocketThroughputHelper* priv;
1711 public:
1712  DLLEXPORT QoreSocketThroughputHelper(QoreSocket& s, bool snd);
1713  DLLEXPORT ~QoreSocketThroughputHelper();
1714  DLLEXPORT void finalize(int64 bytes);
1715 };
1716 
1717 #endif // _QORE_QORESOCKET_H
DLLEXPORT bool isOpen() const
returns true if the socket is open
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
#define Q_SOCK_STREAM
platform-independent define for SOCK_STREAM
Definition: common.h:65
DLLEXPORT QoreStringNode * readHTTPHeaderString(ExceptionSink *xsink, int timeout_ms, int source=QORE_SOURCE_SOCKET)
read a HTTP header, caller owns QoreStringNode reference count returned
DLLEXPORT bool isSecure() const
returns true if an SSL connection is active
DLLEXPORT SocketSource()
creates an empty object
defines string encoding functions in Qore
Definition: QoreEncoding.h:85
a helper class for getting socket origination information
Definition: QoreSocket.h:71
DLLEXPORT int acceptAndReplace(SocketSource *source)
accepts a new connection on a listening socket and replaces the current socket with the new connectio...
DLLEXPORT int sendi8LSB(int64 i)
sends an 8-byte (64bit) binary integer in LSB (Least Significant Byte first, little endian) format th...
DLLEXPORT int sendi1(char i)
sends a 1-byte binary integer data to a connected socket
This is the hash or associative list container type in Qore, dynamically allocated only...
Definition: QoreHashNode.h:49
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 ...
DLLLOCAL int64 getObjectIDForEvents() const
returns a unique ID for the socket to be used in event messages
DLLEXPORT QoreHashNode * getPeerInfo(ExceptionSink *xsink) const
returns peer information for a connected socket
DLLLOCAL Queue * getQueue()
returns the event queue (not part of the library&#39;s public API)
DLLEXPORT long verifyPeerCertificate() const
returns the peer certificate verification code if an SSL connection is in progress ...
DLLEXPORT QoreSocket()
creates an empty, unconnected socket
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 ...
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 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 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...
DLLLOCAL void setAccept(QoreObject *o)
sets backwards-compatible members on accept in a new object - will be removed in a future version of ...
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...
DLLEXPORT const char * getAddress() const
returns the host address string as a C string
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...
The base class for all value and parse types in Qore expression trees.
Definition: AbstractQoreNode.h:55
DLLEXPORT int bindUNIX(const char *name, ExceptionSink *xsink=0)
binds to a UNIX domain socket and returns a status code
DLLEXPORT int sendi2LSB(short i)
sends a 2-byte (16bit) binary integer in LSB (Least Significant Byte first, little endian) format thr...
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 bool pendingHttpChunkedBody() const
returns true if a HTTP header was read indicating chunked transfer encoding, but no chunked body has ...
DLLEXPORT int upgradeClientToSSL(X509 *cert, EVP_PKEY *pkey, ExceptionSink *xsink)
negotiates an SSL connection from the client side
DLLEXPORT const QoreEncoding * getEncoding() const
returns the character encoding associated with this socket
size_t qore_size_t
used for sizes (same range as a pointer)
Definition: common.h:71
DLLEXPORT bool isDataAvailable(int timeout_ms=0) const
returns true if data is available on the socket in the timeout period in milliseconds ...
DLLEXPORT int shutdown()
calls shutdown on the socket
DLLEXPORT int getSocket() const
returns the file descriptor associated with this socket
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
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 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...
Qore&#39;s string type supported by the QoreEncoding class.
Definition: QoreString.h:82
Qore&#39;s string value type, reference counted, dynamically-allocated only.
Definition: QoreStringNode.h:50
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...
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
DLLEXPORT const char * getHostName() const
returns the hostname string as a C string
DLLEXPORT void cleanup(ExceptionSink *xsink)
posts deleted message and removes any event queue
DLLEXPORT ~QoreSocket()
disconnects if necessary, frees all data, and destroys 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=0)
connects to an INET or INET6 socket by hostname and port number or service name and returns a status ...
DLLLOCAL void setEventQueue(Queue *cbq, ExceptionSink *xsink)
sets the event queue (not part of the library&#39;s pubilc API), must be already referenced before call ...
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
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 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 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 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 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
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 isWriteFinished(int timeout_ms=0) const
returns true if all write data has been written within the timeout period in milliseconds ...
DLLEXPORT int listen()
sets an open socket to the listening state
DLLEXPORT int getRecvTimeout() const
get recv timeout in milliseconds
DLLEXPORT ~SocketSource()
destroys the object and frees all memory
DLLEXPORT void setEncoding(const QoreEncoding *id)
sets the character encoding for strings sent and received with this socket
DLLEXPORT QoreStringNode * takeHostName()
returns the hostname string field and leaves the object&#39;s hostname field empty; the caller owns the Q...
provides access to sockets using Qore data structures
Definition: QoreSocket.h:124
the implementation of Qore&#39;s object data type, reference counted, dynamically-allocated only ...
Definition: QoreObject.h:64
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...
container for holding Qore-language exception information and also for registering a &quot;thread_exit&quot; ca...
Definition: ExceptionSink.h:43
DLLEXPORT int upgradeServerToSSL(X509 *cert, EVP_PKEY *pkey, int timeout_ms, ExceptionSink *xsink)
negotiates an SSL connection from the client side
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 sendHTTPResponse(int code, const char *desc, const char *http_version, const QoreHashNode *headers, const void *data, qore_size_t size, int source=QORE_SOURCE_SOCKET)
send an HTTP response message on the 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 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 ...
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 shutdownSSL(ExceptionSink *xsink)
shuts down an active SSL connection
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
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:228
intptr_t qore_offset_t
used for offsets that could be negative
Definition: common.h:74
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
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...
base class for resolved call references
Definition: CallReferenceNode.h:130
DLLEXPORT QoreStringNode * takeAddress()
returns the host address string field and leaves the object&#39;s host address field empty; the caller ow...
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 int getPort()
returns the TCP port number, also assigns the interal port number if it must be discovered ...
DLLEXPORT int getSendTimeout() const
get send timeout in milliseconds
DLLEXPORT int setSendTimeout(int ms)
set send timeout in milliseconds
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 int sendHTTPResponseWithCallback(ExceptionSink *xsink, int code, const char *desc, const char *http_version, const QoreHashNode *headers, const ResolvedCallReferenceNode &send_callback, int source, int timeout_ms)
send an HTTP response message on the socket with a chunked message body using a calback ...
DLLEXPORT int send(const char *buf, qore_size_t size)
sends binary data on a connected socket
DLLEXPORT int setRecvTimeout(int ms)
set recv timeout in milliseconds
DLLEXPORT int close()
closes the socket
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 recvu2(int timeout_ms, unsigned short *val)
reads a 2-byte unsigned integer in MSB (Most Significant Byte first, big endian, network) format from...
#define Q_AF_UNSPEC
cross-platform define for AF_UNSPEC
Definition: common.h:56
DLLEXPORT const char * getSSLCipherName() const
returns the name of the SSL Cipher for the currently-connected control connection, or 0 if there is none
DLLEXPORT int sendi4LSB(int i)
sends a 4-byte (32bit) binary integer in LSB (Least Significant Byte first, little endian) format thr...
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 QoreHashNode * getSocketInfo(ExceptionSink *xsink) const
returns information for the current socket; the socket must be open
DLLEXPORT int sendHTTPMessage(const char *method, const char *path, const char *http_version, const QoreHashNode *headers, const void *data, qore_size_t size, int source=QORE_SOURCE_SOCKET)
send an HTTP request message on the socket
holds arbitrary binary data
Definition: BinaryNode.h:41