License:
BSD style: see license.txt
Version:
Mar 2004 : Initial release
Version:
Jan 2005 : RedShodan patch for timeout query
Version:
Dec 2006 : Outback release
author:
Kris
- class
SocketConduit
: tango.io.device.Conduit.Conduit, tango.io.model.IConduit.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
- char[]
toString
();
- Return the name of this device
- Socket
socket
();
- Return the
socket
wrapper
- uint
bufferSize
();
- Return a preferred size for buffering conduit I/O
- Handle
fileHandle
();
- Models a handle-oriented device.
TODO:
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
();
- 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
();
- Release this SocketConduit
Note that one should always disconnect a SocketConduit
under normal conditions, and generally invoke shutdown
on all connected sockets beforehand
- uint
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.
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
- uint
write
(void[] src);
- 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
.
- package final synchronized uint
read
(void[] dst, uint delegate(void[]) dg);
- Internal routine to handle socket
read
under a timeout.
Note that this is synchronized, in order to serialize
socket access
- package static synchronized SocketConduit
allocate
();
- 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()
|