Qore Programming Language  0.8.8
 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 2003 - 2013 David Nichols
10 
11  will unlink (delete) UNIX domain socket files when closed
12 
13  This library is free software; you can redistribute it and/or
14  modify it under the terms of the GNU Lesser General Public
15  License as published by the Free Software Foundation; either
16  version 2.1 of the License, or (at your option) any later version.
17 
18  This library is distributed in the hope that it will be useful,
19  but WITHOUT ANY WARRANTY; without even the implied warranty of
20  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21  Lesser General Public License for more details.
22 
23  You should have received a copy of the GNU Lesser General Public
24  License along with this library; if not, write to the Free Software
25  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
26 */
27 
28 #ifndef _QORE_QORESOCKET_H
29 
30 #define _QORE_QORESOCKET_H
31 
32 #include <qore/Qore.h>
33 
34 #include <sys/types.h>
35 #include <unistd.h>
36 #include <strings.h>
37 #include <string.h>
38 #include <stdlib.h>
39 #include <ctype.h>
40 #include <unistd.h>
41 
42 #include <openssl/ssl.h>
43 #include <openssl/err.h>
44 
45 #define QSE_MISC_ERR 0
46 #define QSE_RECV_ERR -1
47 #define QSE_NOT_OPEN -2
48 #define QSE_TIMEOUT -3
49 #define QSE_SSL_ERR -4
50 
51 class Queue;
52 
54 
61 class SocketSource {
62  friend struct qore_socket_private;
63 private:
64  struct qore_socketsource_private *priv; // private implementation
65 
67  DLLLOCAL SocketSource(const SocketSource&);
68 
70  DLLLOCAL SocketSource& operator=(const SocketSource&);
71 
72 public:
74  DLLEXPORT SocketSource();
75 
77  DLLEXPORT ~SocketSource();
78 
80 
82  DLLEXPORT QoreStringNode *takeAddress();
83 
85 
87  DLLEXPORT QoreStringNode *takeHostName();
88 
90 
92  DLLEXPORT const char *getAddress() const;
93 
95 
97  DLLEXPORT const char *getHostName() const;
98 
99  DLLLOCAL void setAll(QoreObject *o, ExceptionSink *xsink);
100 };
101 
103 
113 class QoreSocket {
114 private:
116  struct qore_socket_private *priv;
117 
119  DLLLOCAL QoreSocket(int n_sock, int n_sfamily, int n_stype, int s_prot, const QoreEncoding *csid);
120 
121  DLLLOCAL static void convertHeaderToHash(QoreHashNode *h, char *p);
122 
124  DLLLOCAL QoreSocket(const QoreSocket&);
125 
127  DLLLOCAL QoreSocket& operator=(const QoreSocket&);
128 
129 public:
131  DLLEXPORT QoreSocket();
132 
134  DLLEXPORT ~QoreSocket();
135 
137 
148  DLLEXPORT int connect(const char *name, ExceptionSink *xsink = 0);
149 
151 
163  DLLEXPORT int connect(const char *name, int timeout_ms, ExceptionSink *xsink = 0);
164 
166 
176  DLLEXPORT int connectINET(const char *host, int prt, ExceptionSink *xsink = 0);
177 
179 
193  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);
194 
196 
207  DLLEXPORT int connectINET(const char *host, int prt, int timeout_ms, ExceptionSink *xsink = 0);
208 
210 
219  DLLEXPORT int connectUNIX(const char *p, ExceptionSink *xsink = 0);
220 
222 
233  DLLEXPORT int connectUNIX(const char *p, int socktype, int protocol = 0, ExceptionSink *xsink = 0);
234 
236 
251  DLLEXPORT int connectSSL(const char *name, X509 *cert, EVP_PKEY *pkey, ExceptionSink *xsink);
252 
254 
270  DLLEXPORT int connectSSL(const char *name, int timeout_ms, X509 *cert, EVP_PKEY *pkey, ExceptionSink *xsink);
271 
273 
287  DLLEXPORT int connectINETSSL(const char *host, int prt, X509 *cert, EVP_PKEY *pkey, ExceptionSink *xsink);
288 
290 
305  DLLEXPORT int connectINETSSL(const char *host, int prt, int timeout_ms, X509 *cert, EVP_PKEY *pkey, ExceptionSink *xsink);
306 
308 
324  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);
325 
327 
340  DLLEXPORT int connectUNIXSSL(const char *p, X509 *cert, EVP_PKEY *pkey, ExceptionSink *xsink);
341 
343 
358  DLLEXPORT int connectUNIXSSL(const char *p, int socktype, int protocol, X509 *cert, EVP_PKEY *pkey, ExceptionSink *xsink);
359 
361 
367  DLLEXPORT int bind(const char *name, bool reuseaddr = false);
368 
370 
375  DLLEXPORT int bind(int prt, bool reuseaddr);
376 
378 
384  DLLEXPORT int bind(const char *iface, int prt, bool reuseaddr = false);
385 
387 
394  DLLEXPORT int bind(const struct sockaddr *addr, int addr_size);
395 
397 
405  DLLEXPORT int bind(int family, const struct sockaddr *addr, int addr_size, int socktype = Q_SOCK_STREAM, int protocol = 0);
406 
408 
416  DLLEXPORT int bindUNIX(const char *name, ExceptionSink *xsink = 0);
417 
419 
429  DLLEXPORT int bindUNIX(const char *name, int socktype, int protocol = 0, ExceptionSink *xsink = 0);
430 
432 
444  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);
445 
447  DLLEXPORT int getPort();
448 
450 
462  DLLEXPORT QoreSocket *accept(SocketSource *source, ExceptionSink *xsink);
463 
465 
480  DLLEXPORT QoreSocket *acceptSSL(SocketSource *source, X509 *cert, EVP_PKEY *pkey, ExceptionSink *xsink);
481 
483 
495  DLLEXPORT int acceptAndReplace(SocketSource *source);
496 
498 
509  DLLEXPORT QoreSocket *accept(int timeout_ms, ExceptionSink *xsink);
510 
512 
524  DLLEXPORT QoreSocket *acceptSSL(int timeout_ms, X509 *cert, EVP_PKEY *pkey, ExceptionSink *xsink);
525 
527 
538  DLLEXPORT int acceptAndReplace(int timeout_ms, ExceptionSink *xsink);
539 
541 
544  DLLEXPORT int listen();
545 
547 
553  DLLEXPORT int listen(int backlog);
554 
556 
562  DLLEXPORT int send(const char *buf, qore_size_t size);
563 
565 
572  DLLEXPORT int send(const char *buf, qore_size_t size, ExceptionSink* xsink);
573 
575 
583  DLLEXPORT int send(const char *buf, qore_size_t size, int timeout_ms, ExceptionSink* xsink);
584 
586 
592  DLLEXPORT int send(const QoreString *msg, ExceptionSink *xsink);
593 
595 
602  DLLEXPORT int send(const QoreString *msg, int timeout_ms, ExceptionSink *xsink);
603 
605 
610  DLLEXPORT int send(const BinaryNode *msg);
611 
613 
619  DLLEXPORT int send(const BinaryNode *msg, ExceptionSink* xsink);
620 
622 
629  DLLEXPORT int send(const BinaryNode *msg, int timeout_ms, ExceptionSink* xsink);
630 
632 
638  DLLEXPORT int send(int fd, qore_offset_t size = -1);
639 
641 
645  DLLEXPORT int sendi1(char i);
646 
648 
653  DLLEXPORT int sendi2(short i);
654 
656 
661  DLLEXPORT int sendi4(int i);
662 
664 
669  DLLEXPORT int sendi8(int64 i);
670 
672 
678  DLLEXPORT int sendi2LSB(short i);
679 
681 
687  DLLEXPORT int sendi4LSB(int i);
688 
690 
696  DLLEXPORT int sendi8LSB(int64 i);
697 
699 
707  DLLEXPORT int sendi1(char i, int timeout_ms, ExceptionSink* xsink);
708 
710 
719  DLLEXPORT int sendi2(short i, int timeout_ms, ExceptionSink* xsink);
720 
722 
731  DLLEXPORT int sendi4(int i, int timeout_ms, ExceptionSink* xsink);
732 
734 
743  DLLEXPORT int sendi8(int64 i, int timeout_ms, ExceptionSink* xsink);
744 
746 
756  DLLEXPORT int sendi2LSB(short i, int timeout_ms, ExceptionSink* xsink);
757 
759 
769  DLLEXPORT int sendi4LSB(int i, int timeout_ms, ExceptionSink* xsink);
770 
772 
782  DLLEXPORT int sendi8LSB(int64 i, int timeout_ms, ExceptionSink* xsink);
783 
785 
794  DLLEXPORT int recvi1(int timeout_ms, char *val);
795 
797 
805  DLLEXPORT int recvi2(int timeout_ms, short *val);
806 
808 
816  DLLEXPORT int recvi4(int timeout_ms, int *val);
817 
819 
827  DLLEXPORT int recvi8(int timeout_ms, int64 *val);
828 
830 
839  DLLEXPORT int recvi2LSB(int timeout_ms, short *val);
840 
842 
851  DLLEXPORT int recvi4LSB(int timeout_ms, int *val);
852 
854 
861  DLLEXPORT int recvi8LSB(int timeout_ms, int64 *val);
862 
864 
870  DLLEXPORT int recvu1(int timeout_ms, unsigned char *val);
871 
873 
881  DLLEXPORT int recvu2(int timeout_ms, unsigned short *val);
882 
884 
892  DLLEXPORT int recvu4(int timeout_ms, unsigned int *val);
893 
895 
904  DLLEXPORT int recvu2LSB(int timeout_ms, unsigned short *val);
905 
907 
916  DLLEXPORT int recvu4LSB(int timeout_ms, unsigned int *val);
917 
919 
929  DLLEXPORT int64 recvi1(int timeout_ms, char *val, ExceptionSink* xsink);
930 
932 
943  DLLEXPORT int64 recvi2(int timeout_ms, short *val, ExceptionSink* xsink);
944 
946 
958  DLLEXPORT int64 recvi4(int timeout_ms, int *val, ExceptionSink* xsink);
959 
961 
972  DLLEXPORT int64 recvi8(int timeout_ms, int64 *val, ExceptionSink* xsink);
973 
975 
987  DLLEXPORT int64 recvi2LSB(int timeout_ms, short *val, ExceptionSink* xsink);
988 
990 
1002  DLLEXPORT int64 recvi4LSB(int timeout_ms, int *val, ExceptionSink* xsink);
1003 
1005 
1016  DLLEXPORT int64 recvi8LSB(int timeout_ms, int64 *val, ExceptionSink* xsink);
1017 
1019 
1029  DLLEXPORT int64 recvu1(int timeout_ms, unsigned char *val, ExceptionSink* xsink);
1030 
1032 
1044  DLLEXPORT int64 recvu2(int timeout_ms, unsigned short *val, ExceptionSink* xsink);
1045 
1047 
1059  DLLEXPORT int64 recvu4(int timeout_ms, unsigned int *val, ExceptionSink* xsink);
1060 
1062 
1076  DLLEXPORT int64 recvu2LSB(int timeout_ms, unsigned short *val, ExceptionSink* xsink);
1077 
1079 
1093  DLLEXPORT int64 recvu4LSB(int timeout_ms, unsigned int *val, ExceptionSink* xsink);
1094 
1096 
1103  DLLEXPORT QoreStringNode *recv(qore_offset_t bufsize, int timeout_ms, int *prc);
1104 
1106 
1113  DLLEXPORT QoreStringNode* recv(qore_offset_t bufsize, int timeout_ms, ExceptionSink* xsink);
1114 
1116 
1122  DLLEXPORT BinaryNode *recvBinary(qore_offset_t bufsize, int timeout_ms, int *prc);
1123 
1125 
1131  DLLEXPORT BinaryNode* recvBinary(qore_offset_t bufsize, int timeout_ms, ExceptionSink* xsink);
1132 
1134 
1143  DLLEXPORT QoreStringNode *recv(int timeout_ms, int *prc);
1144 
1146 
1155  DLLEXPORT QoreStringNode* recv(int timeout_ms, ExceptionSink* xsink);
1156 
1158 
1166  DLLEXPORT BinaryNode *recvBinary(int timeout_ms, int *prc);
1167 
1169 
1177  DLLEXPORT BinaryNode* recvBinary(int timeout_ms, ExceptionSink* xsink);
1178 
1180 
1187  DLLEXPORT int recv(int fd, qore_offset_t size, int timeout_ms);
1188 
1190 
1200  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);
1201 
1203 
1214  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);
1215 
1217 
1231  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);
1232 
1234 
1249  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);
1250 
1252 
1264  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);
1265 
1267 
1280  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);
1281 
1283 
1297  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);
1298 
1300 
1307  DLLEXPORT AbstractQoreNode *readHTTPHeader(int timeout_ms, int *prc, int source = QORE_SOURCE_SOCKET);
1308 
1310 
1318  DLLEXPORT AbstractQoreNode *readHTTPHeader(QoreHashNode *info, int timeout_ms, int *prc, int source = QORE_SOURCE_SOCKET);
1319 
1321 
1332  DLLEXPORT QoreHashNode *readHTTPHeader(ExceptionSink* xsink, QoreHashNode *info, int timeout_ms, int source = QORE_SOURCE_SOCKET);
1333 
1335 
1344  DLLEXPORT QoreStringNode* readHTTPHeaderString(ExceptionSink* xsink, int timeout_ms, int source = QORE_SOURCE_SOCKET);
1345 
1347 
1356  DLLEXPORT QoreHashNode *readHTTPChunkedBodyBinary(int timeout_ms, ExceptionSink *xsink, int source = QORE_SOURCE_SOCKET);
1357 
1359 
1370  DLLEXPORT QoreHashNode *readHTTPChunkedBody(int timeout_ms, ExceptionSink *xsink, int source = QORE_SOURCE_SOCKET);
1371 
1373  DLLEXPORT int setSendTimeout(int ms);
1374 
1376  DLLEXPORT int setRecvTimeout(int ms);
1377 
1379  DLLEXPORT int getSendTimeout() const;
1380 
1382  DLLEXPORT int getRecvTimeout() const;
1383 
1385 
1390  DLLEXPORT bool isDataAvailable(int timeout_ms = 0) const;
1391 
1393 
1402  DLLEXPORT bool isDataAvailable(ExceptionSink* xsink, int timeout_ms = 0) const;
1403 
1405 
1409  DLLEXPORT int close();
1410 
1412 
1418  DLLEXPORT int shutdown();
1419 
1421 
1425  DLLEXPORT int shutdownSSL(ExceptionSink *xsink);
1426 
1428 
1430  DLLEXPORT int getSocket() const;
1431 
1433 
1435  DLLEXPORT const QoreEncoding *getEncoding() const;
1436 
1438 
1440  DLLEXPORT void setEncoding(const QoreEncoding *id);
1441 
1443 
1445  DLLEXPORT bool isOpen() const;
1446 
1448 
1450  DLLEXPORT const char *getSSLCipherName() const;
1451 
1453 
1455  DLLEXPORT const char *getSSLCipherVersion() const;
1456 
1458 
1460  DLLEXPORT bool isSecure() const;
1461 
1463  DLLEXPORT long verifyPeerCertificate() const;
1464 
1466 
1474  DLLEXPORT int upgradeClientToSSL(X509 *cert, EVP_PKEY *pkey, ExceptionSink *xsink);
1475 
1477 
1485  DLLEXPORT int upgradeServerToSSL(X509 *cert, EVP_PKEY *pkey, ExceptionSink *xsink);
1486 
1488 
1493  DLLEXPORT bool isWriteFinished(int timeout_ms = 0) const;
1494 
1496 
1505  DLLEXPORT bool isWriteFinished(ExceptionSink* xsink, int timeout_ms = 0) const;
1506 
1508 
1519  DLLEXPORT QoreHashNode* getPeerInfo(ExceptionSink* xsink) const;
1520 
1522 
1535  DLLEXPORT QoreHashNode* getPeerInfo(ExceptionSink* xsink, bool host_lookup) const;
1536 
1538 
1551  DLLEXPORT QoreHashNode* getSocketInfo(ExceptionSink* xsink) const;
1552 
1554 
1566  DLLEXPORT QoreHashNode* getSocketInfo(ExceptionSink* xsink, bool host_lookup) const;
1567 
1568  DLLLOCAL static void doException(int rc, const char *meth, int timeout_ms, ExceptionSink *xsink);
1569 
1571  DLLLOCAL void setEventQueue(Queue *cbq, ExceptionSink *xsink);
1572 
1574  DLLLOCAL Queue *getQueue();
1575 
1577  DLLLOCAL int64 getObjectIDForEvents() const;
1578 
1580  DLLLOCAL void cleanup(ExceptionSink *xsink);
1581 
1582  DLLLOCAL int setNoDelay(int nodelay);
1583  DLLLOCAL int getNoDelay() const;
1584 
1586  DLLLOCAL void setAccept(QoreObject *o);
1587 };
1588 
1589 #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:55
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:72
a helper class for getting socket origination information
Definition: QoreSocket.h:61
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:41
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...
DLLLOCAL void cleanup(ExceptionSink *xsink)
posts deleted message and removes any event queue
The base class for all value and parse types in Qore expression trees.
Definition: AbstractQoreNode.h:47
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 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:61
DLLEXPORT bool isDataAvailable(int timeout_ms=0) const
returns true if data is available on the socket in the timeout period in milliseconds ...
long qore_offset_t
used for offsets that could be negative
Definition: common.h:64
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 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:42
Qore&#39;s string value type, reference counted, dynamically-allocated only.
Definition: QoreStringNode.h:40
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 ~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:113
the implementation of Qore&#39;s object data type, reference counted, dynamically-allocated only ...
Definition: QoreObject.h:56
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:35
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
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...
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 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:46
DLLEXPORT int upgradeServerToSSL(X509 *cert, EVP_PKEY *pkey, ExceptionSink *xsink)
negotiates an SSL connection from the client side
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 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:33