Main Page | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Class Members | File Members | Related Pages

Socket Class Reference

Inheritance diagram for Socket:

Conduit DatagramSocket ServerSocket SocketConduit MulticastSocket List of all members.

Public Member Functions

uint bufferSize ()
void setTimeout (uint us)
bool hadTimeout ()
char[] toString ()
void connect (Address to)
void setLingerPeriod (int period)
Address remoteAddress ()
Address localAddress ()
bit poll (events)

Protected Member Functions

 this (socket_t sock)
uint reader (void[] dst)
uint writer (void[] src)
void set (socket_t sock)
void reset ()
 this (AddressFamily af, Type type, Protocol protocol)
void create (AddressFamily af, Type type, Protocol protocol)
socket_t handle ()
bit blocking ()
void blocking (bit byes)
AddressFamily addressFamily ()
bit isAlive ()
void bind (Address addr)
void listen (int backlog)
Socket createSocket (socket_t handle)
Socket accept ()
void shutdown ()
void shutdown (Shutdown how)
void setAddressReuse (bool enabled)
bool setGroup (InternetAddress address, Option option)
void close ()
int send (void[] buf, Flags flags=Flags.NONE)
int sendTo (void[] buf, Flags flags, Address to)
int sendTo (void[] buf, Address to)
int sendTo (void[] buf, Flags flags=Flags.NONE)
int receive (void[] buf, Flags flags=Flags.NONE)
int receiveFrom (void[] buf, Flags flags, out Address from)
int receiveFrom (void[] buf, out Address from)
int receiveFrom (void[] buf, Flags flags)
int receiveFrom (void[] buf)
int getOption (OptionLevel level, Option option, void[] result)
void setOption (OptionLevel level, Option option, void[] value)

Static Protected Member Functions

static char[] hostName ()
static uint hostAddress ()
static int select (SocketSet checkRead, SocketSet checkWrite, SocketSet checkError, timeval *tv)
static int select (SocketSet checkRead, SocketSet checkWrite, SocketSet checkError, int microseconds)
static int select (SocketSet checkRead, SocketSet checkWrite, SocketSet checkError)

Private Member Functions

void collect ()
 ~this ()
Address newFamilyObject ()
 this (ConduitStyle.Bits style, bool seekable)
bool flush (void[] src)
void attach (IConduitFilter filter)
void bind (IConduit conduit, IConduitFilter next)
void unbind ()
uint read (void[] dst)
uint write (void[] src)
bool isSeekable ()
bool isReadable ()
bool isWritable ()
bool isTextual ()
IConduit copy (IConduit source)
ConduitStyle Bits getStyle ()

Static Private Member Functions

static bool isHalting ()

Private Attributes

socket_t sock
AddressFamily _family
SocketSet ss
timeval tv
bool timeout

Detailed Description

MANGO: socket now subclasses mango.io.Resource

Definition at line 469 of file Socket.d.


Constructor & Destructor Documentation

~this  )  [inline, private]
 

Definition at line 1261 of file Socket.d.

References collect().


Member Function Documentation

this socket_t  sock  )  [inline, protected]
 

Construct a Socket from a handle. This is used internally to create new Sockets via an accept().

Reimplemented in SocketConduit.

Definition at line 782 of file Socket.d.

References set(), and sock.

uint reader void[]  dst  )  [inline, protected, virtual]
 

conduit-specific reader

Implements Conduit.

Definition at line 811 of file Socket.d.

References SocketSet::add(), receive(), SocketSet::reset(), select(), ss, timeout, and tv.

uint writer void[]  src  )  [inline, protected, virtual]
 

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.

Implements Conduit.

Definition at line 855 of file Socket.d.

References send().

uint bufferSize  )  [inline]
 

Return a preferred size for buffering conduit I/O

Reimplemented from Conduit.

Definition at line 869 of file Socket.d.

void setTimeout uint  us  )  [inline]
 

Set the read timeout to the specified microseconds. Set a value of zero to disable timeout support.

Definition at line 881 of file Socket.d.

References tv.

Referenced by HttpClient::open().

bool hadTimeout  )  [inline]
 

Did the last operation result in a timeout? Note that this assumes there is no thread contention on this object.

Definition at line 894 of file Socket.d.

References timeout.

void set socket_t  sock  )  [inline, protected]
 

MANGO: moved this out from the above constructor so that it can be called from the FreeList version of SocketConduit

Definition at line 906 of file Socket.d.

Referenced by SocketConduit::allocate(), and this().

void reset  )  [inline, protected]
 

MANGO: added to reset socket

Definition at line 917 of file Socket.d.

References INVALID_SOCKET.

Referenced by SocketConduit::deallocate().

this AddressFamily  af,
Type  type,
Protocol  protocol
[inline, protected]
 

Definition at line 931 of file Socket.d.

References create(), and type().

void create AddressFamily  af,
Type  type,
Protocol  protocol
[inline, protected]
 

MANGO: added for multicast support

Definition at line 945 of file Socket.d.

References _family, sock, and type().

Referenced by ServerSocket::createSocket(), MulticastSocket::leave(), and this().

socket_t handle  )  [inline, protected]
 

get underlying socket handle

Definition at line 960 of file Socket.d.

References sock.

Referenced by blocking(), and setGroup().

char [] toString  )  [inline]
 

Definition at line 971 of file Socket.d.

bit blocking  )  [inline, protected]
 

getter

Definition at line 983 of file Socket.d.

References handle(), and version.

Referenced by connect().

void blocking bit  byes  )  [inline, protected]
 

setter

Definition at line 1002 of file Socket.d.

References handle(), sock, SOCKET_ERROR, and version.

AddressFamily addressFamily  )  [inline, protected]
 

Definition at line 1033 of file Socket.d.

References _family.

bit isAlive  )  [inline, protected]
 

Definition at line 1044 of file Socket.d.

References sock, SOCKET_ERROR, and type().

void bind Address  addr  )  [inline, protected]
 

Definition at line 1056 of file Socket.d.

References Address::name(), Address::nameLen(), sock, and SOCKET_ERROR.

Referenced by MulticastSocket::join(), and ServerSocket::this().

void connect Address  to  )  [inline]
 

Definition at line 1068 of file Socket.d.

References assert(), blocking(), Address::name(), Address::nameLen(), sock, SOCKET_ERROR, and version.

Referenced by HttpClient::open(), and SocketAppender::setAddress().

void listen int  backlog  )  [inline, protected]
 

need to bind() first

Definition at line 1100 of file Socket.d.

References sock, and SOCKET_ERROR.

Referenced by ServerSocket::this().

Socket createSocket socket_t  handle  )  [inline, protected]
 

MANGO: added

Reimplemented in ServerSocket.

Definition at line 1112 of file Socket.d.

References Socket.

Referenced by accept().

Socket accept  )  [inline, protected]
 

Reimplemented in ServerSocket.

Definition at line 1122 of file Socket.d.

References _family, createSocket(), INVALID_SOCKET, sock, and version.

Referenced by ServerSocket::accept().

void shutdown  )  [inline, protected]
 

Definition at line 1148 of file Socket.d.

References sock.

Referenced by HttpClient::close(), and shutdown().

void shutdown Shutdown  how  )  [inline, protected]
 

Definition at line 1158 of file Socket.d.

References shutdown(), and sock.

void setLingerPeriod int  period  )  [inline]
 

MANGO: added

Reimplemented in ServerSocket.

Definition at line 1170 of file Socket.d.

References setOption().

Referenced by ServerSocket::createSocket().

void setAddressReuse bool  enabled  )  [inline, protected]
 

MANGO: added

Definition at line 1188 of file Socket.d.

References setOption().

Referenced by MulticastSocket::join(), and ServerSocket::this().

bool setGroup InternetAddress  address,
Option  option
[inline, protected]
 

Helper function to handle the adding and dropping of group membership.

MANGO: Added

Definition at line 1204 of file Socket.d.

References handle(), InternetAddress::sin, and SOCKET_ERROR.

void close  )  [inline, protected]
 

calling shutdown() before this is recommended for connection- oriented sockets

Reimplemented from Conduit.

Reimplemented in SocketConduit.

Definition at line 1227 of file Socket.d.

References collect().

Referenced by MulticastSocket::leave().

void collect  )  [inline, private]
 

Definition at line 1237 of file Socket.d.

References printf(), sock, and version.

Referenced by close(), and ~this().

Address newFamilyObject  )  [inline, private]
 

Definition at line 1272 of file Socket.d.

References _family.

Referenced by localAddress(), receiveFrom(), and remoteAddress().

static char [] hostName  )  [inline, static, protected]
 

Mango: added this to return the hostname

Definition at line 1294 of file Socket.d.

References SOCKET_ERROR, and strlen().

Referenced by hostAddress().

static uint hostAddress  )  [inline, static, protected]
 

Mango: added this to return the default host address (IPv4)

Definition at line 1310 of file Socket.d.

References InternetHost::addrList, assert(), InternetHost::getHostByName(), and hostName().

Address remoteAddress  )  [inline]
 

Definition at line 1326 of file Socket.d.

References _family, Address::addressFamily(), assert(), Address::name(), Address::nameLen(), newFamilyObject(), sock, and SOCKET_ERROR.

Referenced by AbstractServer::getRemoteAddress().

Address localAddress  )  [inline]
 

Definition at line 1342 of file Socket.d.

References _family, Address::addressFamily(), assert(), Address::name(), Address::nameLen(), newFamilyObject(), sock, and SOCKET_ERROR.

Referenced by AbstractServer::getHost(), and AbstractServer::getPort().

int send void[]  buf,
Flags  flags = Flags.NONE
[inline, protected]
 

returns number of bytes actually sent, or -1 on error

Definition at line 1359 of file Socket.d.

References sock.

Referenced by writer().

int sendTo void[]  buf,
Flags  flags,
Address  to
[inline, protected]
 

-to- is ignored if connected ?

Definition at line 1372 of file Socket.d.

References Address::name(), Address::nameLen(), and sock.

Referenced by sendTo().

int sendTo void[]  buf,
Address  to
[inline, protected]
 

-to- is ignored if connected ?

Definition at line 1385 of file Socket.d.

References sendTo().

int sendTo void[]  buf,
Flags  flags = Flags.NONE
[inline, protected]
 

assumes you connect()ed

Definition at line 1397 of file Socket.d.

References sock.

int receive void[]  buf,
Flags  flags = Flags.NONE
[inline, protected]
 

returns number of bytes actually received, 0 on connection closure, or -1 on error

Definition at line 1411 of file Socket.d.

References sock, and SOCKET_ERROR.

Referenced by reader().

int receiveFrom void[]  buf,
Flags  flags,
out Address  from
[inline, protected]
 

-from- is ignored if connected ?

Definition at line 1429 of file Socket.d.

References _family, assert(), from(), Address::nameLen(), newFamilyObject(), printf(), sock, SOCKET_ERROR, and version.

Referenced by receiveFrom().

int receiveFrom void[]  buf,
out Address  from
[inline, protected]
 

-from- is ignored if connected ?

Definition at line 1459 of file Socket.d.

References from(), and receiveFrom().

int receiveFrom void[]  buf,
Flags  flags
[inline, protected]
 

assumes you connect()ed

Definition at line 1471 of file Socket.d.

References sock, and SOCKET_ERROR.

int receiveFrom void[]  buf  )  [inline, protected]
 

assumes you connect()ed

Definition at line 1489 of file Socket.d.

References receiveFrom().

int getOption OptionLevel  level,
Option  option,
void[]  result
[inline, protected]
 

returns the length, in bytes, of the actual result - very different from getsockopt()

Definition at line 1502 of file Socket.d.

References sock, and SOCKET_ERROR.

void setOption OptionLevel  level,
Option  option,
void[]  value
[inline, protected]
 

Definition at line 1516 of file Socket.d.

References sock, and SOCKET_ERROR.

Referenced by setAddressReuse(), setLingerPeriod(), and MulticastSocket::setLoopback().

static int select SocketSet  checkRead,
SocketSet  checkWrite,
SocketSet  checkError,
timeval *  tv
[inline, static, protected]
 

SocketSet's are updated to include only those sockets which an event occured.

Returns the number of events, 0 on timeout, or -1 on interruption

for a connect()ing socket, writeability means connected for a listen()ing socket, readability means listening

Winsock: possibly internally limited to 64 sockets per set

Definition at line 1550 of file Socket.d.

References assert().

Referenced by poll(), and reader().

static int select SocketSet  checkRead,
SocketSet  checkWrite,
SocketSet  checkError,
int  microseconds
[inline, static, protected]
 

Definition at line 1603 of file Socket.d.

static int select SocketSet  checkRead,
SocketSet  checkWrite,
SocketSet  checkError
[inline, static, protected]
 

maximum timeout

Definition at line 1618 of file Socket.d.

bit poll events   )  [inline]
 

Definition at line 1630 of file Socket.d.

References select().

this ConduitStyle.Bits  style,
bool  seekable
[inline, inherited]
 

Construct a conduit with the given style and seek abilities. Conduits are either seekable or non-seekable.

Reimplemented in DeviceConduit.

Definition at line 104 of file Conduit.d.

References Conduit::filter, Conduit::seekable, and Conduit::style.

bool flush void[]  src  )  [inline, inherited]
 

flush provided content to the conduit

Reimplemented from IConduit.

Definition at line 132 of file Conduit.d.

References Conduit::write().

void attach IConduitFilter  filter  )  [inline, inherited]
 

Please refer to IConduit.attach for details

Reimplemented from IConduit.

Definition at line 150 of file Conduit.d.

References IConduitFilter::bind().

void bind IConduit  conduit,
IConduitFilter  next
[inline, protected, inherited]
 

Reimplemented from IConduitFilter.

Definition at line 159 of file Conduit.d.

void unbind  )  [inline, protected, inherited]
 

Reimplemented from IConduitFilter.

Definition at line 167 of file Conduit.d.

uint read void[]  dst  )  [inline, inherited]
 

read from conduit into a target buffer

Reimplemented from IConduit.

Definition at line 177 of file Conduit.d.

References Conduit::filter, and IConduitFilter::reader().

Referenced by DeviceConduit::VersionPosix::reader().

uint write void[]  src  )  [inline, inherited]
 

write to conduit from a source buffer

Reimplemented from IConduit.

Definition at line 188 of file Conduit.d.

References Conduit::filter, and IConduitFilter::writer().

Referenced by Conduit::flush(), and DeviceConduit::VersionPosix::writer().

bool isSeekable  )  [inline, inherited]
 

Returns true if this conduit is seekable (whether it implements ISeekable)

Reimplemented from IConduit.

Definition at line 200 of file Conduit.d.

References Conduit::seekable.

bool isReadable  )  [inline, inherited]
 

Returns true is this conduit can be read from

Reimplemented from IConduit.

Definition at line 211 of file Conduit.d.

References ConduitStyle::access(), ConduitStyle::Read, and Conduit::style.

bool isWritable  )  [inline, inherited]
 

Returns true if this conduit can be written to

Reimplemented from IConduit.

Definition at line 222 of file Conduit.d.

References ConduitStyle::access(), Conduit::style, and ConduitStyle::Write.

bool isTextual  )  [inline, inherited]
 

Returns true if this conduit is text-based

Reimplemented from IConduit.

Reimplemented in SocketConduit.

Definition at line 233 of file Conduit.d.

References ConduitStyle::access(), Conduit::style, and ConduitStyle::Text.

IConduit copy IConduit  source  )  [inline, inherited]
 

Transfer the content of another conduit to this one. Returns a reference to this class, and throws IOException on failure.

Reimplemented from IConduit.

Definition at line 245 of file Conduit.d.

References Buffer, and buffer.

ConduitStyle Bits getStyle  )  [inline, inherited]
 

Return the style used when creating this conduit

Definition at line 264 of file Conduit.d.

References Conduit::style.

static bool isHalting  )  [inline, static, inherited]
 

Is the application terminating?

Definition at line 275 of file Conduit.d.

References halting.


Member Data Documentation

socket_t sock [private]
 

Definition at line 471 of file Socket.d.

Referenced by accept(), bind(), blocking(), collect(), connect(), create(), getOption(), handle(), isAlive(), listen(), localAddress(), receive(), receiveFrom(), remoteAddress(), send(), sendTo(), setOption(), shutdown(), and this().

AddressFamily _family [private]
 

Definition at line 472 of file Socket.d.

Referenced by accept(), addressFamily(), create(), localAddress(), newFamilyObject(), receiveFrom(), and remoteAddress().

SocketSet ss [private]
 

Callback routine to 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

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

Definition at line 807 of file Socket.d.

Referenced by reader().

timeval tv [private]
 

Definition at line 808 of file Socket.d.

Referenced by reader(), and setTimeout().

bool timeout [private]
 

Definition at line 809 of file Socket.d.

Referenced by hadTimeout(), and reader().


The documentation for this class was generated from the following file:
Generated on Sat Dec 24 17:28:42 2005 for Mango by  doxygen 1.4.0