SSLSocket

SSLSocket is a sub-class of Socket. It's purpose is to provide SSL encryption at the socket level as well as easily fit into existing Tango network applications that may already be using Socket.

SSLSocket requires the OpenSSL library, and uses a dynamic binding to the library. You can find the library at http://www.openssl.org and a Win32 specific port at http://www.slproweb.com/products/Win32OpenSSL.html.

SSLSockets have two modes:

1. Client mode, useful for connecting to existing servers, but not accepting new connections. Accepting a new connection will cause the library to stall on a write on connection.

2. Server mode, useful for creating an SSL server, but not connecting to an existing server. Connection will cause the library to stall on a read on connection.

Example SSL client

auto s = new SSLSocket;
if (s.connect("www.yahoo.com", 443))
{
    char[1024] buff;

    s.write("GET / HTTP/1.0\r\n\r\n");
    auto bytesRead = s.read(buff);
    if (bytesRead != s.Eof)
        Stdout.formatln("received: {}", buff[0..bytesRead]);
}

Constructors

this
this(bool config)

Create a default Client Mode SSLSocket.

Members

Functions

detach
void detach()

Release this SSLSocket.

read
size_t read(void[] dst)

Reads from the underlying socket stream. If needed, setTimeout will set the max length of time the read will take before returning.

setCtx
void setCtx(SSLCtx ctx, bool clientMode)

Used in conjuction with the above ctor with the create flag disabled. It is useful for accepting a new socket into a SSLSocket, and then re-using the Server's existing SSLCtx.

shutdown
SSLSocket shutdown()

Shuts down the underlying socket for reading and writing.

write
size_t write(const(void)[] src)

Writes the passed buffer to the underlying socket stream. This will block until socket error.

Variables

sslCtx
SSLCtx sslCtx;
Undocumented in source.
sslSocket
BIO* sslSocket;
Undocumented in source.

Inherited Members

From Socket

socket
alias socket = native
Undocumented in source.
setTimeout
deprecated void setTimeout(double t)

see super.timeout(int)

hadTimeout
deprecated bool hadTimeout()
Undocumented in source. Be warned that the author may not have intended to support it.
toString
string toString()

Return the name of this device

fileHandle
Handle fileHandle [@property getter]

Models a handle-oriented device.

native
Berkeley* native [@property getter]

Return the socket wrapper

bufferSize
size_t bufferSize [@property getter]

Return a preferred size for buffering conduit I/O

connect
Socket connect(const(char)[] address, uint port)

Connect to the provided endpoint

connect
Socket connect(Address addr)

Connect to the provided endpoint

bind
Socket bind(Address address)

Bind this socket. This is typically used to configure a listening socket (such as a server or multicast socket). The address given should describe a local adapter, or specify the port alone (ADDR_ANY) to have the OS assign a local adapter address.

shutdown
Socket shutdown()

Inform other end of a connected socket that we're no longer available. In general, this should be invoked before close()

detach
void detach()

Release this Socket

read
size_t read(void[] dst)

Read content from the socket. Note that the operation may timeout if method setTimeout() has been invoked with a non-zero value.

write
size_t write(const(void)[] src)
copy
OutputStream copy(InputStream src, size_t max)

Transfer the content of another conduit to this one. Returns the dst OutputStream, or throws IOException on failure.

wait
bool wait(bool reading)

Manage socket IO under a timeout

error
void error()

Throw an IOException noting the last error

asyncCopy
Socket asyncCopy(Handle file)

Meta