|
Qore Programming Language
0.9.16
|
36 #ifndef _QORE_QORESOCKET_H
38 #define _QORE_QORESOCKET_H
41 #include <qore/InputStream.h>
42 #include <qore/OutputStream.h>
48 #include <sys/types.h>
51 #include <openssl/ssl.h>
52 #include <openssl/err.h>
54 #define QSE_MISC_ERR 0
55 #define QSE_RECV_ERR -1
56 #define QSE_NOT_OPEN -2
57 #define QSE_TIMEOUT -3
58 #define QSE_SSL_ERR -4
60 #define QSE_IN_OP_THREAD -6
74 friend hashdecl qore_socket_private;
77 hashdecl qore_socketsource_private *priv;
127 friend hashdecl qore_socket_private;
128 friend hashdecl qore_httpclient_priv;
129 friend class QoreSocketObject;
134 hashdecl qore_socket_private *priv;
139 DLLLOCAL
static void convertHeaderToHash(
QoreHashNode* h,
char* p);
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);
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);
571 DLLEXPORT
int listen(
int backlog);
688 DLLEXPORT
int sendi1(
char i);
696 DLLEXPORT
int sendi2(
short i);
704 DLLEXPORT
int sendi4(
int i);
837 DLLEXPORT
int recvi1(
int timeout_ms,
char* val);
848 DLLEXPORT
int recvi2(
int timeout_ms,
short *val);
859 DLLEXPORT
int recvi4(
int timeout_ms,
int* val);
882 DLLEXPORT
int recvi2LSB(
int timeout_ms,
short *val);
894 DLLEXPORT
int recvi4LSB(
int timeout_ms,
int* val);
913 DLLEXPORT
int recvu1(
int timeout_ms,
unsigned char* val);
924 DLLEXPORT
int recvu2(
int timeout_ms,
unsigned short *val);
935 DLLEXPORT
int recvu4(
int timeout_ms,
unsigned int* val);
947 DLLEXPORT
int recvu2LSB(
int timeout_ms,
unsigned short *val);
959 DLLEXPORT
int recvu4LSB(
int timeout_ms,
unsigned int* val);
1262 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);
1530 DLLEXPORT
int asyncIoWait(
int timeout_ms,
bool read,
bool write)
const;
1537 DLLEXPORT
int close();
1573 DLLEXPORT
bool isOpen()
const;
1727 DLLEXPORT
void clearStats();
1792 DLLLOCAL
static void doException(
int rc,
const char* meth,
int timeout_ms,
ExceptionSink* xsink);
1803 DLLLOCAL
int setNoDelay(
int nodelay);
1804 DLLLOCAL
int getNoDelay()
const;
1810 class QoreSocketTimeoutHelper {
1812 class PrivateQoreSocketTimeoutHelper* priv;
1814 DLLEXPORT QoreSocketTimeoutHelper(
QoreSocket& s,
const char* op);
1815 DLLEXPORT ~QoreSocketTimeoutHelper();
1818 class QoreSocketThroughputHelper {
1820 class PrivateQoreSocketThroughputHelper* priv;
1822 DLLEXPORT QoreSocketThroughputHelper(
QoreSocket& s,
bool snd);
1823 DLLEXPORT ~QoreSocketThroughputHelper();
1824 DLLEXPORT
void finalize(
int64 bytes);
1827 #endif // _QORE_QORESOCKET_H
DLLEXPORT QoreHashNode * getSocketInfo(ExceptionSink *xsink) const
returns information for the current socket; the socket must be open
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 QoreObject * getRemoteCertificate() const
returns a remote certificate if available
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 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 ...
const DLLEXPORT char * getSSLCipherName() const
returns the name of the SSL Cipher for the currently-connected control connection,...
DLLEXPORT SocketSource()
creates an empty object
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,...
intptr_t qore_offset_t
used for offsets that could be negative
Definition: common.h:76
DLLLOCAL void setAccept(QoreObject *o)
sets backwards-compatible members on accept in a new object - will be removed in a future version of ...
The main value class in Qore, designed to be passed by value.
Definition: QoreValue.h:262
DLLEXPORT int sendi4LSB(int i)
sends a 4-byte (32bit) binary integer in LSB (Least Significant Byte first, little endian) format thr...
This is the hash or associative list container type in Qore, dynamically allocated only,...
Definition: QoreHashNode.h:50
DLLEXPORT int upgradeServerToSSL(X509 *cert, EVP_PKEY *pkey, int timeout_ms, ExceptionSink *xsink)
negotiates an SSL connection from the client side
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 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 ...
const DLLEXPORT char * getSSLCipherVersion() const
returns the version string of the SSL Cipher for the currently-connected control connection,...
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 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...
const DLLEXPORT QoreEncoding * getEncoding() const
returns the character encoding 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 int64 getConnectionId() const
returns a connection ID to help identifying when new connections are made
const DLLEXPORT char * getHostName() const
returns the hostname string as a C string
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...
size_t qore_size_t
used for sizes (same range as a pointer)
Definition: common.h:73
#define Q_AF_UNSPEC
cross-platform define for AF_UNSPEC
Definition: common.h:58
DLLEXPORT int setRecvTimeout(int ms)
set recv timeout in milliseconds
provides access to sockets using Qore data structures
Definition: QoreSocket.h:126
DLLEXPORT bool captureRemoteCertificates(bool set)
sets the capture SSL certificate flag
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...
const DLLEXPORT char * getAddress() const
returns the host address string as a C string
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 void cleanup(ExceptionSink *xsink)
posts deleted message and removes any event queue
DLLEXPORT int listen()
sets an open socket to the listening state
DLLEXPORT int bindUNIX(const char *name, ExceptionSink *xsink=0)
binds to a UNIX domain socket and returns a status code
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
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 QoreStringNode * takeHostName()
returns the hostname string field and leaves the object's hostname field empty; the caller owns the Q...
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
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 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 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...
a helper class for getting socket origination information
Definition: QoreSocket.h:73
Qore's string type supported by the QoreEncoding class.
Definition: QoreString.h:81
DLLEXPORT int getRecvTimeout() const
get recv timeout in milliseconds
DLLEXPORT int shutdownSSL(ExceptionSink *xsink)
shuts down an active SSL connection
DLLEXPORT int close()
closes the socket
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...
DLLLOCAL int64 getObjectIDForEvents() const
returns a unique ID for the socket to be used in event messages
DLLEXPORT int acceptAndReplace(SocketSource *source)
accepts a new connection on a listening socket and replaces the current socket with the new connectio...
DLLEXPORT QoreHashNode * getPeerInfo(ExceptionSink *xsink) const
returns peer information for a connected socket
DLLEXPORT bool getAcceptAllCertificates() const
returns the current value of the "accept all certificates" flag
DLLLOCAL void setEventQueue(ExceptionSink *xsink, Queue *q, QoreValue arg, bool with_data)
sets the event queue (not part of the library's pubilc API), must be already referenced before call
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 QoreStringNode * readHTTPHeaderString(ExceptionSink *xsink, int timeout_ms, int source=QORE_SOURCE_SOCKET)
read a HTTP header, caller owns QoreStringNode reference count returned
DLLEXPORT int sendi2(short i)
sends a 2-byte (16bit) binary integer in MSB (Most Significant Byte first, big endian,...
the implementation of Qore's object data type, reference counted, dynamically-allocated only
Definition: QoreObject.h:61
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,...
container for holding Qore-language exception information and also for registering a "thread_exit" ca...
Definition: ExceptionSink.h:48
DLLEXPORT int sendi1(char i)
sends a 1-byte binary integer data to a connected socket
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...
DLLEXPORT bool isWriteFinished(int timeout_ms=0) const
returns true if all write data has been written within the timeout period in milliseconds
DLLLOCAL Queue * getQueue()
returns the event queue (not part of the library's public API)
DLLEXPORT int getSslVerifyMode() const
returns the SSL verification mode
#define Q_SOCK_STREAM
platform-independent define for SOCK_STREAM
Definition: common.h:67
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 getSendTimeout() const
get send timeout in milliseconds
DLLEXPORT QoreSocket()
creates an empty, unconnected socket
DLLEXPORT bool isOpen() const
returns true if the socket is open
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 ~SocketSource()
destroys the object and frees all memory
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
DLLEXPORT int setSendTimeout(int ms)
set send timeout in milliseconds
DLLEXPORT int send(const char *buf, qore_size_t size)
sends binary data on a connected socket
provides thread-safe access to FTP servers through Qore data structures
Definition: QoreFtpClient.h:71
DLLEXPORT int sendi4(int i)
sends a 4-byte (32bit) binary integer in MSB (Most Significant Byte first, big endian,...
DLLEXPORT long verifyPeerCertificate() const
returns the peer certificate verification code if an SSL connection is in progress
DLLEXPORT int sendi2LSB(short i)
sends a 2-byte (16bit) binary integer in LSB (Least Significant Byte first, little endian) format thr...
DLLEXPORT void acceptAllCertificates(bool accept_all=true)
with peer verification enabled, all certificates are accepted regardless of the validity of the Certi...
DLLEXPORT int upgradeClientToSSL(X509 *cert, EVP_PKEY *pkey, ExceptionSink *xsink)
negotiates an SSL connection from the client side
DLLEXPORT bool pendingHttpChunkedBody() const
returns true if a HTTP header was read indicating chunked transfer encoding, but no chunked body has ...
DLLEXPORT int shutdown()
calls shutdown on the socket
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 int getSocket() const
returns the file descriptor associated with this 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 sendi8LSB(int64 i)
sends an 8-byte (64bit) binary integer in LSB (Least Significant Byte first, little endian) format th...
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...
base class for resolved call references
Definition: CallReferenceNode.h:105
DLLEXPORT int getPort()
returns the TCP port number, also assigns the interal port number if it must be discovered
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...
defines string encoding functions in Qore
Definition: QoreEncoding.h:83
holds arbitrary binary data
Definition: BinaryNode.h:41
Qore's string value type, reference counted, dynamically-allocated only.
Definition: QoreStringNode.h:50
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,...
The base class for all value and parse types in Qore expression trees.
Definition: AbstractQoreNode.h:54
DLLEXPORT QoreStringNode * takeAddress()
returns the host address string field and leaves the object's host address field empty; the caller ow...
DLLEXPORT int sendi8(int64 i)
sends an 8-byte (64bit) binary integer in MSB (Most Significant Byte first, big endian,...
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 bool isSecure() const
returns true if an SSL connection is active
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 ...
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 void setSslVerifyMode(int mode)
sets the SSL verification mode
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...
DLLEXPORT ~QoreSocket()
disconnects if necessary, frees all data, and destroys the socket
DLLEXPORT void setEncoding(const QoreEncoding *id)
sets the character encoding for strings sent and received with this socket
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...