36 #ifndef _QORE_QORESOCKET_H 38 #define _QORE_QORESOCKET_H 41 #include <qore/InputStream.h> 42 #include <qore/OutputStream.h> 44 #include <sys/types.h> 52 #include <openssl/ssl.h> 53 #include <openssl/err.h> 55 #define QSE_MISC_ERR 0 56 #define QSE_RECV_ERR -1 57 #define QSE_NOT_OPEN -2 58 #define QSE_TIMEOUT -3 59 #define QSE_SSL_ERR -4 61 #define QSE_IN_OP_THREAD -6 74 friend struct qore_socket_private;
77 struct qore_socketsource_private *priv;
83 DLLLOCAL SocketSource& operator=(
const SocketSource&);
127 friend struct qore_socket_private;
128 friend struct qore_httpclient_priv;
129 friend class QoreSocketObject;
134 struct qore_socket_private *priv;
139 DLLLOCAL
static void convertHeaderToHash(
QoreHashNode* h,
char* p);
142 DLLLOCAL QoreSocket(
const QoreSocket&);
145 DLLLOCAL QoreSocket& operator=(
const QoreSocket&);
149 DLLEXPORT QoreSocket();
152 DLLEXPORT ~QoreSocket();
166 DLLEXPORT
int connect(
const char* name,
ExceptionSink* xsink = 0);
181 DLLEXPORT
int connect(
const char* name,
int timeout_ms,
ExceptionSink* xsink = 0);
194 DLLEXPORT
int connectINET(
const char* host,
int prt,
ExceptionSink* xsink = 0);
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);
225 DLLEXPORT
int connectINET(
const char* host,
int prt,
int timeout_ms,
ExceptionSink* xsink = 0);
237 DLLEXPORT
int connectUNIX(
const char* p,
ExceptionSink* xsink = 0);
251 DLLEXPORT
int connectUNIX(
const char* p,
int socktype,
int protocol = 0,
ExceptionSink* xsink = 0);
269 DLLEXPORT
int connectSSL(
const char* name, X509* cert, EVP_PKEY* pkey,
ExceptionSink* xsink);
288 DLLEXPORT
int connectSSL(
const char* name,
int timeout_ms, X509* cert, EVP_PKEY* pkey,
ExceptionSink* xsink);
305 DLLEXPORT
int connectINETSSL(
const char* host,
int prt, X509* cert, EVP_PKEY* pkey,
ExceptionSink* xsink);
323 DLLEXPORT
int connectINETSSL(
const char* host,
int prt,
int timeout_ms, X509* cert, EVP_PKEY* pkey,
ExceptionSink* xsink);
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);
358 DLLEXPORT
int connectUNIXSSL(
const char* p, X509* cert, EVP_PKEY* pkey,
ExceptionSink* xsink);
376 DLLEXPORT
int connectUNIXSSL(
const char* p,
int socktype,
int protocol, X509* cert, EVP_PKEY* pkey,
ExceptionSink* xsink);
385 DLLEXPORT
int bind(
const char* name,
bool reuseaddr =
false);
393 DLLEXPORT
int bind(
int prt,
bool reuseaddr);
402 DLLEXPORT
int bind(
const char* iface,
int prt,
bool reuseaddr =
false);
412 DLLEXPORT
int bind(
const struct sockaddr *addr,
int addr_size);
423 DLLEXPORT
int bind(
int family,
const struct sockaddr *addr,
int addr_size,
int socktype =
Q_SOCK_STREAM,
int protocol = 0);
434 DLLEXPORT
int bindUNIX(
const char* name,
ExceptionSink* xsink = 0);
447 DLLEXPORT
int bindUNIX(
const char* name,
int socktype,
int protocol = 0,
ExceptionSink* xsink = 0);
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);
465 DLLEXPORT
int getPort();
527 DLLEXPORT QoreSocket* accept(
int timeout_ms,
ExceptionSink* xsink);
542 DLLEXPORT QoreSocket* acceptSSL(
int timeout_ms, X509* cert, EVP_PKEY* pkey,
ExceptionSink* xsink);
556 DLLEXPORT
int acceptAndReplace(
int timeout_ms,
ExceptionSink* xsink);
562 DLLEXPORT
int listen();
571 DLLEXPORT
int listen(
int backlog);
580 DLLEXPORT
int send(
const char* buf,
qore_size_t size);
676 DLLEXPORT
int sendi1(
char i);
684 DLLEXPORT
int sendi2(
short i);
692 DLLEXPORT
int sendi4(
int i);
700 DLLEXPORT
int sendi8(
int64 i);
709 DLLEXPORT
int sendi2LSB(
short i);
718 DLLEXPORT
int sendi4LSB(
int i);
727 DLLEXPORT
int sendi8LSB(
int64 i);
738 DLLEXPORT
int sendi1(
char i,
int timeout_ms,
ExceptionSink* xsink);
750 DLLEXPORT
int sendi2(
short i,
int timeout_ms,
ExceptionSink* xsink);
762 DLLEXPORT
int sendi4(
int i,
int timeout_ms,
ExceptionSink* xsink);
787 DLLEXPORT
int sendi2LSB(
short i,
int timeout_ms,
ExceptionSink* xsink);
800 DLLEXPORT
int sendi4LSB(
int i,
int timeout_ms,
ExceptionSink* xsink);
825 DLLEXPORT
int recvi1(
int timeout_ms,
char* val);
836 DLLEXPORT
int recvi2(
int timeout_ms,
short *val);
847 DLLEXPORT
int recvi4(
int timeout_ms,
int* val);
858 DLLEXPORT
int recvi8(
int timeout_ms,
int64 *val);
870 DLLEXPORT
int recvi2LSB(
int timeout_ms,
short *val);
882 DLLEXPORT
int recvi4LSB(
int timeout_ms,
int* val);
892 DLLEXPORT
int recvi8LSB(
int timeout_ms,
int64 *val);
901 DLLEXPORT
int recvu1(
int timeout_ms,
unsigned char* val);
912 DLLEXPORT
int recvu2(
int timeout_ms,
unsigned short *val);
923 DLLEXPORT
int recvu4(
int timeout_ms,
unsigned int* val);
935 DLLEXPORT
int recvu2LSB(
int timeout_ms,
unsigned short *val);
947 DLLEXPORT
int recvu4LSB(
int timeout_ms,
unsigned int* val);
1107 DLLEXPORT
int64 recvu2LSB(
int timeout_ms,
unsigned short *val,
ExceptionSink* xsink);
1197 DLLEXPORT
BinaryNode* recvBinary(
int timeout_ms,
int* prc);
1221 DLLEXPORT
int recv(
int fd,
qore_offset_t size,
int timeout_ms);
1249 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);
1263 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);
1330 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);
1346 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);
1363 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);
1389 DLLEXPORT
AbstractQoreNode* readHTTPHeader(
int timeout_ms,
int* prc,
int source = QORE_SOURCE_SOCKET);
1439 DLLEXPORT
QoreHashNode* readHTTPChunkedBodyBinary(
int timeout_ms,
ExceptionSink* xsink,
int source = QORE_SOURCE_SOCKET);
1456 DLLEXPORT
int setSendTimeout(
int ms);
1459 DLLEXPORT
int setRecvTimeout(
int ms);
1462 DLLEXPORT
int getSendTimeout()
const;
1465 DLLEXPORT
int getRecvTimeout()
const;
1479 DLLEXPORT
bool isDataAvailable(
int timeout_ms = 0)
const;
1496 DLLEXPORT
bool isDataAvailable(
ExceptionSink* xsink,
int timeout_ms = 0)
const;
1511 DLLEXPORT
int asyncIoWait(
int timeout_ms,
bool read,
bool write)
const;
1518 DLLEXPORT
int close();
1527 DLLEXPORT
int shutdown();
1539 DLLEXPORT
int getSocket()
const;
1554 DLLEXPORT
bool isOpen()
const;
1559 DLLEXPORT
const char* getSSLCipherName()
const;
1564 DLLEXPORT
const char* getSSLCipherVersion()
const;
1569 DLLEXPORT
bool isSecure()
const;
1572 DLLEXPORT
long verifyPeerCertificate()
const;
1583 DLLEXPORT
int upgradeClientToSSL(X509* cert, EVP_PKEY* pkey,
ExceptionSink* xsink);
1595 DLLEXPORT
int upgradeServerToSSL(X509* cert, EVP_PKEY* pkey,
int timeout_ms,
ExceptionSink* xsink);
1607 DLLEXPORT
int upgradeClientToSSL(X509* cert, EVP_PKEY* pkey,
int timeout_ms,
ExceptionSink* xsink);
1618 DLLEXPORT
int upgradeServerToSSL(X509* cert, EVP_PKEY* pkey,
ExceptionSink* xsink);
1630 DLLEXPORT
bool isWriteFinished(
int timeout_ms = 0)
const;
1642 DLLEXPORT
bool isWriteFinished(
ExceptionSink* xsink,
int timeout_ms = 0)
const;
1708 DLLEXPORT
void clearStats();
1714 DLLEXPORT
bool pendingHttpChunkedBody()
const;
1723 DLLEXPORT
void setSslVerifyMode(
int mode);
1730 DLLEXPORT
int getSslVerifyMode()
const;
1737 DLLEXPORT
void acceptAllCertificates(
bool accept_all =
true);
1744 DLLEXPORT
bool getAcceptAllCertificates()
const;
1746 DLLLOCAL
static void doException(
int rc,
const char* meth,
int timeout_ms,
ExceptionSink* xsink);
1749 DLLLOCAL
void setEventQueue(Queue* cbq,
ExceptionSink* xsink);
1752 DLLLOCAL Queue* getQueue();
1755 DLLLOCAL
int64 getObjectIDForEvents()
const;
1757 DLLLOCAL
int setNoDelay(
int nodelay);
1758 DLLLOCAL
int getNoDelay()
const;
1764 class QoreSocketTimeoutHelper {
1766 class PrivateQoreSocketTimeoutHelper* priv;
1768 DLLEXPORT QoreSocketTimeoutHelper(
QoreSocket& s,
const char* op);
1769 DLLEXPORT ~QoreSocketTimeoutHelper();
1772 class QoreSocketThroughputHelper {
1774 class PrivateQoreSocketThroughputHelper* priv;
1776 DLLEXPORT QoreSocketThroughputHelper(
QoreSocket& s,
bool snd);
1777 DLLEXPORT ~QoreSocketThroughputHelper();
1778 DLLEXPORT
void finalize(
int64 bytes);
1781 #endif // _QORE_QORESOCKET_H #define Q_SOCK_STREAM
platform-independent define for SOCK_STREAM
Definition: common.h:68
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:73
This is the hash or associative list container type in Qore, dynamically allocated only...
Definition: QoreHashNode.h:50
The base class for all value and parse types in Qore expression trees.
Definition: AbstractQoreNode.h:54
size_t qore_size_t
used for sizes (same range as a pointer)
Definition: common.h:74
provides thread-safe access to FTP servers through Qore data structures
Definition: QoreFtpClient.h:71
Qore's string type supported by the QoreEncoding class.
Definition: QoreString.h:82
Qore's string value type, reference counted, dynamically-allocated only.
Definition: QoreStringNode.h:50
DLLEXPORT const char * getAddress() const
returns the host address string as a C string
DLLEXPORT ~SocketSource()
destroys the object and frees all memory
DLLEXPORT QoreStringNode * takeHostName()
returns the hostname string field and leaves the object's hostname field empty; the caller owns the Q...
provides access to sockets using Qore data structures
Definition: QoreSocket.h:126
the implementation of Qore's object data type, reference counted, dynamically-allocated only ...
Definition: QoreObject.h:62
container for holding Qore-language exception information and also for registering a "thread_exit" ca...
Definition: ExceptionSink.h:47
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:241
intptr_t qore_offset_t
used for offsets that could be negative
Definition: common.h:77
base class for resolved call references
Definition: CallReferenceNode.h:130
DLLEXPORT QoreStringNode * takeAddress()
returns the host address string field and leaves the object's host address field empty; the caller ow...
#define Q_AF_UNSPEC
cross-platform define for AF_UNSPEC
Definition: common.h:59
holds arbitrary binary data
Definition: BinaryNode.h:41
DLLEXPORT const char * getHostName() const
returns the hostname string as a C string