QoreSocket.h
/* -*- mode: c++; indent-tabs-mode: nil -*- */
/*
QoreSocket.h
IPv4, IPv6, unix socket class with SSL support
Qore Programming Language
Copyright (C) 2003 - 2019 Qore Technologies, s.r.o.
will unlink (delete) UNIX domain socket files when closed
Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"),
to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
Note that the Qore library is released under a choice of three open-source
licenses: MIT (as above), LGPL 2+, or GPL 2+; see README-LICENSE for more
information.
*/
#ifndef _QORE_QORESOCKET_H
#define _QORE_QORESOCKET_H
#include <qore/Qore.h>
#include <qore/InputStream.h>
#include <qore/OutputStream.h>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <strings.h>
#include <sys/types.h>
#include <unistd.h>
#include <openssl/ssl.h>
#include <openssl/err.h>
#define QSE_MISC_ERR 0
#define QSE_RECV_ERR -1
#define QSE_NOT_OPEN -2
#define QSE_TIMEOUT -3
#define QSE_SSL_ERR -4
#define QSE_IN_OP -5
#define QSE_IN_OP_THREAD -6
// forward reference
class Queue;
class SocketSource {
friend struct qore_socket_private;
private:
struct qore_socketsource_private *priv; // private implementation
DLLLOCAL SocketSource(const SocketSource&);
DLLLOCAL SocketSource& operator=(const SocketSource&);
public:
DLLEXPORT SocketSource();
DLLEXPORT ~SocketSource();
DLLEXPORT QoreStringNode* takeAddress();
DLLEXPORT QoreStringNode* takeHostName();
DLLEXPORT const char* getAddress() const;
DLLEXPORT const char* getHostName() const;
DLLLOCAL void setAll(QoreObject* o, ExceptionSink* xsink);
};
class QoreSocket {
friend struct qore_socket_private;
friend struct qore_httpclient_priv;
friend class QoreSocketObject;
friend class QoreFtpClient;
private:
struct qore_socket_private *priv;
DLLLOCAL QoreSocket(int n_sock, int n_sfamily, int n_stype, int s_prot, const QoreEncoding *csid);
DLLLOCAL static void convertHeaderToHash(QoreHashNode* h, char* p);
DLLLOCAL QoreSocket(const QoreSocket&);
DLLLOCAL QoreSocket& operator=(const QoreSocket&);
public:
DLLEXPORT QoreSocket();
DLLEXPORT ~QoreSocket();
DLLEXPORT int connect(const char* name, ExceptionSink* xsink = 0);
DLLEXPORT int connect(const char* name, int timeout_ms, ExceptionSink* xsink = 0);
DLLEXPORT int connectINET(const char* host, int prt, ExceptionSink* xsink = 0);
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);
DLLEXPORT int connectINET(const char* host, int prt, int timeout_ms, ExceptionSink* xsink = 0);
DLLEXPORT int connectUNIX(const char* p, ExceptionSink* xsink = 0);
DLLEXPORT int connectUNIX(const char* p, int socktype, int protocol = 0, ExceptionSink* xsink = 0);
DLLEXPORT int connectSSL(const char* name, X509* cert, EVP_PKEY* pkey, ExceptionSink* xsink);
DLLEXPORT int connectSSL(const char* name, int timeout_ms, X509* cert, EVP_PKEY* pkey, ExceptionSink* xsink);
DLLEXPORT int connectINETSSL(const char* host, int prt, X509* cert, EVP_PKEY* pkey, ExceptionSink* xsink);
DLLEXPORT int connectINETSSL(const char* host, int prt, int timeout_ms, X509* cert, EVP_PKEY* pkey, ExceptionSink* xsink);
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);
DLLEXPORT int connectUNIXSSL(const char* p, X509* cert, EVP_PKEY* pkey, ExceptionSink* xsink);
DLLEXPORT int connectUNIXSSL(const char* p, int socktype, int protocol, X509* cert, EVP_PKEY* pkey, ExceptionSink* xsink);
DLLEXPORT int bind(const char* name, bool reuseaddr = false);
DLLEXPORT int bind(int prt, bool reuseaddr);
DLLEXPORT int bind(const char* iface, int prt, bool reuseaddr = false);
DLLEXPORT int bind(const struct sockaddr *addr, int addr_size);
DLLEXPORT int bind(int family, const struct sockaddr *addr, int addr_size, int socktype = Q_SOCK_STREAM, int protocol = 0);
DLLEXPORT int bindUNIX(const char* name, ExceptionSink* xsink = 0);
DLLEXPORT int bindUNIX(const char* name, int socktype, int protocol = 0, ExceptionSink* xsink = 0);
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);
DLLEXPORT int getPort();
DLLEXPORT QoreSocket* accept(SocketSource* source, ExceptionSink* xsink);
DLLEXPORT QoreSocket* acceptSSL(SocketSource* source, X509* cert, EVP_PKEY* pkey, ExceptionSink* xsink);
DLLEXPORT int acceptAndReplace(SocketSource* source);
DLLEXPORT QoreSocket* accept(int timeout_ms, ExceptionSink* xsink);
DLLEXPORT QoreSocket* acceptSSL(int timeout_ms, X509* cert, EVP_PKEY* pkey, ExceptionSink* xsink);
DLLEXPORT int acceptAndReplace(int timeout_ms, ExceptionSink* xsink);
DLLEXPORT int listen();
DLLEXPORT int listen(int backlog);
DLLEXPORT int send(const char* buf, qore_size_t size);
DLLEXPORT int send(const char* buf, qore_size_t size, ExceptionSink* xsink);
DLLEXPORT int send(const char* buf, qore_size_t size, int timeout_ms, ExceptionSink* xsink);
DLLEXPORT int send(const QoreString *msg, ExceptionSink* xsink);
DLLEXPORT int send(const QoreString *msg, int timeout_ms, ExceptionSink* xsink);
DLLEXPORT int send(const QoreStringNode& msg, int timeout_ms, ExceptionSink* xsink);
DLLEXPORT int send(const BinaryNode* msg);
DLLEXPORT int send(const BinaryNode* msg, ExceptionSink* xsink);
DLLEXPORT int send(const BinaryNode* msg, int timeout_ms, ExceptionSink* xsink);
DLLEXPORT int send(int fd, qore_offset_t size = -1);
DLLEXPORT int send(int fd, qore_offset_t size, int timeout_ms, ExceptionSink* xsink);
DLLEXPORT int sendi1(char i);
DLLEXPORT int sendi2(short i);
DLLEXPORT int sendi4(int i);
DLLEXPORT int sendi8(int64 i);
DLLEXPORT int sendi2LSB(short i);
DLLEXPORT int sendi4LSB(int i);
DLLEXPORT int sendi8LSB(int64 i);
DLLEXPORT int sendi1(char i, int timeout_ms, ExceptionSink* xsink);
DLLEXPORT int sendi2(short i, int timeout_ms, ExceptionSink* xsink);
DLLEXPORT int sendi4(int i, int timeout_ms, ExceptionSink* xsink);
DLLEXPORT int sendi8(int64 i, int timeout_ms, ExceptionSink* xsink);
DLLEXPORT int sendi2LSB(short i, int timeout_ms, ExceptionSink* xsink);
DLLEXPORT int sendi4LSB(int i, int timeout_ms, ExceptionSink* xsink);
DLLEXPORT int sendi8LSB(int64 i, int timeout_ms, ExceptionSink* xsink);
DLLEXPORT int recvi1(int timeout_ms, char* val);
DLLEXPORT int recvi2(int timeout_ms, short *val);
DLLEXPORT int recvi4(int timeout_ms, int* val);
DLLEXPORT int recvi8(int timeout_ms, int64 *val);
DLLEXPORT int recvi2LSB(int timeout_ms, short *val);
DLLEXPORT int recvi4LSB(int timeout_ms, int* val);
DLLEXPORT int recvi8LSB(int timeout_ms, int64 *val);
DLLEXPORT int recvu1(int timeout_ms, unsigned char* val);
DLLEXPORT int recvu2(int timeout_ms, unsigned short *val);
DLLEXPORT int recvu4(int timeout_ms, unsigned int* val);
DLLEXPORT int recvu2LSB(int timeout_ms, unsigned short *val);
DLLEXPORT int recvu4LSB(int timeout_ms, unsigned int* val);
DLLEXPORT int64 recvi1(int timeout_ms, char* val, ExceptionSink* xsink);
DLLEXPORT int64 recvi2(int timeout_ms, short *val, ExceptionSink* xsink);
DLLEXPORT int64 recvi4(int timeout_ms, int* val, ExceptionSink* xsink);
DLLEXPORT int64 recvi8(int timeout_ms, int64 *val, ExceptionSink* xsink);
DLLEXPORT int64 recvi2LSB(int timeout_ms, short *val, ExceptionSink* xsink);
DLLEXPORT int64 recvi4LSB(int timeout_ms, int* val, ExceptionSink* xsink);
DLLEXPORT int64 recvi8LSB(int timeout_ms, int64 *val, ExceptionSink* xsink);
DLLEXPORT int64 recvu1(int timeout_ms, unsigned char* val, ExceptionSink* xsink);
DLLEXPORT int64 recvu2(int timeout_ms, unsigned short *val, ExceptionSink* xsink);
DLLEXPORT int64 recvu4(int timeout_ms, unsigned int* val, ExceptionSink* xsink);
DLLEXPORT int64 recvu2LSB(int timeout_ms, unsigned short *val, ExceptionSink* xsink);
DLLEXPORT int64 recvu4LSB(int timeout_ms, unsigned int* val, ExceptionSink* xsink);
DLLEXPORT QoreStringNode* recv(qore_offset_t bufsize, int timeout_ms, int* prc);
DLLEXPORT QoreStringNode* recv(qore_offset_t bufsize, int timeout_ms, ExceptionSink* xsink);
DLLEXPORT BinaryNode* recvBinary(qore_offset_t bufsize, int timeout_ms, int* prc);
DLLEXPORT BinaryNode* recvBinary(qore_offset_t bufsize, int timeout_ms, ExceptionSink* xsink);
DLLEXPORT QoreStringNode* recv(int timeout_ms, int* prc);
DLLEXPORT QoreStringNode* recv(int timeout_ms, ExceptionSink* xsink);
DLLEXPORT BinaryNode* recvBinary(int timeout_ms, int* prc);
DLLEXPORT BinaryNode* recvBinary(int timeout_ms, ExceptionSink* xsink);
DLLEXPORT int recv(int fd, qore_offset_t size, int timeout_ms);
DLLEXPORT int recv(int fd, qore_offset_t size, int timeout_ms, ExceptionSink* xsink);
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);
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);
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);
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);
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);
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);
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);
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);
DLLEXPORT int sendHTTPResponse(ExceptionSink* xsink, QoreHashNode* info, int code, const char* desc,
const char* http_version, const QoreHashNode* headers, const void* data, qore_size_t size, int source,
int timeout_ms);
DLLEXPORT AbstractQoreNode* readHTTPHeader(int timeout_ms, int* prc, int source = QORE_SOURCE_SOCKET);
DLLEXPORT AbstractQoreNode* readHTTPHeader(QoreHashNode* info, int timeout_ms, int* prc, int source = QORE_SOURCE_SOCKET);
DLLEXPORT QoreHashNode* readHTTPHeader(ExceptionSink* xsink, QoreHashNode* info, int timeout_ms, int source = QORE_SOURCE_SOCKET);
DLLEXPORT QoreStringNode* readHTTPHeaderString(ExceptionSink* xsink, int timeout_ms, int source = QORE_SOURCE_SOCKET);
DLLEXPORT QoreHashNode* readHTTPChunkedBodyBinary(int timeout_ms, ExceptionSink* xsink, int source = QORE_SOURCE_SOCKET);
DLLEXPORT QoreHashNode* readHTTPChunkedBody(int timeout_ms, ExceptionSink* xsink, int source = QORE_SOURCE_SOCKET);
DLLEXPORT int setSendTimeout(int ms);
DLLEXPORT int setRecvTimeout(int ms);
DLLEXPORT int getSendTimeout() const;
DLLEXPORT int getRecvTimeout() const;
DLLEXPORT bool isDataAvailable(int timeout_ms = 0) const;
DLLEXPORT bool isDataAvailable(ExceptionSink* xsink, int timeout_ms = 0) const;
DLLEXPORT int asyncIoWait(int timeout_ms, bool read, bool write) const;
DLLEXPORT int close();
DLLEXPORT int shutdown();
DLLEXPORT int shutdownSSL(ExceptionSink* xsink);
DLLEXPORT int getSocket() const;
DLLEXPORT const QoreEncoding *getEncoding() const;
DLLEXPORT void setEncoding(const QoreEncoding *id);
DLLEXPORT bool isOpen() const;
DLLEXPORT const char* getSSLCipherName() const;
DLLEXPORT const char* getSSLCipherVersion() const;
DLLEXPORT bool isSecure() const;
DLLEXPORT long verifyPeerCertificate() const;
DLLEXPORT int upgradeClientToSSL(X509* cert, EVP_PKEY* pkey, ExceptionSink* xsink);
DLLEXPORT int upgradeServerToSSL(X509* cert, EVP_PKEY* pkey, int timeout_ms, ExceptionSink* xsink);
DLLEXPORT int upgradeClientToSSL(X509* cert, EVP_PKEY* pkey, int timeout_ms, ExceptionSink* xsink);
DLLEXPORT int upgradeServerToSSL(X509* cert, EVP_PKEY* pkey, ExceptionSink* xsink);
DLLEXPORT bool isWriteFinished(int timeout_ms = 0) const;
DLLEXPORT bool isWriteFinished(ExceptionSink* xsink, int timeout_ms = 0) const;
DLLEXPORT QoreHashNode* getPeerInfo(ExceptionSink* xsink) const;
DLLEXPORT QoreHashNode* getPeerInfo(ExceptionSink* xsink, bool host_lookup) const;
DLLEXPORT QoreHashNode* getSocketInfo(ExceptionSink* xsink) const;
DLLEXPORT QoreHashNode* getSocketInfo(ExceptionSink* xsink, bool host_lookup) const;
DLLEXPORT void clearWarningQueue(ExceptionSink* xsink);
DLLEXPORT void setWarningQueue(ExceptionSink* xsink, int64 warning_ms, int64 warning_bs, Queue* wq, QoreValue arg, int64 min_ms = 1000);
DLLEXPORT QoreHashNode* getUsageInfo() const;
DLLEXPORT void clearStats();
DLLEXPORT void cleanup(ExceptionSink* xsink);
DLLEXPORT bool pendingHttpChunkedBody() const;
DLLEXPORT void setSslVerifyMode(int mode);
DLLEXPORT int getSslVerifyMode() const;
DLLEXPORT void acceptAllCertificates(bool accept_all = true);
DLLEXPORT bool getAcceptAllCertificates() const;
DLLEXPORT bool captureRemoteCertificates(bool set);
DLLEXPORT QoreObject* getRemoteCertificate() const;
DLLEXPORT int64 getConnectionId() const;
DLLLOCAL static void doException(int rc, const char* meth, int timeout_ms, ExceptionSink* xsink);
DLLLOCAL void setEventQueue(ExceptionSink* xsink, Queue* q, QoreValue arg, bool with_data);
DLLLOCAL Queue* getQueue();
DLLLOCAL int64 getObjectIDForEvents() const;
DLLLOCAL int setNoDelay(int nodelay);
DLLLOCAL int getNoDelay() const;
DLLLOCAL void setAccept(QoreObject* o);
};
class QoreSocketTimeoutHelper {
protected:
class PrivateQoreSocketTimeoutHelper* priv;
public:
DLLEXPORT QoreSocketTimeoutHelper(QoreSocket& s, const char* op);
DLLEXPORT ~QoreSocketTimeoutHelper();
};
class QoreSocketThroughputHelper {
protected:
class PrivateQoreSocketThroughputHelper* priv;
public:
DLLEXPORT QoreSocketThroughputHelper(QoreSocket& s, bool snd);
DLLEXPORT ~QoreSocketThroughputHelper();
DLLEXPORT void finalize(int64 bytes);
};
#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
SocketSource::SocketSource
DLLEXPORT SocketSource()
creates an empty object
QoreEncoding
defines string encoding functions in Qore
Definition: QoreEncoding.h:83
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:54
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
qore_size_t
size_t qore_size_t
used for sizes (same range as a pointer)
Definition: common.h:73
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::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:262
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:61
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::sendHTTPResponse
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
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:105
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::send
DLLEXPORT int send(const char *buf, qore_size_t size)
sends binary data on a connected socket
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
QoreSocket::sendHTTPMessage
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
BinaryNode
holds arbitrary binary data
Definition: BinaryNode.h:41
SocketSource::getHostName
DLLEXPORT const char * getHostName() const
returns the hostname string as a C string