All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
QoreSocket Class Reference

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 | 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 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 | connectUNIX (const char *p, int socktype, int protocol=0, 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 | 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 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 | connectUNIXSSL (const char *p, int socktype, int protocol, 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 (ipv4 only) port on all interfaces and returns a status code
DLLEXPORT int | bind (const char *iface, int prt, bool reuseaddr=false)
| binds to a TCP INET (ipv4 only) 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 - do not use, deprecated, use bind(int family, const struct sockaddr *addr, int addr_size, int socktype, int protocol) instead
DLLEXPORT int | bind (int family, const struct sockaddr *addr, int addr_size, int socktype=Q_SOCK_STREAM, int protocol=0)
| binds an INET or INET6 TCP socket to a specific socket address
DLLEXPORT int | bindUNIX (const char *name, ExceptionSink *xsink=0)
| binds to a UNIX domain socket and returns a status code
DLLEXPORT int | bindUNIX (const char *name, int socktype, int protocol=0, ExceptionSink *xsink=0)
| binds to a UNIX domain socket and returns a status code
DLLEXPORT int | bindINET (const char *name, const char *service, bool reuseaddr=true, int family=Q_AF_UNSPEC, int socktype=Q_SOCK_STREAM, int protocol=0, ExceptionSink *xsink=0)
| binds an INET or INET6 TCP socket to a specific socket address
DLLEXPORT int | 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 QoreSocket * | accept (int timeout_ms, ExceptionSink *xsink)
| accepts a new connection on a listening socket and returns a new QoreSocket object for the new connection with a timeout; if no connection is accepted within the timeout period 0 is returned
DLLEXPORT QoreSocket * | acceptSSL (int timeout_ms, 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 with a timeout; if no connection is accepted within the timeout period 0 is returned
DLLEXPORT int | acceptAndReplace (int timeout_ms, ExceptionSink *xsink)
| accepts a new connection on a listening socket and replaces the current socket with the new connection with a timeout; if no connection is accepted within the timeout period, -3 (QSE_TIMEOUT) is returned
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 char *buf, qore_size_t size, ExceptionSink *xsink)
| sends binary data on a connected socket
DLLEXPORT int | send (const char *buf, qore_size_t size, int timeout_ms, ExceptionSink *xsink)
| 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 QoreString *msg, int timeout_ms, 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 (const BinaryNode *msg, ExceptionSink *xsink)
| sends binary data on a connected socket
DLLEXPORT int | send (const BinaryNode *msg, int timeout_ms, ExceptionSink *xsink)
| 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 | sendi1 (char i, int timeout_ms, ExceptionSink *xsink)
| sends a 1-byte binary integer data to a connected socket
DLLEXPORT int | sendi2 (short i, int timeout_ms, ExceptionSink *xsink)
| 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, int timeout_ms, ExceptionSink *xsink)
| 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, int timeout_ms, ExceptionSink *xsink)
| 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, int timeout_ms, ExceptionSink *xsink)
| 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, int timeout_ms, ExceptionSink *xsink)
| 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, int timeout_ms, ExceptionSink *xsink)
| 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_ms, 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_ms, 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_ms, 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_ms, 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_ms, 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_ms, 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_ms, 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_ms, 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_ms, 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_ms, 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_ms, 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_ms, 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 int64 | recvi1 (int timeout_ms, char *val, ExceptionSink *xsink)
| reads a 1-byte signed integer from the socket with a timeout value and returns the value read as an output parameter
DLLEXPORT int64 | recvi2 (int timeout_ms, short *val, ExceptionSink *xsink)
| 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 int64 | recvi4 (int timeout_ms, int *val, ExceptionSink *xsink)
| 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 int64 | recvi8 (int timeout_ms, int64 *val, ExceptionSink *xsink)
| 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 int64 | recvi2LSB (int timeout_ms, short *val, ExceptionSink *xsink)
| 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 int64 | recvi4LSB (int timeout_ms, int *val, ExceptionSink *xsink)
| 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 int64 | recvi8LSB (int timeout_ms, int64 *val, ExceptionSink *xsink)
| 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 int64 | recvu1 (int timeout_ms, unsigned char *val, ExceptionSink *xsink)
| reads a 1-byte unsigned integer from the socket with a timeout value and returns the value read as an output parameter
DLLEXPORT int64 | recvu2 (int timeout_ms, unsigned short *val, ExceptionSink *xsink)
| 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 int64 | recvu4 (int timeout_ms, unsigned int *val, ExceptionSink *xsink)
| 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 int64 | recvu2LSB (int timeout_ms, unsigned short *val, ExceptionSink *xsink)
| 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 int64 | recvu4LSB (int timeout_ms, unsigned int *val, ExceptionSink *xsink)
| 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_ms, int *prc)
| receive a certain number of bytes with a timeout value and return a QoreStringNode, caller owns the reference count returned
DLLEXPORT QoreStringNode * | recv (qore_offset_t bufsize, int timeout_ms, ExceptionSink *xsink)
| 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_ms, int *prc)
| receive a certain number of bytes with a timeout value and return a BinaryNode, caller owns the reference count returned
DLLEXPORT BinaryNode * | recvBinary (qore_offset_t bufsize, int timeout_ms, ExceptionSink *xsink)
| 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_ms, int *prc)
| receive with a timeout value and return a QoreStringNode, caller owns the reference count returned
DLLEXPORT QoreStringNode * | recv (int timeout_ms, ExceptionSink *xsink)
| receive with a timeout value and return a QoreStringNode, caller owns the reference count returned
DLLEXPORT BinaryNode * | recvBinary (int timeout_ms, int *prc)
| receive with a timeout value and return a BinaryNode, caller owns the reference count returned
DLLEXPORT BinaryNode * | recvBinary (int timeout_ms, ExceptionSink *xsink)
| 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_ms)
| 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 | 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)
| send an HTTP request message on the 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)
| send an HTTP request message on the socket with a timeout value
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 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)
| send an HTTP response message on the 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)
| send an HTTP response message on the socket
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 AbstractQoreNode * | readHTTPHeader (QoreHashNode *info, int timeout_ms, int *prc, int source=QORE_SOURCE_SOCKET)
| read and parse HTTP header, caller owns AbstractQoreNode reference count returned
DLLEXPORT QoreHashNode * | readHTTPHeader (ExceptionSink *xsink, QoreHashNode *info, int timeout_ms, int source=QORE_SOURCE_SOCKET)
| read and parse HTTP header, caller owns QoreHashNode reference count returned
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 returned
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 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_ms=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_ms=0) const
| returns true if all write data has been written within the timeout period in milliseconds
DLLEXPORT QoreHashNode * | getPeerInfo (ExceptionSink *xsink) const
| returns peer information for a connected socket
DLLEXPORT QoreHashNode * | getSocketInfo (ExceptionSink *xsink) const
| returns information for the current socket; the socket must be open
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
DLLLOCAL void | setAccept (QoreObject *o)
| sets backwards-compatible members on accept in a new object - will be removed in a future version of qore

## Detailed Description

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).

Note
  currently only supports IPv4, TCP sockets

See Also
  QoreEncoding

## Member Function Documentation

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.

Parameters

  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

Returns
  a new QoreSocket object for the new connection (or 0 if an error occured)

See Also
  - QoreSocket::listen()
  - QoreSocket::acceptSSL()
  - SocketSource

DLLEXPORT QoreSocket* QoreSocket::accept | ( | int | timeout_ms,
|  | ExceptionSink * | xsink
| ) |  |

accepts a new connection on a listening socket and returns a new QoreSocket object for the new connection with a timeout; if no connection is accepted within the timeout period 0 is returned

the socket must be opened and in a listening state before making this call.

Parameters

  timeout_ms | the timeout in milliseconds; if a timeout occurs then 0 is returned (no Qore-language excepton is raised)
  xsink | if an error occurs, the Qore-language exception information will be added here

Returns
  a new QoreSocket object for the new connection (or 0 if an error or timeout occured)

See Also
  - QoreSocket::listen()
  - QoreSocket::acceptSSL(int timeout_ms, X509 *cert, EVP_PKEY *pkey, ExceptionSink *xsink)

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.

Parameters

  source | source connection information will be written to this object if not 0

Returns
  0 for OK, not 0 if an error occured

See Also
  - QoreSocket::listen()
  - QoreSocket::accept()
  - QoreSocket::acceptSSL()
  - SocketSource

DLLEXPORT int QoreSocket::acceptAndReplace | ( | int | timeout_ms,
|  | ExceptionSink * | xsink
| ) |  |

accepts a new connection on a listening socket and replaces the current socket with the new connection with a timeout; if no connection is accepted within the timeout period, -3 (QSE_TIMEOUT) is returned

the socket must be opened and in a listening state before making this call.

Parameters

  timeout_ms | the timeout in milliseconds; if a timeout occurs then 0 is returned (no Qore-language excepton is raised)
  xsink | if an error occurs, the Qore-language exception information will be added here

Returns
  0 for OK, -1 if an error occured, -3 (QSE_TIMEOUT) if a timeout occured

See Also
  - QoreSocket::listen()
  - QoreSocket::accept(int timeout_ms, ExceptionSink *xsink)
  - QoreSocket::acceptSSL(int timeout_ms, X509 *cert, EVP_PKEY *pkey, ExceptionSink *xsink)

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.

Parameters

  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

Returns
  a new QoreSocket object for the new connection (or 0 if an error occured)

Note
  the same as calling QoreSocket::accept() and then QoreSocket::upgradeServerToSSL() on the new socket

See Also
  - QoreSocket::listen()
  - SocketSource

DLLEXPORT QoreSocket* QoreSocket::acceptSSL | ( | int | timeout_ms,
|  | 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 with a timeout; if no connection is accepted within the timeout period 0 is returned

the socket must be opened and in a listening state before making this call.

Parameters

  timeout_ms | the timeout in milliseconds; if a timeout occurs then 0 is returned (no Qore-language excepton is raised)
  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

Returns
  a new QoreSocket object for the new connection (or 0 if an error or timeout occured)

Note
  the same as calling QoreSocket::accept() and then QoreSocket::upgradeServerToSSL() on the new socket

See Also
  - QoreSocket::accept(int timeout_ms, ExceptionSink *xsink)
  - QoreSocket::listen()

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

Note
  a socket file will be created on the filesystem if a UNIX domain socket is opened.
  the socket will be closed and reopened if necessary

Parameters

  name | address:port or filename to bind to; if the name has a ':' in it; it's assumed to be an address:port specification for binding to an INET socket, otherwise it is assumed to be a file name for a UNIX domain socket. If there is more than 1 ':' in the name, then the address is assumed to be an ipv6 interface address, otherwise it is assumed to be an ipv4 address.
  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

Returns
  0 for OK, not 0 for error

DLLEXPORT int QoreSocket::bind | ( | int | prt,
|  | bool | reuseaddr
| ) |  |

binds to a TCP INET (ipv4 only) port on all interfaces and returns a status code

Note
  the socket will be closed and reopened if necessary

Parameters

  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

Returns
  0 for OK, not 0 for error

DLLEXPORT int QoreSocket::bind | ( | const char * | iface,
|  | int | prt,
|  | bool | reuseaddr = `false`
| ) |  |

binds to a TCP INET (ipv4 only) port on the given interface and returns a status code

Note
  the socket will be closed and reopened if necessary

Parameters

  iface | 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

Returns
  0 for OK, not 0 for error

DLLEXPORT int QoreSocket::bind | ( | const struct sockaddr * | addr,
|  | int | addr_size
| ) |  |

binds an INET TCP socket to a specific socket address - do not use, deprecated, use bind(int family, const struct sockaddr *addr, int addr_size, int socktype, int protocol) instead

this function will not set the port number; use bind(int family, const struct sockaddr *addr, int addr_size) instead

Note
  the socket will be closed and reopened if necessary

Parameters

  addr | the socket address to bind to
  addr_size | the size of the addr argument

Returns
  0 for OK, not 0 for error

Deprecated:
  use bind(int family, const struct sockaddr *addr, int addr_size, int socktype, int protocol) instead

DLLEXPORT int QoreSocket::bind | ( | int | family,
|  | const struct sockaddr * | addr,
|  | int | addr_size,
|  | int | socktype = `Q_SOCK_STREAM`,
|  | int | protocol = `0`
| ) |  |

binds an INET or INET6 TCP socket to a specific socket address

Note
  the socket will be closed and reopened if necessary

Parameters

  family | the address family (AF_INET or AF_INET6)
  addr | the socket address to bind to
  addr_size | the size of the addr argument
  socktype | the type of socket (SOCK_STREAM = tcp socket)
  protocol | the protocol for the socket

Returns
  0 for OK, not 0 for error

DLLEXPORT int QoreSocket::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

Note
  the socket will be closed and reopened if necessary

Parameters

  name | the name or address of the interface, can be 0 meaning all interfaces
  service | the service name or port number
  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
  family | the address family (AF_INET, AF_INET6, or AF_UNSPEC)
  socktype | the type of socket (SOCK_STREAM = tcp socket)
  protocol | the protocol for the socket
  xsink | if not 0 and an error occurs, the Qore-language exception information will be added here

Returns
  0 for OK, not 0 for error

DLLEXPORT int QoreSocket::bindUNIX | ( | const char * | name,
|  | ExceptionSink * | xsink = `0`
| ) |  |

binds to a UNIX domain socket and returns a status code

Note
  a socket file will be created on the filesystem if a UNIX domain socket is opened.
  the socket will be closed and reopened if necessary

Parameters

  name | UNIX filename to bind to
  xsink | if not 0 and an error occurs, the Qore-language exception information will be added here

Returns
  0 for OK, not 0 for error

DLLEXPORT int QoreSocket::bindUNIX | ( | const char * | name,
|  | int | socktype,
|  | int | protocol = `0`,
|  | ExceptionSink * | xsink = `0`
| ) |  |

binds to a UNIX domain socket and returns a status code

Note
  a socket file will be created on the filesystem if a UNIX domain socket is opened.
  the socket will be closed and reopened if necessary

Parameters

  name | UNIX filename to bind to
  socktype | the type of socket (SOCK_STREAM = tcp socket)
  protocol | the protocol for the socket (use 0 for default)
  xsink | if not 0 and an error occurs, the Qore-language exception information will be added here

Returns
  0 for OK, not 0 for error

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.

Returns
  0 if OK, not 0 on error

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.

Parameters

  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

Returns
  0 for OK, -1 means that an error occured and a Qore-language exception was raised

See Also
  QoreSocket::connectINET()
  QoreSocket::connectUNIX()
  QoreSocket::connectSSL()
  QoreSocket::connectINETSSL()
  QoreSocket::connectUNIXSSL()

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.

Parameters

  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

Returns
  0 for OK, -1 means that an error occured and a Qore-language exception was raised

See Also
  QoreSocket::connectINET()
  QoreSocket::connectUNIX()
  QoreSocket::connectSSL()
  QoreSocket::connectINETSSL()
  QoreSocket::connectUNIXSSL()

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

Parameters

  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

Returns
  0 for OK, -1 means that an error occured and a Qore-language exception was raised

See Also
  QoreSocket::connect()
  QoreSocket::connectUNIX()
  QoreSocket::connectSSL()
  QoreSocket::connectINETSSL()
  QoreSocket::connectUNIXSSL()

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

Parameters

  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

Returns
  0 for OK, -1 means that an error occured and a Qore-language exception was raised

See Also
  QoreSocket::connect()
  QoreSocket::connectUNIX()
  QoreSocket::connectSSL()
  QoreSocket::connectINETSSL()
  QoreSocket::connectUNIXSSL()

DLLEXPORT int QoreSocket::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 code, Qore-language exceptions are raised in the case of any errors

Parameters

  name | the name or address of the host
  service | the port number or service name of the remote socket
  family | should be either AF_INET (for ipv4) or AF_INET6 (for ipv6)
  sock_type | the type of socket, normally SOCK_STREAM for tcp sockets or SOCK_DGRAM for udp sockets
  protocol | the protocol number, use 0 for the default
  timeout_ms | the timeout period in milliseconds
  xsink | if not 0, if an error occurs, the Qore-language exception information will be added here

Returns
  0 for OK, -1 means that an error occured and a Qore-language exception was raised

See Also
  QoreSocket::connect()
  QoreSocket::connectUNIX()
  QoreSocket::connectSSL()
  QoreSocket::connectINETSSL()
  QoreSocket::connectUNIXSSL()

DLLEXPORT int QoreSocket::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 code, Qore-language exceptions are raised in the case of any errors

Parameters

  name | the name or address of the host
  service | the port number or service name of the remote socket
  family | should be either AF_INET (for ipv4) or AF_INET6 (for ipv6)
  sock_type | the type of socket, normally SOCK_STREAM for tcp sockets or SOCK_DGRAM for udp sockets
  protocol | the protocol number, use 0 for the default
  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 not 0, if an error occurs, the Qore-language exception information will be added here

Returns
  0 for OK, -1 means that an error occured and a Qore-language exception was raised

See Also
  QoreSocket::connect()
  QoreSocket::connectUNIX()
  QoreSocket::connectSSL()
  QoreSocket::connectINETSSL()
  QoreSocket::connectUNIXSSL()

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

Parameters

  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

Returns
  0 for OK, -1 means that an error occured and a Qore-language exception was raised

Note
  the same as calling QoreSocket::connectINET() and then QoreSocket::upgradeClientToSSL()

See Also
  QoreSocket::connect()
  QoreSocket::connectUNIX()
  QoreSocket::connectINET()
  QoreSocket::connectSSL()
  QoreSocket::connectUNIXSSL()
  QoreSocket::upgradeClientToSSL()

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

Parameters

  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

Returns
  0 for OK, -1 means that an error occured and a Qore-language exception was raised

Note
  the same as calling QoreSocket::connectINET() and then QoreSocket::upgradeClientToSSL()

See Also
  QoreSocket::connect()
  QoreSocket::connectUNIX()
  QoreSocket::connectINET()
  QoreSocket::connectSSL()
  QoreSocket::connectUNIXSSL()
  QoreSocket::upgradeClientToSSL()

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.

Parameters

  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

Returns
  0 for OK, -1 means that an error occured and a Qore-language exception was raised

Note
  the same as calling QoreSocket::connect() and then QoreSocket::upgradeClientToSSL()

See Also
  QoreSocket::connect()
  QoreSocket::connectINET()
  QoreSocket::connectUNIX()
  QoreSocket::connectINETSSL()
  QoreSocket::connectUNIXSSL()
  QoreSocket::upgradeClientToSSL()

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.

Parameters

  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

Returns
  0 for OK, -1 means that an error occured and a Qore-language exception was raised

Note
  the same as calling QoreSocket::connect() and then QoreSocket::upgradeClientToSSL()

See Also
  QoreSocket::connect()
  QoreSocket::connectINET()
  QoreSocket::connectUNIX()
  QoreSocket::connectINETSSL()
  QoreSocket::connectUNIXSSL()
  QoreSocket::upgradeClientToSSL()

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

Parameters

  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

Returns
  0 for OK, -1 means that an error occured and a Qore-language exception was raised

See Also
  QoreSocket::connect()
  QoreSocket::connectINET()
  QoreSocket::connectSSL()
  QoreSocket::connectINETSSL()
  QoreSocket::connectUNIXSSL()

DLLEXPORT int QoreSocket::connectUNIX | ( | const char * | p,
|  | int | socktype,
|  | int | protocol = `0`,
|  | 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

Parameters

  p | the file name of the UNIX domain socket
  socktype | the type of socket (SOCK_STREAM = tcp socket)
  protocol | the protocol for the socket (use 0 for default)
  xsink | if not 0, if an error occurs, the Qore-language exception information will be added here

Returns
  0 for OK, -1 means that an error occured and a Qore-language exception was raised

See Also
  QoreSocket::connect()
  QoreSocket::connectINET()
  QoreSocket::connectSSL()
  QoreSocket::connectINETSSL()
  QoreSocket::connectUNIXSSL()

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

Parameters

  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

Returns
  0 for OK, -1 means that an error occured and a Qore-language exception was raised

Note
  the same as calling QoreSocket::connectUNIX() and then QoreSocket::upgradeClientToSSL()

See Also
  QoreSocket::connect()
  QoreSocket::connectINET()
  QoreSocket::connectUNIX()
  QoreSocket::connectSSL()
  QoreSocket::connectINETSSL()
  QoreSocket::upgradeClientToSSL()

DLLEXPORT int QoreSocket::connectUNIXSSL | ( | const char * | p,
|  | int | socktype,
|  | int | protocol,
|  | 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

Parameters

  p | the file name of the UNIX domain socket
  socktype | the type of socket (SOCK_STREAM = tcp socket)
  protocol | the protocol for the socket (use 0 for default)
  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

Returns
  0 for OK, -1 means that an error occured and a Qore-language exception was raised

Note
  the same as calling QoreSocket::connectUNIX() and then QoreSocket::upgradeClientToSSL()

See Also
  QoreSocket::connect()
  QoreSocket::connectINET()
  QoreSocket::connectUNIX()
  QoreSocket::connectSSL()
  QoreSocket::connectINETSSL()
  QoreSocket::upgradeClientToSSL()

DLLEXPORT const QoreEncoding* QoreSocket::getEncoding | ( |  | ) | const

returns the character encoding associated with this socket

Returns
  the character encoding associated with this socket

DLLEXPORT QoreHashNode* QoreSocket::getPeerInfo | ( | ExceptionSink * | xsink | ) | const

returns peer information for a connected socket

if the socket is not connected, a Qore-language exception is thrown

Parameters

  xsink | if an error occurs, the Qore-language exception information will be added here

Returns
  a hash with the following keys:
  - `hostname:` the hostname of the remote end (if known or appropriate for the socket type)
  - `hostname_desc:` a descriptive string for the remote hostname (including the socket type - ie "ipv6[host]")
  - `address:` the address of the remote end - for UNIX sockets this is the file path
  - `address_desc:` a descriptive string for the remote address
  - `port:` the port number if known
  - `family:` the address family (ie AF_INET, AF_INET6, AF_UNIX, ...)
  - `familystr:` a string description of the address family ("ipv4", "ipv6", etc)

DLLEXPORT int QoreSocket::getSocket | ( |  | ) | const

returns the file descriptor associated with this socket

Returns
  the file descriptor associated with this socket

DLLEXPORT QoreHashNode* QoreSocket::getSocketInfo | ( | ExceptionSink * | xsink | ) | const

returns information for the current socket; the socket must be open

if the socket is not open, a Qore-language exception is thrown

Parameters

  xsink | if an error occurs, the Qore-language exception information will be added here

Returns
  a hash with the following keys:
  - `hostname:` the hostname for the local interface (if known or appropriate for the socket type)
  - `hostname_desc:` a descriptive string for the local hostname (including the socket type - ie "ipv6[host]")
  - `address:` the address of the local interface - for UNIX sockets this is the file path
  - `address_desc:` a descriptive string for the local interface
  - `port:` the port number if known
  - `family:` the address family (ie AF_INET, AF_INET6, AF_UNIX, ...)
  - `familystr:` a string description of the address family ("ipv4", "ipv6", etc)

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

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

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_ms = `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

Parameters

  timeout_ms | timeout in milliseconds, -1=never timeout, 0=do not block, return immediately if there is no data waiting

Returns
  true if data is available within the timeout period

DLLEXPORT bool QoreSocket::isOpen | ( |  | ) | const

returns true if the socket is open

Returns
  true if the socket is open

DLLEXPORT bool QoreSocket::isSecure | ( |  | ) | const

returns true if an SSL connection is active

Returns
  true if an SSL connection is active

DLLEXPORT bool QoreSocket::isWriteFinished | ( | int | timeout_ms = `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

Parameters

  timeout_ms | timeout in milliseconds, -1=never timeout, 0=do not block, return immediately if there is no data waiting

Returns
  true if data is available within the timeout period

DLLEXPORT int QoreSocket::listen | ( |  | ) |

sets an open socket to the listening state

Returns
  0 for OK, not 0 if an error occured

DLLEXPORT QoreHashNode* QoreSocket::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 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.

Parameters

  timeout_ms | 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

Returns
  the message body as the value of the "body" key and any footers read after the body as other keys (0 if an error occurs)

See Also
  QoreStringNode

DLLEXPORT QoreHashNode* QoreSocket::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 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.

Parameters

  timeout_ms | tieout 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

Returns
  the message body as the value of the "body" key and any footers read after the body as other keys (0 if an error occurs)

See Also
  BinaryNode

DLLEXPORT AbstractQoreNode* QoreSocket::readHTTPHeader | ( | int | timeout_ms,
|  | 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.

Note
  does not read the message body; message body must be read manually

Parameters

  timeout_ms | 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

Returns
  if 0 (and prc == 0), the socket was closed on the remote end without a response, if the type is NT_STRING, the response could not be parsed, if not 0, caller owns the reference count returned

DLLEXPORT AbstractQoreNode* QoreSocket::readHTTPHeader | ( | QoreHashNode * | info,
|  | int | timeout_ms,
|  | 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.

Note
  does not read the message body; message body must be read manually

Parameters

  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_ms | 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

Returns
  if 0 (and prc == 0), the socket was closed on the remote end without a response, if the type is NT_STRING, the response could not be parsed, if not 0, caller owns the reference count returned

DLLEXPORT QoreHashNode* QoreSocket::readHTTPHeader | ( | ExceptionSink * | xsink,
|  | QoreHashNode * | info,
|  | int | timeout_ms,
|  | int | source = `QORE_SOURCE_SOCKET`
| ) |  |

read and parse HTTP header, caller owns QoreHashNode reference count returned

The socket must be connected before this call is made.

Note
  does not read the message body; message body must be read manually

Parameters

  xsink | if an error occurs, the Qore-language exception information will be added here
  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_ms | in milliseconds, -1=never timeout, 0=do not block, return immediately if there is no data waiting
  source | the event source code for socket events

Returns
  if 0, an exception was raised, if not 0, caller owns the reference count returned

DLLEXPORT QoreStringNode* QoreSocket::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

The socket must be connected before this call is made.

Parameters

  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_ms | 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

Returns
  the data read as a QoreStringNode tagged with the socket's QoreEncoding, caller owns the reference count returned (0 if an error occurs)

See Also
  QoreEncoding

DLLEXPORT QoreStringNode* QoreSocket::recv | ( | qore_offset_t | bufsize,
|  | int | timeout_ms,
|  | ExceptionSink * | xsink
| ) |  |

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.

Parameters

  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_ms | 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

Returns
  the data read as a QoreStringNode tagged with the socket's QoreEncoding, caller owns the reference count returned (0 if an error occurs)

See Also
  QoreEncoding

DLLEXPORT QoreStringNode* QoreSocket::recv | ( | int | timeout_ms,
|  | 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.

Parameters

  timeout_ms | 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

Returns
  the data read as a QoreStringNode tagged with the socket's QoreEncoding, caller owns the reference count returned (0 if an error occurs)

See Also
  QoreEncoding

DLLEXPORT QoreStringNode* QoreSocket::recv | ( | int | timeout_ms,
|  | ExceptionSink * | xsink
| ) |  |

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.

Parameters

  timeout_ms | 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

Returns
  the data read as a QoreStringNode tagged with the socket's QoreEncoding, caller owns the reference count returned (0 if an error occurs)

See Also
  QoreEncoding

DLLEXPORT int QoreSocket::recv | ( | int | fd,
|  | qore_offset_t | size,
|  | int | timeout_ms
| ) |  |

receive data on the socket and write it to a file descriptor

The socket must be connected before this call is made.

Parameters

  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_ms | timeout in milliseconds, -1=never timeout, 0=do not block, return immediately if there is no data waiting

Returns
  0 for OK, not 0 for error

Note
  the timeout value applies to each read from the socket

DLLEXPORT BinaryNode* QoreSocket::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 reference count returned

The socket must be connected before this call is made.

Parameters

  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_ms | 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

Returns
  the data read as a BinaryNode, caller owns the reference count returned (0 if an error occurs)

DLLEXPORT BinaryNode* QoreSocket::recvBinary | ( | qore_offset_t | bufsize,
|  | int | timeout_ms,
|  | ExceptionSink * | xsink
| ) |  |

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.

Parameters

  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_ms | 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

Returns
  the data read as a BinaryNode, caller owns the reference count returned (0 if an error occurs)

DLLEXPORT BinaryNode* QoreSocket::recvBinary | ( | int | timeout_ms,
|  | 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.

Parameters

  timeout_ms | 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

Returns
  the data read as a BinaryNode, caller owns the reference count returned (0 if an error occurs)

DLLEXPORT BinaryNode* QoreSocket::recvBinary | ( | int | timeout_ms,
|  | ExceptionSink * | xsink
| ) |  |

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.

Parameters

  timeout_ms | 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

Returns
  the data read as a BinaryNode, caller owns the reference count returned (0 if an error occurs)

DLLEXPORT int QoreSocket::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 output parameter

The socket must be connected before this call is made.

Parameters

  timeout_ms | 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

Returns
  0 for OK, not 0 for error

See Also
  QoreSocket::recvu1()

DLLEXPORT int64 QoreSocket::recvi1 | ( | int | timeout_ms,
|  | char * | val,
|  | ExceptionSink * | xsink
| ) |  |

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.

Parameters

  timeout_ms | 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
  xsink | if an error occurs in socket communication, the Qore-language exception information will be added here

Returns
  <= 0 = error, otherwise the number of bytes received

See Also
  QoreSocket::recvu1()

DLLEXPORT int QoreSocket::recvi2 | ( | int | timeout_ms,
|  | 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.

Parameters

  timeout_ms | 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

Returns
  0 for OK, not 0 for error

See Also
  QoreSocket::recvi2LSB()
  QoreSocket::recvu2()
  QoreSocket::recvu2LSB()

DLLEXPORT int64 QoreSocket::recvi2 | ( | int | timeout_ms,
|  | short * | val,
|  | ExceptionSink * | xsink
| ) |  |

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.

Parameters

  timeout_ms | 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
  xsink | if an error occurs in socket communication, the Qore-language exception information will be added here

Returns
  <= 0 = error, otherwise the number of bytes received

See Also
  QoreSocket::recvi2LSB()
  QoreSocket::recvu2()
  QoreSocket::recvu2LSB()

DLLEXPORT int QoreSocket::recvi2LSB | ( | int | timeout_ms,
|  | 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.

Note
  that this is not network byte order, normally QoreSocket::recvi2() should be used instead

Parameters

  timeout_ms | 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

Returns
  0 for OK, not 0 for error

See Also
  QoreSocket::recvi2()
  QoreSocket::recvu2()
  QoreSocket::recvu2LSB()

DLLEXPORT int64 QoreSocket::recvi2LSB | ( | int | timeout_ms,
|  | short * | val,
|  | ExceptionSink * | xsink
| ) |  |

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.

Note
  that this is not network byte order, normally QoreSocket::recvi2() should be used instead

Parameters

  timeout_ms | 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
  xsink | if an error occurs in socket communication, the Qore-language exception information will be added here

Returns
  <= 0 = error, otherwise the number of bytes received

See Also
  QoreSocket::recvi2()
  QoreSocket::recvu2()
  QoreSocket::recvu2LSB()

DLLEXPORT int QoreSocket::recvi4 | ( | int | timeout_ms,
|  | 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.

Parameters

  timeout_ms | 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

Returns
  0 for OK, not 0 for error

See Also
  QoreSocket::recvi4LSB()
  QoreSocket::recvu4()
  QoreSocket::recvu4LSB()

DLLEXPORT int64 QoreSocket::recvi4 | ( | int | timeout_ms,
|  | int * | val,
|  | ExceptionSink * | xsink
| ) |  |

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.

Parameters

  timeout_ms | 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
  xsink | if an error occurs in socket communication, the Qore-language exception information will be added here

Returns
  <= 0 = error, otherwise the number of bytes received

See Also
  QoreSocket::recvi4LSB()
  QoreSocket::recvu4()
  QoreSocket::recvu4LSB()

DLLEXPORT int QoreSocket::recvi4LSB | ( | int | timeout_ms,
|  | 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.

Note
  that this is not network byte order, normally QoreSocket::recvi4() should be used instead

Parameters

  timeout_ms | 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

Returns
  0 for OK, not 0 for error

See Also
  QoreSocket::recvi4()
  QoreSocket::recvu4()
  QoreSocket::recvu4LSB()

DLLEXPORT int64 QoreSocket::recvi4LSB | ( | int | timeout_ms,
|  | int * | val,
|  | ExceptionSink * | xsink
| ) |  |

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.

Note
  that this is not network byte order, normally QoreSocket::recvi4() should be used instead

Parameters

  timeout_ms | 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
  xsink | if an error occurs in socket communication, the Qore-language exception information will be added here

Returns
  <= 0 = error, otherwise the number of bytes received

See Also
  QoreSocket::recvi4()
  QoreSocket::recvu4()
  QoreSocket::recvu4LSB()

DLLEXPORT int QoreSocket::recvi8 | ( | int | timeout_ms,
|  | 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.

Parameters

  timeout_ms | 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

Returns
  0 for OK, not 0 for error

See Also
  QoreSocket::recvi8LSB()
  QoreSocket::recvu8()
  QoreSocket::recvu8LSB()

DLLEXPORT int64 QoreSocket::recvi8 | ( | int | timeout_ms,
|  | int64 * | val,
|  | ExceptionSink * | xsink
| ) |  |

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.

Parameters

  timeout_ms | 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
  xsink | if an error occurs in socket communication, the Qore-language exception information will be added here

Returns
  <= 0 = error, otherwise the number of bytes received

See Also
  QoreSocket::recvi8LSB()
  QoreSocket::recvu8()
  QoreSocket::recvu8LSB()

DLLEXPORT int QoreSocket::recvi8LSB | ( | int | timeout_ms,
|  | 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.

Note
  that this is not network byte order, normally QoreSocket::recvi8() should be used instead

Parameters

  timeout_ms | 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

Returns
  0 for OK, not 0 for error

See Also
  QoreSocket::recvi8()

DLLEXPORT int64 QoreSocket::recvi8LSB | ( | int | timeout_ms,
|  | int64 * | val,
|  | ExceptionSink * | xsink
| ) |  |

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.

Note
  that this is not network byte order, normally QoreSocket::recvi8() should be used instead

Parameters

  timeout_ms | 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
  xsink | if an error occurs in socket communication, the Qore-language exception information will be added here

Returns
  <= 0 = error, otherwise the number of bytes received

See Also
  QoreSocket::recvi8()

DLLEXPORT int QoreSocket::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 output parameter

The socket must be connected before this call is made.

Parameters

  timeout_ms | 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

Returns
  0 for OK, not 0 for error

See Also
  QoreSocket::recvi1()

DLLEXPORT int64 QoreSocket::recvu1 | ( | int | timeout_ms,
|  | unsigned char * | val,
|  | ExceptionSink * | xsink
| ) |  |

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.

Parameters

  timeout_ms | 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
  xsink | if an error occurs in socket communication, the Qore-language exception information will be added here

Returns
  <= 0 = error, otherwise the number of bytes received

See Also
  QoreSocket::recvi1()

DLLEXPORT int QoreSocket::recvu2 | ( | int | timeout_ms,
|  | 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.

Parameters

  timeout_ms | 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

Returns
  0 for OK, not 0 for error

See Also
  QoreSocket::recvi2()
  QoreSocket::recvu2LSB()
  QoreSocket::recvi2LSB()

DLLEXPORT int64 QoreSocket::recvu2 | ( | int | timeout_ms,
|  | unsigned short * | val,
|  | ExceptionSink * | xsink
| ) |  |

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.

Parameters

  timeout_ms | 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
  xsink | if an error occurs in socket communication, the Qore-language exception information will be added here

Returns
  <= 0 = error, otherwise the number of bytes received

See Also
  QoreSocket::recvi2()
  QoreSocket::recvu2LSB()
  QoreSocket::recvi2LSB()

DLLEXPORT int QoreSocket::recvu2LSB | ( | int | timeout_ms,
|  | 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.

Note
  that this is not network byte order, normally QoreSocket::recvu2() should be used instead

Parameters

  timeout_ms | 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

Returns
  0 for OK, not 0 for error

See Also
  QoreSocket::recvu2()
  QoreSocket::recvi2()
  QoreSocket::recvi2LSB()

DLLEXPORT int64 QoreSocket::recvu2LSB | ( | int | timeout_ms,
|  | unsigned short * | val,
|  | ExceptionSink * | xsink
| ) |  |

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.

Note
  that this is not network byte order, normally QoreSocket::recvu2() should be used instead

Parameters

  timeout_ms | 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
  xsink | if an error occurs in socket communication, the Qore-language exception information will be added here

Returns
  <= 0 = error, otherwise the number of bytes received

See Also
  QoreSocket::recvu2()
  QoreSocket::recvi2()
  QoreSocket::recvi2LSB()

DLLEXPORT int QoreSocket::recvu4 | ( | int | timeout_ms,
|  | 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.

Parameters

  timeout_ms | 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

Returns
  0 for OK, not 0 for error

See Also
  QoreSocket::recvi4()
  QoreSocket::recvu4LSB()
  QoreSocket::recvi4LSB()

DLLEXPORT int64 QoreSocket::recvu4 | ( | int | timeout_ms,
|  | unsigned int * | val,
|  | ExceptionSink * | xsink
| ) |  |

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.

Parameters

  timeout_ms | 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
  xsink | if an error occurs in socket communication, the Qore-language exception information will be added here

Returns
  <= 0 = error, otherwise the number of bytes received

See Also
  QoreSocket::recvi4()
  QoreSocket::recvu4LSB()
  QoreSocket::recvi4LSB()

DLLEXPORT int QoreSocket::recvu4LSB | ( | int | timeout_ms,
|  | 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.

Note
  that this is not network byte order, normally QoreSocket::recvu4() should be used instead

Parameters

  timeout_ms | 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

Returns
  0 for OK, not 0 for error

See Also
  QoreSocket::recvu4()
  QoreSocket::recvi4()
  QoreSocket::recvi4LSB()

DLLEXPORT int64 QoreSocket::recvu4LSB | ( | int | timeout_ms,
|  | unsigned int * | val,
|  | ExceptionSink * | xsink
| ) |  |

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.

Note
  that this is not network byte order, normally QoreSocket::recvu4() should be used instead

Parameters

  timeout_ms | 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
  xsink | if an error occurs in socket communication, the Qore-language exception information will be added here

Returns
  <= 0 = error, otherwise the number of bytes received

See Also
  QoreSocket::recvu4()
  QoreSocket::recvi4()
  QoreSocket::recvi4LSB()

DLLEXPORT int QoreSocket::send | ( | const char * | buf,
|  | qore_size_t | size
| ) |  |

sends binary data on a connected socket

Parameters

  buf | the data to send
  size | the size of the data to send

Returns
  0 for OK, not 0 if an error occured

DLLEXPORT int QoreSocket::send | ( | const char * | buf,
|  | qore_size_t | size,
|  | ExceptionSink * | xsink
| ) |  |

sends binary data on a connected socket

Parameters

  buf | the data to send
  size | the size of the data to send
  xsink | if an error occurs in socket communication, the Qore-language exception information will be added here

Returns
  0 for OK, not 0 if an error occured

DLLEXPORT int QoreSocket::send | ( | const char * | buf,
|  | qore_size_t | size,
|  | int | timeout_ms,
|  | ExceptionSink * | xsink
| ) |  |

sends binary data on a connected socket

Parameters

  buf | the data to send
  size | the size of the data to send
  timeout_ms | the maximum amount of time the socket can block on a single send as an integer in milliseconds
  xsink | if an error occurs in socket communication, the Qore-language exception information will be added here

Returns
  0 for OK, not 0 if an error occured

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

Parameters

  msg | the string to send (must not be 0)
  xsink | if an error occurs in converting the string's character encoding or in socket communication, the Qore-language exception information will be added here

Returns
  0 for OK, not 0 if an error occured

DLLEXPORT int QoreSocket::send | ( | const QoreString * | msg,
|  | int | timeout_ms,
|  | ExceptionSink * | xsink
| ) |  |

sends string data on a connected socket, converts the string encoding to the socket's encoding if necessary

Parameters

  msg | the string to send (must not be 0)
  timeout_ms | the maximum amount of time the socket can block on a single send as an integer in milliseconds
  xsink | if an error occurs in converting the string's character encoding or in socket communication, the Qore-language exception information will be added here

Returns
  0 for OK, not 0 if an error occured

DLLEXPORT int QoreSocket::send | ( | const BinaryNode * | msg | ) |

sends binary data on a connected socket

Parameters

  msg | the data to send

Returns
  0 for OK, not 0 if an error occured

DLLEXPORT int QoreSocket::send | ( | const BinaryNode * | msg,
|  | ExceptionSink * | xsink
| ) |  |

sends binary data on a connected socket

Parameters

  msg | the data to send
  xsink | if an error occurs in socket communication, the Qore-language exception information will be added here

Returns
  0 for OK, not 0 if an error occured

DLLEXPORT int QoreSocket::send | ( | const BinaryNode * | msg,
|  | int | timeout_ms,
|  | ExceptionSink * | xsink
| ) |  |

sends binary data on a connected socket

Parameters

  msg | the data to send
  timeout_ms | the maximum amount of time the socket can block on a single send as an integer in milliseconds
  xsink | if an error occurs in socket communication, the Qore-language exception information will be added here

Returns
  0 for OK, not 0 if an error occured

DLLEXPORT int QoreSocket::send | ( | int | fd,
|  | qore_offset_t | size = `-1`
| ) |  |

sends untranslated data from an open file descriptor

Parameters

  fd | a file descriptor, open for reading
  size | the number of bytes to send (-1 = send all until EOF)

Returns
  0 for OK, not 0 if an error occured

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.

Parameters

  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

Returns
  0 for OK, not 0 for error

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.

Parameters

  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

Returns
  0 for OK, not 0 for error

DLLEXPORT int QoreSocket::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`
| ) |  |

send an HTTP request message on the socket

The socket must be connected before this call is made.

Parameters

  xsink | if an error occurs, the Qore-language exception information will be added here
  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

Returns
  0 for OK, not 0 for error

DLLEXPORT int QoreSocket::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
| ) |  |

send an HTTP request message on the socket with a timeout value

The socket must be connected before this call is made.

Parameters

  xsink | if an error occurs, the Qore-language exception information will be added here
  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
  timeout_ms | the maximum amount of time the socket can block on a single send as an integer in milliseconds

Returns
  0 for OK, not 0 for error

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.

Parameters

  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

Returns
  0 for OK, not 0 for error

DLLEXPORT int QoreSocket::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`
| ) |  |

send an HTTP response message on the socket

The socket must be connected before this call is made.

Parameters

  xsink | if an error occurs, the Qore-language exception information will be added here
  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

Returns
  0 for OK, not 0 for error

DLLEXPORT int QoreSocket::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
| ) |  |

send an HTTP response message on the socket

The socket must be connected before this call is made.

Parameters

  xsink | if an error occurs, the Qore-language exception information will be added here
  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
  timeout_ms | the maximum amount of time the socket can block on a single send as an integer in milliseconds

Returns
  0 for OK, not 0 for error

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.

Parameters

  i | the 1-byte integer to send through the socket

Returns
  0 for OK, not 0 if an error occured

DLLEXPORT int QoreSocket::sendi1 | ( | char | i,
|  | int | timeout_ms,
|  | ExceptionSink * | xsink
| ) |  |

sends a 1-byte binary integer data to a connected socket

The socket must be connected before this call is made.

Parameters

  i | the 1-byte integer to send through the socket
  timeout_ms | the maximum amount of time the socket can block on a single send as an integer in milliseconds
  xsink | if an error occurs in socket communication, the Qore-language exception information will be added here

Returns
  0 for OK, not 0 if an error occured

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.

Parameters

  i | the integer to write to the file

Returns
  0 for OK, not 0 if an error occured

See Also
  QoreSocket::sendi2LSB()

DLLEXPORT int QoreSocket::sendi2 | ( | short | i,
|  | int | timeout_ms,
|  | ExceptionSink * | xsink
| ) |  |

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.

Parameters

  i | the integer to write to the file
  timeout_ms | the maximum amount of time the socket can block on a single send as an integer in milliseconds
  xsink | if an error occurs in socket communication, the Qore-language exception information will be added here

Returns
  0 for OK, not 0 if an error occured

See Also
  QoreSocket::sendi2LSB()

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.

Note
  that this is not network byte order, normally QoreSocket::sendi2() should be used

Parameters

  i | the integer to write to the file

Returns
  0 for OK, not 0 if an error occured

See Also
  QoreSocket::sendi2()

DLLEXPORT int QoreSocket::sendi2LSB | ( | short | i,
|  | int | timeout_ms,
|  | ExceptionSink * | xsink
| ) |  |

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.

Note
  that this is not network byte order, normally QoreSocket::sendi2() should be used

Parameters

  i | the integer to write to the file
  timeout_ms | the maximum amount of time the socket can block on a single send as an integer in milliseconds
  xsink | if an error occurs in socket communication, the Qore-language exception information will be added here

Returns
  0 for OK, not 0 if an error occured

See Also
  QoreSocket::sendi2()

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.

Parameters

  i | the integer to write to the file

Returns
  0 for OK, not 0 if an error occured

See Also
  QoreSocket::sendi4LSB()

DLLEXPORT int QoreSocket::sendi4 | ( | int | i,
|  | int | timeout_ms,
|  | ExceptionSink * | xsink
| ) |  |

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.

Parameters

  i | the integer to write to the file
  timeout_ms | the maximum amount of time the socket can block on a single send as an integer in milliseconds
  xsink | if an error occurs in socket communication, the Qore-language exception information will be added here

Returns
  0 for OK, not 0 if an error occured

See Also
  QoreSocket::sendi4LSB()

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.

Note
  that this is not network byte order, normally QoreSocket::sendi4() should be used

Parameters

  i | the integer to write to the file

Returns
  0 for OK, not 0 if an error occured

See Also
  QoreSocket::sendi4()

DLLEXPORT int QoreSocket::sendi4LSB | ( | int | i,
|  | int | timeout_ms,
|  | ExceptionSink * | xsink
| ) |  |

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.

Note
  that this is not network byte order, normally QoreSocket::sendi4() should be used

Parameters

  i | the integer to write to the file
  timeout_ms | the maximum amount of time the socket can block on a single send as an integer in milliseconds
  xsink | if an error occurs in socket communication, the Qore-language exception information will be added here

Returns
  0 for OK, not 0 if an error occured

See Also
  QoreSocket::sendi4()

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.

Parameters

  i | the integer to write to the file

Returns
  0 for OK, not 0 if an error occured

See Also
  QoreSocket::sendi8LSB()

DLLEXPORT int QoreSocket::sendi8 | ( | int64 | i,
|  | int | timeout_ms,
|  | ExceptionSink * | xsink
| ) |  |

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.

Parameters

  i | the integer to write to the file
  timeout_ms | the maximum amount of time the socket can block on a single send as an integer in milliseconds
  xsink | if an error occurs in socket communication, the Qore-language exception information will be added here

Returns
  0 for OK, not 0 if an error occured

See Also
  QoreSocket::sendi8LSB()

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.

Note
  that this is not network byte order, normally QoreSocket::sendi8() should be used

Parameters

  i | the integer to write to the file

Returns
  0 for OK, not 0 if an error occured

See Also
  QoreSocket::sendi8()

DLLEXPORT int QoreSocket::sendi8LSB | ( | int64 | i,
|  | int | timeout_ms,
|  | ExceptionSink * | xsink
| ) |  |

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.

Note
  that this is not network byte order, normally QoreSocket::sendi8() should be used

Parameters

  i | the integer to write to the file
  timeout_ms | the maximum amount of time the socket can block on a single send as an integer in milliseconds
  xsink | if an error occurs in socket communication, the Qore-language exception information will be added here

Returns
  0 for OK, not 0 if an error occured

See Also
  QoreSocket::sendi8()

DLLEXPORT void QoreSocket::setEncoding | ( | const QoreEncoding * | id | ) |

sets the character encoding for strings sent and received with this socket

Parameters

  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.

Note
  QoreSocket::shutdown() should normally be called before calling this function.

Returns
  0 if OK, not 0 on error

See Also
  QoreSocket::shutdown()

DLLEXPORT int QoreSocket::shutdownSSL | ( | ExceptionSink * | xsink | ) |

shuts down an active SSL connection

called implicitly by QoreSocket::close()

Returns
  0 if OK, not 0 on error

See Also
  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.

Parameters

  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

Returns
  0 if OK, not 0 on error

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.

Parameters

  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

Returns
  0 if OK, not 0 on error

The documentation for this class was generated from the following file:

- include/qore/QoreSocket.h (5431)