provides access to sockets using Qore data structures More...
#include <QoreSocket.h>
Public Member Functions | |
DLLEXPORT | QoreSocket () |
creates an empty, unconnected socket | |
DLLEXPORT | ~QoreSocket () |
disconnects if necessary, frees all data, and destroys the socket | |
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 any errors | |
DLLEXPORT int | connect (const char *name, int timeout_ms, ExceptionSink *xsink=0) |
connects to a socket and returns a status code, Qore-language exceptions are raised in the case of any errors | |
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 exceptions are raised in the case of any errors | |
DLLEXPORT int | connectINET (const char *host, int prt, int timeout_ms, ExceptionSink *xsink=0) |
connects to an INET socket by hostname and port number and returns a status code, Qore-language exceptions are raised in the case of any errors | |
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 the case of any errors | |
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 exceptions are raised in the case of any errors | |
DLLEXPORT int | connectSSL (const char *name, int timeout_ms, X509 *cert, EVP_PKEY *pkey, ExceptionSink *xsink) |
connects to a socket, negotiates an SSL connection, and returns a status code, Qore-language exceptions are raised in the case of any errors | |
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 | connectINETSSL (const char *host, int prt, int timeout_ms, 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 | 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, Qore-language exceptions are raised in the case of any errors | |
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 int | bind (int prt, bool reuseaddr) |
binds to a TCP INET port on all interfaces and returns a status code | |
DLLEXPORT int | bind (const char *interface, int prt, bool reuseaddr=false) |
binds to a TCP INET port on the given interface and returns a status code | |
DLLEXPORT int | bind (const struct sockaddr *addr, int addr_size) |
binds an INET TCP socket to a specific socket address | |
DLLEXPORT int | getPort () |
returns the TCP port number, also assigns the interal port number if it must be discovered | |
DLLEXPORT QoreSocket * | accept (SocketSource *source, ExceptionSink *xsink) |
accepts a new connection on a listening socket and returns a new QoreSocket object for the new connection | |
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 QoreSocket object for the new connection | |
DLLEXPORT int | acceptAndReplace (SocketSource *source) |
accepts a new connection on a listening socket and replaces the current socket with the new connection | |
DLLEXPORT int | listen () |
sets an open socket to the listening state | |
DLLEXPORT int | send (const char *buf, qore_size_t size) |
sends binary data on a connected socket | |
DLLEXPORT int | send (const QoreString *msg, ExceptionSink *xsink) |
sends string data on a connected socket, converts the string encoding to the socket's encoding if necessary | |
DLLEXPORT int | send (const BinaryNode *msg) |
sends binary data on a connected socket | |
DLLEXPORT int | send (int fd, qore_offset_t size=-1) |
sends untranslated data from an open file descriptor | |
DLLEXPORT int | sendi1 (char i) |
sends a 1-byte binary integer data to a connected socket | |
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 | 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 | 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 | sendi2LSB (short i) |
sends a 2-byte (16bit) binary integer in LSB (Least Significant Byte first, little endian) format through a connected socket | |
DLLEXPORT int | sendi4LSB (int i) |
sends a 4-byte (32bit) binary integer in LSB (Least Significant Byte first, little endian) format through a connected socket | |
DLLEXPORT int | sendi8LSB (int64 i) |
sends an 8-byte (64bit) binary integer in LSB (Least Significant Byte first, little endian) format through a connected socket | |
DLLEXPORT int | recvi1 (int timeout, char *val) |
reads a 1-byte signed integer from the socket with a timeout value and returns the value read as an output parameter | |
DLLEXPORT int | recvi2 (int timeout, short *val) |
reads a 2-byte signed integer in MSB (Most Significant Byte first, big endian, network) format from the socket with a timeout value and returns the value read as an output parameter | |
DLLEXPORT int | recvi4 (int timeout, int *val) |
reads a 4-byte signed integer in MSB (Most Significant Byte first, big endian, network) format from the socket with a timeout value and returns the value read as an output parameter | |
DLLEXPORT int | recvi8 (int timeout, int64 *val) |
reads an 8-byte signed integer in MSB (Most Significant Byte first, big endian, network) format from the socket with a timeout value and returns the value read as an output parameter | |
DLLEXPORT int | recvi2LSB (int timeout, short *val) |
reads a 2-byte signed integer in LSB (Most Significant Byte first, little endian) format from the socket with a timeout value and returns the value read as an output parameter | |
DLLEXPORT int | recvi4LSB (int timeout, int *val) |
reads a 4-byte signed integer in LSB (Most Significant Byte first, little endian) format from the socket with a timeout value and returns the value read as an output parameter | |
DLLEXPORT int | recvi8LSB (int timeout, int64 *val) |
reads an 8-byte signed integer in LSB (Most Significant Byte first, little endian) format from the socket with a timeout value and returns the value read as an output parameter | |
DLLEXPORT int | recvu1 (int timeout, unsigned char *val) |
reads a 1-byte unsigned integer from the socket with a timeout value and returns the value read as an output parameter | |
DLLEXPORT int | recvu2 (int timeout, unsigned short *val) |
reads a 2-byte unsigned integer in MSB (Most Significant Byte first, big endian, network) format from the socket with a timeout value and returns the value read as an output parameter | |
DLLEXPORT int | recvu4 (int timeout, unsigned int *val) |
reads a 4-byte unsigned integer in MSB (Most Significant Byte first, big endian, network) format from the socket with a timeout value and returns the value read as an output parameter | |
DLLEXPORT int | recvu2LSB (int timeout, unsigned short *val) |
reads a 2-byte unsigned integer in LSB (Most Significant Byte first, little endian) format from the socket with a timeout value and returns the value read as an output parameter | |
DLLEXPORT int | recvu4LSB (int timeout, unsigned int *val) |
reads a 4-byte unsigned integer in LSB (Most Significant Byte first, little endian) format from the socket with a timeout value and returns the value read as an output parameter | |
DLLEXPORT QoreStringNode * | recv (qore_offset_t bufsize, int timeout, int *prc) |
receive a certain number of bytes with a timeout value and return a QoreStringNode, caller owns the reference count returned | |
DLLEXPORT BinaryNode * | recvBinary (qore_offset_t bufsize, int timeout, int *prc) |
receive a certain number of bytes with a timeout value and return a BinaryNode, caller owns the reference count returned | |
DLLEXPORT QoreStringNode * | recv (int timeout, int *prc) |
receive with a timeout value and return a QoreStringNode, caller owns the reference count returned | |
DLLEXPORT BinaryNode * | recvBinary (int timeout, int *prc) |
receive with a timeout value and return a BinaryNode, caller owns the reference count returned | |
DLLEXPORT int | recv (int fd, qore_offset_t size, int timeout) |
receive data on the socket and write it to a file descriptor | |
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 | 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) |
send an HTTP request message on the socket | |
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 AbstractQoreNode * | readHTTPHeader (int timeout, int *prc, int source=QORE_SOURCE_SOCKET) |
read and parse HTTP header, caller owns AbstractQoreNode reference count returned | |
DLLEXPORT AbstractQoreNode * | readHTTPHeader (QoreHashNode *info, int timeout, int *prc, int source=QORE_SOURCE_SOCKET) |
read and parse HTTP header, caller owns AbstractQoreNode reference count returned | |
DLLEXPORT QoreHashNode * | readHTTPChunkedBodyBinary (int timeout, ExceptionSink *xsink, int source=QORE_SOURCE_SOCKET) |
receive a binary message in HTTP chunked transfer encoding, caller owns QoreHashNode reference count returned | |
DLLEXPORT QoreHashNode * | readHTTPChunkedBody (int timeout, ExceptionSink *xsink, int source=QORE_SOURCE_SOCKET) |
receive a string message in HTTP chunked transfer encoding, caller owns QoreHashNode reference count returned | |
DLLEXPORT int | setSendTimeout (int ms) |
set send timeout in milliseconds | |
DLLEXPORT int | setRecvTimeout (int ms) |
set recv timeout in milliseconds | |
DLLEXPORT int | getSendTimeout () const |
get send timeout in milliseconds | |
DLLEXPORT int | getRecvTimeout () const |
get recv timeout in milliseconds | |
DLLEXPORT bool | isDataAvailable (int timeout=0) const |
returns true if data is available on the socket in the timeout period in milliseconds | |
DLLEXPORT int | close () |
closes the socket | |
DLLEXPORT int | shutdown () |
calls shutdown on the socket | |
DLLEXPORT int | shutdownSSL (ExceptionSink *xsink) |
shuts down an active SSL connection | |
DLLEXPORT int | getSocket () const |
returns the file descriptor associated with this socket | |
DLLEXPORT const QoreEncoding * | getEncoding () const |
returns the character encoding associated with this socket | |
DLLEXPORT void | setEncoding (const QoreEncoding *id) |
sets the character encoding for strings sent and received with this socket | |
DLLEXPORT bool | isOpen () const |
returns true if the socket is open | |
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 const char * | getSSLCipherVersion () const |
returns the version string of the SSL Cipher for the currently-connected control connection, or 0 if there is none | |
DLLEXPORT bool | isSecure () const |
returns true if an SSL connection is active | |
DLLEXPORT long | verifyPeerCertificate () const |
returns the peer certificate verification code if an SSL connection is in progress | |
DLLEXPORT int | upgradeClientToSSL (X509 *cert, EVP_PKEY *pkey, ExceptionSink *xsink) |
negotiates an SSL connection from the client side | |
DLLEXPORT int | upgradeServerToSSL (X509 *cert, EVP_PKEY *pkey, ExceptionSink *xsink) |
negotiates an SSL connection from the client side | |
DLLEXPORT bool | isWriteFinished (int timeout=0) const |
returns true if all write data has been written within the timeout period in milliseconds | |
DLLLOCAL void | setEventQueue (Queue *cbq, ExceptionSink *xsink) |
sets the event queue (not part of the library's pubilc API), must be already referenced before call | |
DLLLOCAL Queue * | getQueue () |
returns the event queue (not part of the library's public API) | |
DLLLOCAL int64 | getObjectIDForEvents () const |
returns a unique ID for the socket to be used in event messages | |
DLLLOCAL void | cleanup (ExceptionSink *xsink) |
posts deleted message and removes any event queue |
provides access to sockets using Qore data structures
QoreSocket objects also have a QoreEncoding associated with them used for sending and receiving string data. String data received from the socket will be tagged with the appropriate encoding; string data send through the socket will be implicitly converted to the socket's encoding if necessary. This class does no implement any thread locking; thread locking must be performed at a higher level (for example, as with QoreHTTPClient and QoreFtpClient).
DLLEXPORT QoreSocket* QoreSocket::accept | ( | SocketSource * | source, | |
ExceptionSink * | xsink | |||
) |
accepts a new connection on a listening socket and returns a new QoreSocket object for the new connection
the socket must be opened and in a listening state before making this call.
source | source connection information will be written to this object if not 0 | |
xsink | if an error occurs, the Qore-language exception information will be added here |
DLLEXPORT int QoreSocket::acceptAndReplace | ( | SocketSource * | source | ) |
accepts a new connection on a listening socket and replaces the current socket with the new connection
the socket must be opened and in a listening state before making this call.
source | source connection information will be written to this object if not 0 |
DLLEXPORT QoreSocket* 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 QoreSocket object for the new connection
the socket must be opened and in a listening state before making this call.
source | source connection information will be written to this object if not 0 | |
cert | the X509 certificate to use for the connection, may be 0 if no certificate should be used | |
pkey | the private key to use for the connection, may be 0 if no private key should be used | |
xsink | if an error occurs, the Qore-language exception information will be added here |
DLLEXPORT int QoreSocket::bind | ( | const struct sockaddr * | addr, | |
int | addr_size | |||
) |
binds an INET TCP socket to a specific socket address
addr | the socket address to bind to | |
addr_size | the size of the addr argument |
DLLEXPORT int QoreSocket::bind | ( | const char * | interface, | |
int | prt, | |||
bool | reuseaddr = false | |||
) |
binds to a TCP INET port on the given interface and returns a status code
interface | the interface to bind to (hostname or IP address) | |
prt | the port to bind to | |
reuseaddr | if true then setsockopt() will be called with SO_REUSEADDR, allowing the bind to succeed even if the port is still in a TIME_WAIT state, for example |
DLLEXPORT int QoreSocket::bind | ( | int | prt, | |
bool | reuseaddr | |||
) |
binds to a TCP INET port on all interfaces and returns a status code
prt | the port to bind to | |
reuseaddr | if true then setsockopt() will be called with SO_REUSEADDR, allowing the bind to succeed even if the port is still in a TIME_WAIT state, for example |
DLLEXPORT int QoreSocket::bind | ( | const char * | name, | |
bool | reuseaddr = false | |||
) |
binds to a UNIX domain socket or INET interface:port using TCP and returns a status code
If "name" has a ':' in it; it's assumed to be a address:port specification for binding to an INET socket, otherwise "name" is assumed to be a file name for a UNIX domain socket.
name | address:port or filename to bind to | |
reuseaddr | if true then setsockopt() will be called with SO_REUSEADDR, allowing the bind to succeed even if the port is still in a TIME_WAIT state, for example |
DLLEXPORT int QoreSocket::close | ( | ) |
closes the socket
Deletes the socket file if it was a UNIX domain socket and was created with the QoreSocket::bind() call. Also implicitly calls QoreSocket::shutdownSSL() if an SSL connection is active.
DLLEXPORT int QoreSocket::connect | ( | const char * | name, | |
int | timeout_ms, | |||
ExceptionSink * | xsink = 0 | |||
) |
connects to a socket and returns a status code, Qore-language exceptions are raised in the case of any errors
If "name" has a ':' in it; it's assumed to be a hostname:port specification and QoreSocket::connectINET() is called. Otherwise "name" is assumed to be a file name for a UNIX domain socket and QoreSocket::connectUNIX() is called.
name | the name of the socket (either hostname:port or file name) | |
timeout_ms | the timeout period in milliseconds | |
xsink | if not 0, if an error occurs, the Qore-language exception information will be added here |
DLLEXPORT int QoreSocket::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 any errors
If "name" has a ':' in it; it's assumed to be a hostname:port specification and QoreSocket::connectINET() is called. Otherwise "name" is assumed to be a file name for a UNIX domain socket and QoreSocket::connectUNIX() is called.
name | the name of the socket (either hostname:port or file name) | |
xsink | if not 0, if an error occurs, the Qore-language exception information will be added here |
DLLEXPORT int QoreSocket::connectINET | ( | const char * | host, | |
int | prt, | |||
int | timeout_ms, | |||
ExceptionSink * | xsink = 0 | |||
) |
connects to an INET socket by hostname and port number and returns a status code, Qore-language exceptions are raised in the case of any errors
host | the name or IP address of the host | |
prt | the port number of the remote socket | |
timeout_ms | the timeout period in milliseconds | |
xsink | if not 0, if an error occurs, the Qore-language exception information will be added here |
DLLEXPORT int QoreSocket::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 exceptions are raised in the case of any errors
host | the name or IP address of the host | |
prt | the port number of the remote socket | |
xsink | if not 0, if an error occurs, the Qore-language exception information will be added here |
DLLEXPORT int QoreSocket::connectINETSSL | ( | const char * | host, | |
int | prt, | |||
int | timeout_ms, | |||
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
host | the name or IP address of the host | |
prt | the port number of the remote socket | |
timeout_ms | the timeout period in milliseconds | |
cert | the X509 certificate to use for the connection, may be 0 if no certificate should be used | |
pkey | the private key to use for the connection, may be 0 if no private key should be used | |
xsink | if an error occurs, the Qore-language exception information will be added here |
DLLEXPORT int QoreSocket::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
host | the name or IP address of the host | |
prt | the port number of the remote socket | |
cert | the X509 certificate to use for the connection, may be 0 if no certificate should be used | |
pkey | the private key to use for the connection, may be 0 if no private key should be used | |
xsink | if an error occurs, the Qore-language exception information will be added here |
DLLEXPORT int QoreSocket::connectSSL | ( | const char * | name, | |
int | timeout_ms, | |||
X509 * | cert, | |||
EVP_PKEY * | pkey, | |||
ExceptionSink * | xsink | |||
) |
connects to a socket, negotiates an SSL connection, and returns a status code, Qore-language exceptions are raised in the case of any errors
If "name" has a ':' in it; it's assumed to be a hostname:port specification and QoreSocket::connectINETSSL() is called. Otherwise "name" is assumed to be a file name for a UNIX domain socket and QoreSocket::connectUNIXSSL() is called.
name | the name of the socket (either hostname:port or file name) | |
timeout_ms | the timeout period in milliseconds | |
cert | the X509 certificate to use for the connection, may be 0 if no certificate should be used | |
pkey | the private key to use for the connection, may be 0 if no private key should be used | |
xsink | if an error occurs, the Qore-language exception information will be added here |
DLLEXPORT int QoreSocket::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 exceptions are raised in the case of any errors
If "name" has a ':' in it; it's assumed to be a hostname:port specification and QoreSocket::connectINETSSL() is called. Otherwise "name" is assumed to be a file name for a UNIX domain socket and QoreSocket::connectUNIXSSL() is called.
name | the name of the socket (either hostname:port or file name) | |
cert | the X509 certificate to use for the connection, may be 0 if no certificate should be used | |
pkey | the private key to use for the connection, may be 0 if no private key should be used | |
xsink | if an error occurs, the Qore-language exception information will be added here |
DLLEXPORT int QoreSocket::connectUNIX | ( | const char * | p, | |
ExceptionSink * | xsink = 0 | |||
) |
connects to a UNIX domain socket and returns a status code, Qore-language exceptions are raised in the case of any errors
p | the file name of the UNIX domain socket | |
xsink | if not 0, if an error occurs, the Qore-language exception information will be added here |
DLLEXPORT int QoreSocket::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, Qore-language exceptions are raised in the case of any errors
p | the file name of the UNIX domain socket | |
cert | the X509 certificate to use for the connection, may be 0 if no certificate should be used | |
pkey | the private key to use for the connection, may be 0 if no private key should be used | |
xsink | if not 0, if an error occurs, the Qore-language exception information will be added here |
DLLEXPORT const QoreEncoding* QoreSocket::getEncoding | ( | ) | const |
returns the character encoding associated with this socket
DLLEXPORT int QoreSocket::getSocket | ( | ) | const |
returns the file descriptor associated with this socket
DLLEXPORT const char* QoreSocket::getSSLCipherName | ( | ) | const |
returns the name of the SSL Cipher for the currently-connected control connection, or 0 if there is none
DLLEXPORT const char* QoreSocket::getSSLCipherVersion | ( | ) | const |
returns the version string of the SSL Cipher for the currently-connected control connection, or 0 if there is none
DLLEXPORT bool QoreSocket::isDataAvailable | ( | int | timeout = 0 |
) | const |
returns true if data is available on the socket in the timeout period in milliseconds
The socket must be connected before this call is made. use a timeout of 0 to see if there is any data available on the socket
timeout | in milliseconds, -1=never timeout, 0=do not block, return immediately if there is no data waiting |
DLLEXPORT bool QoreSocket::isOpen | ( | ) | const |
returns true if the socket is open
DLLEXPORT bool QoreSocket::isSecure | ( | ) | const |
returns true if an SSL connection is active
DLLEXPORT bool QoreSocket::isWriteFinished | ( | int | timeout = 0 |
) | const |
returns true if all write data has been written within the timeout period in milliseconds
The socket must be connected before this call is made. use a timeout of 0 to receive an answer immediately
timeout | in milliseconds, -1=never timeout, 0=do not block, return immediately if there is no data waiting |
DLLEXPORT int QoreSocket::listen | ( | ) |
sets an open socket to the listening state
DLLEXPORT QoreHashNode* QoreSocket::readHTTPChunkedBody | ( | int | timeout, | |
ExceptionSink * | xsink, | |||
int | source = QORE_SOURCE_SOCKET | |||
) |
receive a string message in HTTP chunked transfer encoding, caller owns QoreHashNode reference count returned
The socket must be connected before this call is made. The message body is returned as a QoreStringNode in the "body" key, any footers read after the body are returned as the other hash keys in the hash.
timeout | in milliseconds, -1=never timeout, 0=do not block, return immediately if there is no data waiting | |
xsink | if an error occurs, the Qore-language exception information will be added here | |
source | the event source code for socket events |
DLLEXPORT QoreHashNode* QoreSocket::readHTTPChunkedBodyBinary | ( | int | timeout, | |
ExceptionSink * | xsink, | |||
int | source = QORE_SOURCE_SOCKET | |||
) |
receive a binary message in HTTP chunked transfer encoding, caller owns QoreHashNode reference count returned
The socket must be connected before this call is made. The message body is returned as a BinaryNode in the "body" key, any footers read after the body are returned as the other hash keys in the hash.
timeout | in milliseconds, -1=never timeout, 0=do not block, return immediately if there is no data waiting | |
xsink | if an error occurs, the Qore-language exception information will be added here | |
source | the event source code for socket events |
DLLEXPORT AbstractQoreNode* QoreSocket::readHTTPHeader | ( | QoreHashNode * | info, | |
int | timeout, | |||
int * | prc, | |||
int | source = QORE_SOURCE_SOCKET | |||
) |
read and parse HTTP header, caller owns AbstractQoreNode reference count returned
The socket must be connected before this call is made.
info | the request-uri or response-uri is written to this hash if non-null; neither of these keys should be present in the hash before the call | |
timeout | in milliseconds, -1=never timeout, 0=do not block, return immediately if there is no data waiting | |
prc | output parameter: 0 or -2: remote end closed the connection, -1: receive error, -3: timeout | |
source | the event source code for socket events |
DLLEXPORT AbstractQoreNode* QoreSocket::readHTTPHeader | ( | int | timeout, | |
int * | prc, | |||
int | source = QORE_SOURCE_SOCKET | |||
) |
read and parse HTTP header, caller owns AbstractQoreNode reference count returned
The socket must be connected before this call is made.
timeout | in milliseconds, -1=never timeout, 0=do not block, return immediately if there is no data waiting | |
prc | output parameter: 0 or -2: remote end closed the connection, -1: receive error, -3: timeout | |
source | the event source code for socket events |
DLLEXPORT int QoreSocket::recv | ( | int | fd, | |
qore_offset_t | size, | |||
int | timeout | |||
) |
receive data on the socket and write it to a file descriptor
The socket must be connected before this call is made.
fd | the file descriptor to write to, must be already opened for writing | |
size | the number of bytes to read from the socket, -1 to read until the socket is closed | |
timeout | in milliseconds, -1=never timeout, 0=do not block, return immediately if there is no data waiting |
DLLEXPORT QoreStringNode* QoreSocket::recv | ( | int | timeout, | |
int * | prc | |||
) |
receive with a timeout value and return a QoreStringNode, caller owns the reference count returned
The socket must be connected before this call is made. This call will read data, blocking according to the timeout value. Then all data available on the socket will be read and returned as a QoreStringNode. As soon as the first timeout occurs, the data will be returned immediately without blocking.
timeout | in milliseconds, -1=never timeout, 0=do not block, return immediately if there is no data waiting | |
prc | output parameter: 0 for OK, not 0 for error |
DLLEXPORT QoreStringNode* QoreSocket::recv | ( | qore_offset_t | bufsize, | |
int | timeout, | |||
int * | prc | |||
) |
receive a certain number of bytes with a timeout value and return a QoreStringNode, caller owns the reference count returned
The socket must be connected before this call is made.
bufsize | number of bytes to read from the socket; if <= 0, read all data available from the socket until the socket is closed from the other side | |
timeout | in milliseconds, -1=never timeout, 0=do not block, return immediately if there is no data waiting | |
prc | output parameter: 0 for OK, not 0 for error |
DLLEXPORT BinaryNode* QoreSocket::recvBinary | ( | int | timeout, | |
int * | prc | |||
) |
receive with a timeout value and return a BinaryNode, caller owns the reference count returned
The socket must be connected before this call is made. This call will read data, blocking according to the timeout value. Then all data available on the socket will be read and returned as a BinaryNode. As soon as the first timeout occurs, the data will be returned immediately without blocking.
timeout | in milliseconds, -1=never timeout, 0=do not block, return immediately if there is no data waiting | |
prc | output parameter: 0 for OK, not 0 for error |
DLLEXPORT BinaryNode* QoreSocket::recvBinary | ( | qore_offset_t | bufsize, | |
int | timeout, | |||
int * | prc | |||
) |
receive a certain number of bytes with a timeout value and return a BinaryNode, caller owns the reference count returned
The socket must be connected before this call is made.
bufsize | number of bytes to read from the socket; if <= 0, read all data available from the socket until the socket is closed from the other side | |
timeout | in milliseconds, -1=never timeout, 0=do not block, return immediately if there is no data waiting | |
prc | output parameter: 0 for OK, not 0 for error |
DLLEXPORT int QoreSocket::recvi1 | ( | int | timeout, | |
char * | val | |||
) |
reads a 1-byte signed integer from the socket with a timeout value and returns the value read as an output parameter
The socket must be connected before this call is made.
timeout | in milliseconds, -1=never timeout, 0=do not block, return immediately if there is no data waiting | |
val | output parameter: the integer value read from the file |
DLLEXPORT int QoreSocket::recvi2 | ( | int | timeout, | |
short * | val | |||
) |
reads a 2-byte signed integer in MSB (Most Significant Byte first, big endian, network) format from the socket with a timeout value and returns the value read as an output parameter
The socket must be connected before this call is made.
timeout | in milliseconds, -1=never timeout, 0=do not block, return immediately if there is no data waiting | |
val | output parameter: the integer value read from the file |
DLLEXPORT int QoreSocket::recvi2LSB | ( | int | timeout, | |
short * | val | |||
) |
reads a 2-byte signed integer in LSB (Most Significant Byte first, little endian) format from the socket with a timeout value and returns the value read as an output parameter
The socket must be connected before this call is made.
timeout | in milliseconds, -1=never timeout, 0=do not block, return immediately if there is no data waiting | |
val | output parameter: the integer value read from the file |
DLLEXPORT int QoreSocket::recvi4 | ( | int | timeout, | |
int * | val | |||
) |
reads a 4-byte signed integer in MSB (Most Significant Byte first, big endian, network) format from the socket with a timeout value and returns the value read as an output parameter
The socket must be connected before this call is made.
timeout | in milliseconds, -1=never timeout, 0=do not block, return immediately if there is no data waiting | |
val | output parameter: the integer value read from the file |
DLLEXPORT int QoreSocket::recvi4LSB | ( | int | timeout, | |
int * | val | |||
) |
reads a 4-byte signed integer in LSB (Most Significant Byte first, little endian) format from the socket with a timeout value and returns the value read as an output parameter
The socket must be connected before this call is made.
timeout | in milliseconds, -1=never timeout, 0=do not block, return immediately if there is no data waiting | |
val | output parameter: the integer value read from the file |
DLLEXPORT int QoreSocket::recvi8 | ( | int | timeout, | |
int64 * | val | |||
) |
reads an 8-byte signed integer in MSB (Most Significant Byte first, big endian, network) format from the socket with a timeout value and returns the value read as an output parameter
The socket must be connected before this call is made.
timeout | in milliseconds, -1=never timeout, 0=do not block, return immediately if there is no data waiting | |
val | output parameter: the integer value read from the file |
DLLEXPORT int QoreSocket::recvi8LSB | ( | int | timeout, | |
int64 * | val | |||
) |
reads an 8-byte signed integer in LSB (Most Significant Byte first, little endian) format from the socket with a timeout value and returns the value read as an output parameter
The socket must be connected before this call is made.
timeout | in milliseconds, -1=never timeout, 0=do not block, return immediately if there is no data waiting | |
val | output parameter: the integer value read from the file |
DLLEXPORT int QoreSocket::recvu1 | ( | int | timeout, | |
unsigned char * | val | |||
) |
reads a 1-byte unsigned integer from the socket with a timeout value and returns the value read as an output parameter
The socket must be connected before this call is made.
timeout | in milliseconds, -1=never timeout, 0=do not block, return immediately if there is no data waiting | |
val | output parameter: the integer value read from the file |
DLLEXPORT int QoreSocket::recvu2 | ( | int | timeout, | |
unsigned short * | val | |||
) |
reads a 2-byte unsigned integer in MSB (Most Significant Byte first, big endian, network) format from the socket with a timeout value and returns the value read as an output parameter
The socket must be connected before this call is made.
timeout | in milliseconds, -1=never timeout, 0=do not block, return immediately if there is no data waiting | |
val | output parameter: the integer value read from the file |
DLLEXPORT int QoreSocket::recvu2LSB | ( | int | timeout, | |
unsigned short * | val | |||
) |
reads a 2-byte unsigned integer in LSB (Most Significant Byte first, little endian) format from the socket with a timeout value and returns the value read as an output parameter
The socket must be connected before this call is made.
timeout | in milliseconds, -1=never timeout, 0=do not block, return immediately if there is no data waiting | |
val | output parameter: the integer value read from the file |
DLLEXPORT int QoreSocket::recvu4 | ( | int | timeout, | |
unsigned int * | val | |||
) |
reads a 4-byte unsigned integer in MSB (Most Significant Byte first, big endian, network) format from the socket with a timeout value and returns the value read as an output parameter
The socket must be connected before this call is made.
timeout | in milliseconds, -1=never timeout, 0=do not block, return immediately if there is no data waiting | |
val | output parameter: the integer value read from the file |
DLLEXPORT int QoreSocket::recvu4LSB | ( | int | timeout, | |
unsigned int * | val | |||
) |
reads a 4-byte unsigned integer in LSB (Most Significant Byte first, little endian) format from the socket with a timeout value and returns the value read as an output parameter
The socket must be connected before this call is made.
timeout | in milliseconds, -1=never timeout, 0=do not block, return immediately if there is no data waiting | |
val | output parameter: the integer value read from the file |
DLLEXPORT int QoreSocket::send | ( | int | fd, | |
qore_offset_t | size = -1 | |||
) |
sends untranslated data from an open file descriptor
fd | a file descriptor, open for reading | |
size | the number of bytes to send (-1 = send all until EOF) |
DLLEXPORT int QoreSocket::send | ( | const BinaryNode * | msg | ) |
sends binary data on a connected socket
msg | the data to send |
DLLEXPORT int QoreSocket::send | ( | const QoreString * | msg, | |
ExceptionSink * | xsink | |||
) |
sends string data on a connected socket, converts the string encoding to the socket's encoding if necessary
msg | the string to send (must not be 0) | |
xsink | if an error occurs in converting the string's character encoding, the Qore-language exception information will be added here |
DLLEXPORT int QoreSocket::send | ( | const char * | buf, | |
qore_size_t | size | |||
) |
sends binary data on a connected socket
buf | the data to send | |
size | the size of the data to send |
DLLEXPORT int QoreSocket::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 | |||
) |
send an HTTP request message on the socket
The socket must be connected before this call is made.
info | if not null, the request-uri and response-uri will be written to this hash, neither of these keys should be set before this call | |
method | the method string to use in the header - no validity checking is made on this string | |
path | the path string to use in the header, if the path is empty then '/' is sent | |
http_version | should be either "1.0" or "1.1" | |
headers | a hash of headers to send (key: value) | |
data | optional message body to send (may be 0) | |
size | the length of the message body (may be 0) | |
source | the event source code for socket events |
DLLEXPORT int QoreSocket::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
The socket must be connected before this call is made.
method | the method string to use in the header - no validity checking is made on this string | |
path | the path string to use in the header, if the path is empty then '/' is sent | |
http_version | should be either "1.0" or "1.1" | |
headers | a hash of headers to send (key: value) | |
data | optional message body to send (may be 0) | |
size | the length of the message body (may be 0) | |
source | the event source code for socket events |
DLLEXPORT int QoreSocket::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
The socket must be connected before this call is made.
code | the HTTP response code | |
desc | the text description for the response code | |
http_version | should be either "1.0" or "1.1" | |
headers | a hash of headers to send (key: value) | |
data | optional message body to send (may be 0) | |
size | the length of the message body (may be 0) | |
source | the event source code for socket events |
DLLEXPORT int QoreSocket::sendi1 | ( | char | i | ) |
sends a 1-byte binary integer data to a connected socket
The socket must be connected before this call is made.
i | the 1-byte integer to send through the socket |
DLLEXPORT int QoreSocket::sendi2 | ( | short | i | ) |
sends a 2-byte (16bit) binary integer in MSB (Most Significant Byte first, big endian, network) format through a connected socket
The socket must be connected before this call is made.
i | the integer to write to the file |
DLLEXPORT int QoreSocket::sendi2LSB | ( | short | i | ) |
sends a 2-byte (16bit) binary integer in LSB (Least Significant Byte first, little endian) format through a connected socket
The socket must be connected before this call is made.
i | the integer to write to the file |
DLLEXPORT int QoreSocket::sendi4 | ( | int | i | ) |
sends a 4-byte (32bit) binary integer in MSB (Most Significant Byte first, big endian, network) format through a connected socket
The socket must be connected before this call is made.
i | the integer to write to the file |
DLLEXPORT int QoreSocket::sendi4LSB | ( | int | i | ) |
sends a 4-byte (32bit) binary integer in LSB (Least Significant Byte first, little endian) format through a connected socket
The socket must be connected before this call is made.
i | the integer to write to the file |
DLLEXPORT int QoreSocket::sendi8 | ( | int64 | i | ) |
sends an 8-byte (64bit) binary integer in MSB (Most Significant Byte first, big endian, network) format through a connected socket
The socket must be connected before this call is made.
i | the integer to write to the file |
DLLEXPORT int QoreSocket::sendi8LSB | ( | int64 | i | ) |
sends an 8-byte (64bit) binary integer in LSB (Least Significant Byte first, little endian) format through a connected socket
The socket must be connected before this call is made.
i | the integer to write to the file |
DLLEXPORT void QoreSocket::setEncoding | ( | const QoreEncoding * | id | ) |
sets the character encoding for strings sent and received with this socket
id | the character encoding for strings sent and received with this socket |
DLLEXPORT int QoreSocket::shutdown | ( | ) |
calls shutdown on the socket
shuts down the socket for reading and writing, after this call further sends and receives are disallowed until the socket is reopened.
DLLEXPORT int QoreSocket::shutdownSSL | ( | ExceptionSink * | xsink | ) |
shuts down an active SSL connection
called implicitly by QoreSocket::close()
DLLEXPORT int QoreSocket::upgradeClientToSSL | ( | X509 * | cert, | |
EVP_PKEY * | pkey, | |||
ExceptionSink * | xsink | |||
) |
negotiates an SSL connection from the client side
The socket must be connected before this call is made.
cert | the X509 certificate to use for the connection, may be 0 if no certificate should be used | |
pkey | the private key to use for the connection, may be 0 if no private key should be used | |
xsink | if an error occurs, the Qore-language exception information will be added here |
DLLEXPORT int QoreSocket::upgradeServerToSSL | ( | X509 * | cert, | |
EVP_PKEY * | pkey, | |||
ExceptionSink * | xsink | |||
) |
negotiates an SSL connection from the client side
The socket must be connected before this call is made.
cert | the X509 certificate to use for the connection, may be 0 if no certificate should be used | |
pkey | the private key to use for the connection, may be 0 if no private key should be used | |
xsink | if an error occurs, the Qore-language exception information will be added here |