QoreSocket Class Reference

provides access to sockets using Qore data structures More...

#include <QoreSocket.h>

List of all members.

Public Member Functions

DLLEXPORT QoreSocket ()
 creates an empty, unconnected socket
DLLEXPORT ~QoreSocket ()
 disconnects if necessary, frees all data, and destroys the socket
DLLEXPORT int connect (const char *name, ExceptionSink *xsink=0)
 connects to a socket and returns a status code, Qore-language exceptions are raised in the case of any errors
DLLEXPORT int connect (const char *name, int timeout_ms, ExceptionSink *xsink=0)
 connects to a socket and returns a status code, Qore-language exceptions are raised in the case of any errors
DLLEXPORT int connectINET (const char *host, int prt, ExceptionSink *xsink=0)
 connects to an INET socket by hostname and port number and returns a status code, Qore-language exceptions are raised in the case of any errors
DLLEXPORT int connectINET (const char *host, int prt, int timeout_ms, ExceptionSink *xsink=0)
 connects to an INET socket by hostname and port number and returns a status code, Qore-language exceptions are raised in the case of any errors
DLLEXPORT int connectUNIX (const char *p, ExceptionSink *xsink=0)
 connects to a UNIX domain socket and returns a status code, Qore-language exceptions are raised in the case of any errors
DLLEXPORT int connectSSL (const char *name, X509 *cert, EVP_PKEY *pkey, ExceptionSink *xsink)
 connects to a socket, negotiates an SSL connection, and returns a status code, Qore-language exceptions are raised in the case of any errors
DLLEXPORT int connectSSL (const char *name, int timeout_ms, X509 *cert, EVP_PKEY *pkey, ExceptionSink *xsink)
 connects to a socket, negotiates an SSL connection, and returns a status code, Qore-language exceptions are raised in the case of any errors
DLLEXPORT int connectINETSSL (const char *host, int prt, X509 *cert, EVP_PKEY *pkey, ExceptionSink *xsink)
 connects to an INET socket by hostname and port number, negotiates an SSL connection, and returns a status code, Qore-language exceptions are raised in the case of any errors
DLLEXPORT int connectINETSSL (const char *host, int prt, int timeout_ms, X509 *cert, EVP_PKEY *pkey, ExceptionSink *xsink)
 connects to an INET socket by hostname and port number, negotiates an SSL connection, and returns a status code, Qore-language exceptions are raised in the case of any errors
DLLEXPORT int connectUNIXSSL (const char *p, X509 *cert, EVP_PKEY *pkey, ExceptionSink *xsink)
 connects to a UNIX domain socket, negotiates an SSL connection, and returns a status code, Qore-language exceptions are raised in the case of any errors
DLLEXPORT int bind (const char *name, bool reuseaddr=false)
 binds to a UNIX domain socket or INET interface:port using TCP and returns a status code
DLLEXPORT int bind (int prt, bool reuseaddr)
 binds to a TCP INET port on all interfaces and returns a status code
DLLEXPORT int bind (const char *interface, int prt, bool reuseaddr=false)
 binds to a TCP INET port on the given interface and returns a status code
DLLEXPORT int bind (const struct sockaddr *addr, int addr_size)
 binds an INET TCP socket to a specific socket address
DLLEXPORT int getPort ()
 returns the TCP port number, also assigns the interal port number if it must be discovered
DLLEXPORT QoreSocketaccept (SocketSource *source, ExceptionSink *xsink)
 accepts a new connection on a listening socket and returns a new QoreSocket object for the new connection
DLLEXPORT QoreSocketacceptSSL (SocketSource *source, X509 *cert, EVP_PKEY *pkey, ExceptionSink *xsink)
 accepts a new connection on a listening socket, negotiates an SSL connection, and returns a new QoreSocket object for the new connection
DLLEXPORT int acceptAndReplace (SocketSource *source)
 accepts a new connection on a listening socket and replaces the current socket with the new connection
DLLEXPORT int listen ()
 sets an open socket to the listening state
DLLEXPORT int send (const char *buf, qore_size_t size)
 sends binary data on a connected socket
DLLEXPORT int send (const QoreString *msg, ExceptionSink *xsink)
 sends string data on a connected socket, converts the string encoding to the socket's encoding if necessary
DLLEXPORT int send (const BinaryNode *msg)
 sends binary data on a connected socket
DLLEXPORT int send (int fd, qore_offset_t size=-1)
 sends untranslated data from an open file descriptor
DLLEXPORT int sendi1 (char i)
 sends a 1-byte binary integer data to a connected socket
DLLEXPORT int sendi2 (short i)
 sends a 2-byte (16bit) binary integer in MSB (Most Significant Byte first, big endian, network) format through a connected socket
DLLEXPORT int sendi4 (int i)
 sends a 4-byte (32bit) binary integer in MSB (Most Significant Byte first, big endian, network) format through a connected socket
DLLEXPORT int sendi8 (int64 i)
 sends an 8-byte (64bit) binary integer in MSB (Most Significant Byte first, big endian, network) format through a connected socket
DLLEXPORT int sendi2LSB (short i)
 sends a 2-byte (16bit) binary integer in LSB (Least Significant Byte first, little endian) format through a connected socket
DLLEXPORT int sendi4LSB (int i)
 sends a 4-byte (32bit) binary integer in LSB (Least Significant Byte first, little endian) format through a connected socket
DLLEXPORT int sendi8LSB (int64 i)
 sends an 8-byte (64bit) binary integer in LSB (Least Significant Byte first, little endian) format through a connected socket
DLLEXPORT int recvi1 (int timeout, char *val)
 reads a 1-byte signed integer from the socket with a timeout value and returns the value read as an output parameter
DLLEXPORT int recvi2 (int timeout, short *val)
 reads a 2-byte signed integer in MSB (Most Significant Byte first, big endian, network) format from the socket with a timeout value and returns the value read as an output parameter
DLLEXPORT int recvi4 (int timeout, int *val)
 reads a 4-byte signed integer in MSB (Most Significant Byte first, big endian, network) format from the socket with a timeout value and returns the value read as an output parameter
DLLEXPORT int recvi8 (int timeout, int64 *val)
 reads an 8-byte signed integer in MSB (Most Significant Byte first, big endian, network) format from the socket with a timeout value and returns the value read as an output parameter
DLLEXPORT int recvi2LSB (int timeout, short *val)
 reads a 2-byte signed integer in LSB (Most Significant Byte first, little endian) format from the socket with a timeout value and returns the value read as an output parameter
DLLEXPORT int recvi4LSB (int timeout, int *val)
 reads a 4-byte signed integer in LSB (Most Significant Byte first, little endian) format from the socket with a timeout value and returns the value read as an output parameter
DLLEXPORT int recvi8LSB (int timeout, int64 *val)
 reads an 8-byte signed integer in LSB (Most Significant Byte first, little endian) format from the socket with a timeout value and returns the value read as an output parameter
DLLEXPORT int recvu1 (int timeout, unsigned char *val)
 reads a 1-byte unsigned integer from the socket with a timeout value and returns the value read as an output parameter
DLLEXPORT int recvu2 (int timeout, unsigned short *val)
 reads a 2-byte unsigned integer in MSB (Most Significant Byte first, big endian, network) format from the socket with a timeout value and returns the value read as an output parameter
DLLEXPORT int recvu4 (int timeout, unsigned int *val)
 reads a 4-byte unsigned integer in MSB (Most Significant Byte first, big endian, network) format from the socket with a timeout value and returns the value read as an output parameter
DLLEXPORT int recvu2LSB (int timeout, unsigned short *val)
 reads a 2-byte unsigned integer in LSB (Most Significant Byte first, little endian) format from the socket with a timeout value and returns the value read as an output parameter
DLLEXPORT int recvu4LSB (int timeout, unsigned int *val)
 reads a 4-byte unsigned integer in LSB (Most Significant Byte first, little endian) format from the socket with a timeout value and returns the value read as an output parameter
DLLEXPORT QoreStringNoderecv (qore_offset_t bufsize, int timeout, int *prc)
 receive a certain number of bytes with a timeout value and return a QoreStringNode, caller owns the reference count returned
DLLEXPORT BinaryNoderecvBinary (qore_offset_t bufsize, int timeout, int *prc)
 receive a certain number of bytes with a timeout value and return a BinaryNode, caller owns the reference count returned
DLLEXPORT QoreStringNoderecv (int timeout, int *prc)
 receive with a timeout value and return a QoreStringNode, caller owns the reference count returned
DLLEXPORT BinaryNoderecvBinary (int timeout, int *prc)
 receive all available data with a timeout value and return a BinaryNode, caller owns the reference count returned
DLLEXPORT int recv (int fd, qore_offset_t size, int timeout)
 receive data on the socket and write it to a file descriptor
DLLEXPORT int sendHTTPMessage (const char *method, const char *path, const char *http_version, const QoreHashNode *headers, const void *data, qore_size_t size, int source=QORE_SOURCE_SOCKET)
 send an HTTP request message on the socket
DLLEXPORT int 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 AbstractQoreNodereadHTTPHeader (int timeout, int *prc, int source=QORE_SOURCE_SOCKET)
 read and parse HTTP header, caller owns AbstractQoreNode reference count returned
DLLEXPORT QoreHashNodereadHTTPChunkedBodyBinary (int timeout, ExceptionSink *xsink, int source=QORE_SOURCE_SOCKET)
 receive a binary message in HTTP chunked transfer encoding, caller owns QoreHashNode reference count returned
DLLEXPORT QoreHashNodereadHTTPChunkedBody (int timeout, ExceptionSink *xsink, int source=QORE_SOURCE_SOCKET)
 receive a string message in HTTP chunked transfer encoding, caller owns QoreHashNode reference count returned
DLLEXPORT int setSendTimeout (int ms)
 set send timeout in milliseconds
DLLEXPORT int setRecvTimeout (int ms)
 set recv timeout in milliseconds
DLLEXPORT int getSendTimeout () const
 get send timeout in milliseconds
DLLEXPORT int getRecvTimeout () const
 get recv timeout in milliseconds
DLLEXPORT bool isDataAvailable (int timeout=0) const
 returns true if data is available on the socket in the timeout period in milliseconds
DLLEXPORT int close ()
 closes the socket
DLLEXPORT int shutdown ()
 calls shutdown on the socket
DLLEXPORT int shutdownSSL (ExceptionSink *xsink)
 shuts down an active SSL connection
DLLEXPORT int getSocket () const
 returns the file descriptor associated with this socket
DLLEXPORT const QoreEncodinggetEncoding () const
 returns the character encoding associated with this socket
DLLEXPORT void setEncoding (const QoreEncoding *id)
 sets the character encoding for strings sent and received with this socket
DLLEXPORT bool isOpen () const
 returns true if the socket is open
DLLEXPORT const char * getSSLCipherName () const
 returns the name of the SSL Cipher for the currently-connected control connection, or 0 if there is none
DLLEXPORT const char * getSSLCipherVersion () const
 returns the version string of the SSL Cipher for the currently-connected control connection, or 0 if there is none
DLLEXPORT bool isSecure () const
 returns true if an SSL connection is active
DLLEXPORT long verifyPeerCertificate () const
 returns the peer certificate verification code if an SSL connection is in progress
DLLEXPORT int upgradeClientToSSL (X509 *cert, EVP_PKEY *pkey, ExceptionSink *xsink)
 negotiates an SSL connection from the client side
DLLEXPORT int upgradeServerToSSL (X509 *cert, EVP_PKEY *pkey, ExceptionSink *xsink)
 negotiates an SSL connection from the client side
DLLEXPORT bool isWriteFinished (int timeout=0) const
 returns true if all write data has been written within the timeout period in milliseconds
DLLLOCAL void setEventQueue (Queue *cbq, ExceptionSink *xsink)
 sets the event queue (not part of the library's pubilc API), must be already referenced before call
DLLLOCAL Queue * getQueue ()
 returns the event queue (not part of the library's public API)
DLLLOCAL int64 getObjectIDForEvents () const
 returns a unique ID for the socket to be used in event messages
DLLLOCAL void cleanup (ExceptionSink *xsink)
 posts deleted message and removes any event queue


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 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 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 int QoreSocket::bind ( const struct sockaddr *  addr,
int  addr_size 
)

binds an INET TCP socket to a specific socket address

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

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

binds to a TCP INET port on the given interface and returns a status code

Note:
the socket will be closed and reopened if necessary
Parameters:
interface the interface to bind to (hostname or IP address)
prt the port to bind to
reuseaddr if true then setsockopt() will be called with SO_REUSEADDR, allowing the bind to succeed even if the port is still in a TIME_WAIT state, for example
Returns:
0 for OK, not 0 for error

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

binds to a TCP INET 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 *  name,
bool  reuseaddr = false 
)

binds to a UNIX domain socket or INET interface:port using TCP and returns a status code

If "name" has a ':' in it; it's assumed to be a address:port specification for binding to an INET socket, otherwise "name" is assumed to be a file name for a UNIX domain socket.

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
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::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,
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::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::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::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::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::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::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::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::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::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 const QoreEncoding* QoreSocket::getEncoding (  )  const

returns the character encoding associated with this socket

Returns:
the character encoding associated with this socket

DLLEXPORT int QoreSocket::getSocket (  )  const

returns the file descriptor associated with this socket

Returns:
the file descriptor associated with this socket

DLLEXPORT const char* QoreSocket::getSSLCipherName (  )  const

returns the name of the SSL Cipher for the currently-connected control connection, or 0 if there is none

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 = 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 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 = 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 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,
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 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,
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 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,
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 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 int QoreSocket::recv ( int  fd,
qore_offset_t  size,
int  timeout 
)

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

The socket must be connected before this call is made.

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 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 QoreStringNode* QoreSocket::recv ( int  timeout,
int *  prc 
)

receive with a timeout value and return a QoreStringNode, caller owns the reference count returned

The socket must be connected before this call is made. This call will read data, blocking according to the timeout value. Then all data available on the socket will be read and returned as a QoreStringNode.

Parameters:
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,
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 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 BinaryNode* QoreSocket::recvBinary ( int  timeout,
int *  prc 
)

receive all available data 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 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,
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 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 int QoreSocket::recvi1 ( int  timeout,
char *  val 
)

reads a 1-byte signed integer from the socket with a timeout value and returns the value read as an output parameter

The socket must be connected before this call is made.

Parameters:
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 int QoreSocket::recvi2 ( int  timeout,
short *  val 
)

reads a 2-byte signed integer in MSB (Most Significant Byte first, big endian, network) format from the socket with a timeout value and returns the value read as an output parameter

The socket must be connected before this call is made.

Parameters:
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 int QoreSocket::recvi2LSB ( int  timeout,
short *  val 
)

reads a 2-byte signed integer in LSB (Most Significant Byte first, little endian) format from the socket with a timeout value and returns the value read as an output parameter

The socket must be connected before this call is made.

Note:
that this is not network byte order, normally QoreSocket::recvi2() should be used instead
Parameters:
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 int QoreSocket::recvi4 ( int  timeout,
int *  val 
)

reads a 4-byte signed integer in MSB (Most Significant Byte first, big endian, network) format from the socket with a timeout value and returns the value read as an output parameter

The socket must be connected before this call is made.

Parameters:
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 int QoreSocket::recvi4LSB ( int  timeout,
int *  val 
)

reads a 4-byte signed integer in LSB (Most Significant Byte first, little endian) format from the socket with a timeout value and returns the value read as an output parameter

The socket must be connected before this call is made.

Note:
that this is not network byte order, normally QoreSocket::recvi4() should be used instead
Parameters:
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 int QoreSocket::recvi8 ( int  timeout,
int64 *  val 
)

reads an 8-byte signed integer in MSB (Most Significant Byte first, big endian, network) format from the socket with a timeout value and returns the value read as an output parameter

The socket must be connected before this call is made.

Parameters:
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 int QoreSocket::recvi8LSB ( int  timeout,
int64 *  val 
)

reads an 8-byte signed integer in LSB (Most Significant Byte first, little endian) format from the socket with a timeout value and returns the value read as an output parameter

The socket must be connected before this call is made.

Note:
that this is not network byte order, normally QoreSocket::recvi8() should be used instead
Parameters:
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 int QoreSocket::recvu1 ( int  timeout,
unsigned char *  val 
)

reads a 1-byte unsigned integer from the socket with a timeout value and returns the value read as an output parameter

The socket must be connected before this call is made.

Parameters:
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 int QoreSocket::recvu2 ( int  timeout,
unsigned short *  val 
)

reads a 2-byte unsigned integer in MSB (Most Significant Byte first, big endian, network) format from the socket with a timeout value and returns the value read as an output parameter

The socket must be connected before this call is made.

Parameters:
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 int QoreSocket::recvu2LSB ( int  timeout,
unsigned short *  val 
)

reads a 2-byte unsigned integer in LSB (Most Significant Byte first, little endian) format from the socket with a timeout value and returns the value read as an output parameter

The socket must be connected before this call is made.

Note:
that this is not network byte order, normally QoreSocket::recvu2() should be used instead
Parameters:
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 int QoreSocket::recvu4 ( int  timeout,
unsigned int *  val 
)

reads a 4-byte unsigned integer in MSB (Most Significant Byte first, big endian, network) format from the socket with a timeout value and returns the value read as an output parameter

The socket must be connected before this call is made.

Parameters:
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 int QoreSocket::recvu4LSB ( int  timeout,
unsigned int *  val 
)

reads a 4-byte unsigned integer in LSB (Most Significant Byte first, little endian) format from the socket with a timeout value and returns the value read as an output parameter

The socket must be connected before this call is made.

Note:
that this is not network byte order, normally QoreSocket::recvu4() should be used instead
Parameters:
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 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::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 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, 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 
)

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

doxygen