BSD style: see
license.txt
Mar 2004 : Initial release
Jan 2005 : RedShodan patch for timeout query
Dec 2006 : Outback release
Kris
- class SocketConduit : Conduit, ISelectable ¶#
-
A wrapper around the bare Socket to implement the IConduit abstraction
and add socket-specific functionality.
SocketConduit data-transfer is typically performed in conjunction with
an IBuffer, but can happily be handled directly using void array where
preferred
- this() ¶#
-
Create a streaming Internet Socket
- this(AddressFamily family, SocketType type, ProtocolType protocol) ¶#
-
Create an Internet Socket with the provided characteristics
- this(AddressFamily family, SocketType type, ProtocolType protocol, bool create) [private] ¶#
-
Create an Internet Socket. See method allocate() below
- char[] toString() [override] ¶#
-
Return the name of this device
- Socket socket() ¶#
-
Return the socket wrapper
- size_t bufferSize() [override] ¶#
-
Return a preferred size for buffering conduit I/O
- Handle fileHandle() ¶#
-
Models a handle-oriented device.
figure out how to avoid exposing this in the general
case
- SocketConduit setTimeout(float timeout) ¶#
-
Set the read timeout to the specified interval. Set a
value of zero to disable timeout support.
The interval is in units of seconds, where 0.500 would
represent 500 milliseconds. Use TimeSpan.interval to
convert from a TimeSpan instance.
- bool hadTimeout() ¶#
-
Did the last operation result in a timeout?
- bool isAlive() [override] ¶#
-
Is this socket still alive?
- SocketConduit connect(Address addr) ¶#
-
Connect to the provided endpoint
- SocketConduit bind(Address address) ¶#
-
Bind the 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.
- SocketConduit shutdown() ¶#
-
Inform other end of a connected socket that we're no longer
available. In general, this should be invoked before close()
is invoked
The shutdown function shuts down the connection of the socket:
- stops receiving data for this socket. If further data
arrives, it is rejected.
- stops trying to transmit data from this socket. Also
discards any data waiting to be sent. Stop looking for
acknowledgement of data already sent; don't retransmit
if any data is lost.
- void detach() [override] ¶#
-
Release this SocketConduit
Note that one should always disconnect a SocketConduit
under normal conditions, and generally invoke shutdown
on all connected sockets beforehand
- size_t read(void[] dst) [override] ¶#
-
Read content from the socket. Note that the operation
may timeout if method setTimeout() has been invoked with
a non-zero value.
Returns the number of bytes read from the socket, or
IConduit.Eof where there's no more content available.
If the underlying socket is a blocking socket, Eof will
only be returned once the socket has closed.
Note that a timeout is equivalent to Eof. Isolating
a timeout condition can be achieved via hadTimeout()
Note also that a zero return value is not legitimate;
such a value indicates Eof
- size_t write(void[] src) [override] ¶#
-
Callback routine to write the provided content to the
socket. This will stall until the socket responds in
some manner. Returns the number of bytes sent to the
output, or IConduit.Eof if the socket cannot write.
- size_t read(void[] dst, size_t delegate(void[]) dg) [package, synchronized, final] ¶#
-
Internal routine to handle socket read under a timeout.
Note that this is synchronized, in order to serialize
socket access
- SocketConduit allocate() [package, synchronized, static] ¶#
-
Allocate a SocketConduit from a list rather than creating
a new one. Note that the socket itself is not opened; only
the wrappers. This is because the socket is often assigned
directly via accept()
- void deallocate(SocketConduit s) [private, synchronized, static] ¶#
-
Return this SocketConduit to the free-list