BSD style: see
license.txt
Initial release: March 2004
Christopher Miller
Kris Bell
Anders F Bjorklund (Darwin patches)
The original code has been modified in several ways:
1) It has been altered to fit within the Tango environment, meaning
that certain original classes have been reorganized, and/or have
subclassed Tango base-classes. For example, the original Socket
class has been wrapped with three distinct subclasses, and now
derives from class tango.io.Resource.
2) All exception instances now subclass the Tango IOException.
3) Construction of new Socket instances via accept() is now
overloadable.
4) Constants and enums have been moved within a class boundary to
ensure explicit namespace usage.
5) changed Socket.select() to loop if it was interrupted.
All changes within the main body of code all marked with "Tango:"
For a good tutorial on socket-programming I highly recommend going
http://www.ecst.csuchico.edu/~beej/guide/net/
- socket_t INVALID_SOCKET [private, const] ¶#
-
- struct timeval ¶#
-
Internal structs:
- int strlen(char*) [private, extern(C)] ¶#
-
- int lastError() [public, static] ¶#
-
Public interface ...
- enum SocketOption [public] ¶#
-
- union linger [public] ¶#
-
- enum SocketOptionLevel [public] ¶#
-
- enum SocketShutdown [public] ¶#
-
- enum SocketFlags [public] ¶#
-
- enum SocketType [public] ¶#
-
Communication semantics
- STREAM ¶#
-
sequenced, reliable, two-way communication-based byte streams
- DGRAM ¶#
-
connectionless, unreliable datagrams with a fixed maximum length; data may be lost or arrive out of order
- RAW ¶#
-
raw protocol access
- RDM ¶#
-
reliably-delivered message datagrams
- SEQPACKET ¶#
-
sequenced, reliable, two-way connection-based datagrams with a fixed maximum length
- enum ProtocolType [public] ¶#
-
Protocol
- IP ¶#
-
internet protocol version 4
- ICMP ¶#
-
internet control message protocol
- IGMP ¶#
-
internet group management protocol
- GGP ¶#
-
gateway to gateway protocol
- TCP ¶#
-
transmission control protocol
- PUP ¶#
-
PARC universal packet protocol
- UDP ¶#
-
user datagram protocol
- IDP ¶#
-
Xerox NS protocol
- class Socket [public] ¶#
-
- this(AddressFamily family, SocketType type, ProtocolType protocol, bool create = true) ¶#
-
Describe a socket flavor. If a single protocol type exists to support
this socket type within the address family, the ProtocolType may be
omitted.
- void initialize(socket_t sock = sock.init) [private] ¶#
-
Create or assign a socket
- socket_t fileHandle() ¶#
-
Return the underlying OS handle of this Conduit
- void reopen(socket_t sock = sock.init) ¶#
-
Create a new native socket instance for this Socket
- bool isAlive() ¶#
-
Is this socket still alive? A closed socket is considered to
be dead, but a shutdown socket is still alive.
- char[] toString() [override] ¶#
-
- bool blocking() ¶#
-
getter
- void blocking(bool byes) ¶#
-
setter
- AddressFamily addressFamily() ¶#
-
- Socket bind(Address addr) ¶#
-
- Socket connect(Address to) ¶#
-
- Socket listen(int backlog) ¶#
-
need to bind() first
- Socket accept() ¶#
-
Accept an incoming connection. If the socket is blocking, accept
waits for a connection request. Throws SocketAcceptException if unable
to accept. See accepting for use with derived classes.
- Socket shutdown(SocketShutdown how) ¶#
-
The shutdown function shuts down the connection of the socket.
Depending on the argument value, it will:
- stop receiving data for this socket. If further data
arrives, it is rejected.
- stop 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.
- Socket setLingerPeriod(int period) ¶#
-
added
- Socket setAddressReuse(bool enabled) ¶#
-
added
- Socket setNoDelay(bool enabled) ¶#
-
added
- void joinGroup(IPv4Address address, bool onOff) ¶#
-
Helper function to handle the adding and dropping of group
membership.
Added
- void detach() ¶#
-
calling shutdown() before this is recommended for connection-
oriented sockets
- Address newFamilyObject() ¶#
-
- char[] hostName() [static] ¶#
-
added this to return the hostname
- uint hostAddress() [static] ¶#
-
added this to return the default host address (IPv4)
- Address remoteAddress() ¶#
-
- Address localAddress() ¶#
-
- int ERROR [const] ¶#
-
Send or receive error code.
- int send(void[] buf, SocketFlags flags = SocketFlags.NONE) ¶#
-
Send data on the connection. Returns the number of bytes actually
sent, or ERROR on failure. If the socket is blocking and there is no
buffer space left, send waits.
- int sendTo(void[] buf, SocketFlags flags, Address to) ¶#
- int sendTo(void[] buf, Address to) ¶#
- int sendTo(void[] buf, SocketFlags flags = SocketFlags.NONE) ¶#
-
Send data to a specific destination Address. If the destination address is not specified, a connection must have been made and that address is used. If the socket is blocking and there is no buffer space left, sendTo waits.
- int receive(void[] buf, SocketFlags flags = SocketFlags.NONE) ¶#
-
Receive data on the connection. Returns the number of bytes actually
received, 0 if the remote side has closed the connection, or ERROR on
failure. If the socket is blocking, receive waits until there is data
to be received.
- int receiveFrom(void[] buf, SocketFlags flags, Address from) ¶#
- int receiveFrom(void[] buf, Address from) ¶#
- int receiveFrom(void[] buf, SocketFlags flags = SocketFlags.NONE) ¶#
-
Receive data and get the remote endpoint Address. Returns the number of bytes actually received, 0 if the remote side has closed the connection, or ERROR on failure. If the socket is blocking, receiveFrom waits until there is data to be received.
- int getOption(SocketOptionLevel level, SocketOption option, void[] result) ¶#
-
returns the length, in bytes, of the actual result - very
different from getsockopt()
- Socket setOption(SocketOptionLevel level, SocketOption option, void[] value) ¶#
-
- void exception(char[] msg) [protected, static] ¶#
-
added this common function
- void badArg(char[] msg) [protected, static] ¶#
-
added this common function
- int select(SocketSet checkRead, SocketSet checkWrite, SocketSet checkError, timeval* tv) [static] ¶#
-
SocketSet's are updated to include only those sockets which an
event occured.
Returns the number of events, 0 on timeout, or -1 on error
for a connect()ing socket, writeability means connected
for a listen()ing socket, readability means listening
possibly internally limited to 64 sockets per set
- int select(SocketSet checkRead, SocketSet checkWrite, SocketSet checkError, TimeSpan time) [static] ¶#
-
select with specified timeout
- int select(SocketSet checkRead, SocketSet checkWrite, SocketSet checkError) [static] ¶#
-
select with maximum timeout
- timeval toTimeval(TimeSpan time) [static] ¶#
-
Handy utility for converting TimeSpan into timeval
- class Address [public, abstract] ¶#
-
- void exception(char[] msg) [static] ¶#
-
added this common function
- class UnknownAddress : Address [public] ¶#
-
- sockaddr* name() [protected] ¶#
-
- int nameLen() [protected] ¶#
-
- AddressFamily addressFamily() [public] ¶#
-
- char[] toString() [public] ¶#
-
- class NetHost [public] ¶#
-
- void validHostent(hostent* he) [protected] ¶#
-
- void populate(hostent* he) ¶#
-
- bool getHostByName(char[] name) ¶#
-
- bool getHostByAddr(uint addr) ¶#
-
- bool getHostByAddr(char[] addr) ¶#
-
- class IPv4Address : Address [public] ¶#
-
- struct sockaddr_in [protected] ¶#
-
- sockaddr* name() [protected] ¶#
-
- int nameLen() [protected] ¶#
-
- this() [public] ¶#
-
- AddressFamily addressFamily() [public] ¶#
-
- ushort port() [public] ¶#
-
- uint addr() [public] ¶#
-
- this(char[] addr, int port = PORT_ANY) [public] ¶#
-
-port- can be PORT_ANY
-addr- is an IP address or host name
- this(uint addr, ushort port) [public] ¶#
-
- this(ushort port) [public] ¶#
-
- char[] toAddrString() [public, synchronized] ¶#
-
- char[] toPortString() [public] ¶#
-
- char[] toString() [public] ¶#
-
- uint parse(char[] addr) [public, static] ¶#
-
-addr- is an IP address in the format "a.b.c.d"
returns ADDR_NONE on failure
- class SocketSet [public] ¶#
-
- this(uint max) [public] ¶#
-
- this(SocketSet o) [public] ¶#
-
- this() [public] ¶#
-
- SocketSet dup() [public] ¶#
-
- void reset() [public] ¶#
-
- void add(socket_t s) [public] ¶#
-
- void add(Socket s) [public] ¶#
-
- void remove(socket_t s) [public] ¶#
-
- void remove(Socket s) [public] ¶#
-
- int isSet(socket_t s) [public] ¶#
-
- int isSet(Socket s) [public] ¶#
-
- uint max() [public] ¶#
-
max sockets that can be added, like FD_SETSIZE
- fd_set* toFd_set() [public] ¶#
-