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

SocketConduit Class Reference

Inheritance diagram for SocketConduit:

Socket IConduit ISocketReader List of all members.

Public Member Functions

 this ()
IBuffer createBuffer ()
void setTimeout (uint us)
bool hadTimeout ()
void attach (IConduitSource input)
void attach (IConduitSink output)
int read (void[] src)
int write (void[] src)
int read (IBuffer target)
int write (IBuffer source)
bool isSeekable ()
bool isReadable ()
bool isWritable ()
IConduit copy (IConduit source)
IConduit flush (IBuffer source)
ConduitStyle getStyle ()

Static Public Member Functions

static SocketConduit create (socket_t handle)

Protected Member Functions

void bind (IConduitSink sink)
void bind (IConduitSource source)
void unbind ()

Private Types

enum  { Eof = -1 }

Private Member Functions

void fixup ()
 this (socket_t handle)
 this (AddressFamily af, Type type, Protocol protocol)
void set (socket_t sock)
void reset ()
void create (AddressFamily af, Type type, Protocol protocol)
socket_t handle ()
char[] toString ()
bit blocking ()
void blocking (bit byes)
AddressFamily addressFamily ()
bit isAlive ()
void bind (Address addr)
void connect (Address to)
void listen (int backlog)
Socket createSocket (socket_t handle)
Socket accept ()
void shutdown ()
void shutdown (Shutdown how)
void setLingerPeriod (int period)
void setAddressReuse (bool enabled)
bool setGroup (InternetAddress address, Option option)
void closure ()
bit poll (events)
Object getLock ()
void setLock (Object lock)
void acquire ()
bool acquireIfOpen ()
void close ()

Static Private Member Functions

static bool isCancelled ()
static void cancelAll (bool cancel)
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 Attributes

timeval tv
SocketSet ss
IConduitSource input
IConduitSink output
bool timeout

Classes

class  VersionUseFreeList

Detailed Description

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 instance, but can be handled directly using raw arrays if preferred. See FileConduit for examples of both approaches.

Definition at line 62 of file SocketConduit.d.


Member Enumeration Documentation

anonymous enum [inherited]
 

Declare the End Of File identifer

Enumeration values:
Eof 

Definition at line 68 of file IConduit.d.


Member Function Documentation

void fixup  )  [inline, private]
 

Definition at line 170 of file SocketConduit.d.

References input, and output.

Referenced by SocketConduit::VersionUseFreeList::closure(), and this().

static SocketConduit create socket_t  handle  )  [inline, static]
 

Construct this SocketConduit with the given socket handle; this is for FreeList and ServerSocket support.

Definition at line 183 of file SocketConduit.d.

References SocketConduit, and version.

this  )  [inline]
 

Create a streaming Internet Socket

Reimplemented from Resource.

Definition at line 203 of file SocketConduit.d.

References fixup().

this socket_t  handle  )  [inline, private]
 

Construct this SocketConduit with the given socket handle; this is for FreeList and ServerSocket support.

Reimplemented from Socket.

Definition at line 216 of file SocketConduit.d.

References fixup().

IBuffer createBuffer  )  [inline]
 

Create a Buffer of a conduit-specific size. I think 8K bytes is the common standard for socket buffering?

Reimplemented from IConduit.

Definition at line 229 of file SocketConduit.d.

References Buffer, and Buffer::setConduit().

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

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 243 of file SocketConduit.d.

References tv.

Referenced by HttpClient::open(), testHttpClient(), testHttpClient2(), and testSocket().

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 256 of file SocketConduit.d.

References timeout.

void attach IConduitSource  input  )  [inline]
 

Please refer to IConduit.attach for details

Reimplemented from IConduit.

Definition at line 267 of file SocketConduit.d.

References IConduitSource::bind().

void attach IConduitSink  output  )  [inline]
 

Please refer to IConduit.attach for details

Reimplemented from IConduit.

Definition at line 279 of file SocketConduit.d.

References IConduitSink::bind().

void bind IConduitSink  sink  )  [inline, protected]
 

Reimplemented from IConduitSink.

Definition at line 289 of file SocketConduit.d.

void bind IConduitSource  source  )  [inline, protected]
 

Reimplemented from IConduitSource.

Definition at line 297 of file SocketConduit.d.

void unbind  )  [inline, protected]
 

Reimplemented from IConduitSource.

Definition at line 305 of file SocketConduit.d.

int read void[]  src  )  [inline]
 

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

Reimplemented from IConduit.

Definition at line 326 of file SocketConduit.d.

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

Referenced by HttpClient::read(), testClient(), and testHttpClient2().

int write void[]  src  )  [inline]
 

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.

Reimplemented from IConduit.

Definition at line 370 of file SocketConduit.d.

References Socket::send().

Referenced by flush(), and testClient().

int read IBuffer  target  )  [inline]
 

Read from conduit into a target buffer. Note that this uses SocketSet to handle timeouts, such that the socket does not stall forever.

Reimplemented from IConduit.

Definition at line 386 of file SocketConduit.d.

References assert().

int write IBuffer  source  )  [inline]
 

Write to conduit from a source buffer.

Reimplemented from IConduit.

Definition at line 399 of file SocketConduit.d.

References assert().

bool isSeekable  )  [inline]
 

This conduit is not seekable

Reimplemented from IConduit.

Definition at line 417 of file SocketConduit.d.

bool isReadable  )  [inline]
 

This conduit is readable

Reimplemented from IConduit.

Definition at line 428 of file SocketConduit.d.

bool isWritable  )  [inline]
 

This conduit is writable

Reimplemented from IConduit.

Definition at line 439 of file SocketConduit.d.

IConduit copy IConduit  source  )  [inline]
 

Transfer the content of this conduit to another one. Returns true if all content was successfully copied.

Reimplemented from IConduit.

Definition at line 451 of file SocketConduit.d.

References assert().

Referenced by testSocket().

IConduit flush IBuffer  source  )  [inline]
 

Flush buffer content out to this conduit.

Returns true if all content is flushed; false if writing results in an Eof condition.

Definition at line 474 of file SocketConduit.d.

References write().

ConduitStyle getStyle  )  [inline]
 

Return the style used to open the conduit

Definition at line 488 of file SocketConduit.d.

References ConduitStyle::ReadWrite.

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

Definition at line 856 of file Socket.d.

References Resource::acquire(), and Socket::create().

void set socket_t  sock  )  [inline, protected, inherited]
 

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

Definition at line 505 of file Socket.d.

References Resource::acquire().

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

void reset  )  [inline, protected, inherited]
 

MANGO: added to reset socket

Definition at line 519 of file Socket.d.

References INVALID_SOCKET.

Referenced by SocketConduit::VersionUseFreeList::deallocate().

static bool isCancelled  )  [inline, static, inherited]
 

MANGO: added for subscriber control

Definition at line 533 of file Socket.d.

References Socket::cancelled.

static void cancelAll bool  cancel  )  [inline, static, inherited]
 

MANGO: added for subscriber control

Definition at line 544 of file Socket.d.

References Socket::cancelled, printf(), and version.

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

MANGO: added for multicast support

Definition at line 871 of file Socket.d.

References Socket::_family, and Socket::sock.

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

socket_t handle  )  [inline, inherited]
 

get underlying socket handle

Definition at line 886 of file Socket.d.

References Socket::sock.

Referenced by Socket::blocking(), and Socket::setGroup().

char [] toString  )  [inline, inherited]
 

Definition at line 897 of file Socket.d.

bit blocking  )  [inline, inherited]
 

getter

Definition at line 909 of file Socket.d.

References Socket::_blocking, Socket::handle(), and version.

Referenced by Socket::connect().

void blocking bit  byes  )  [inline, inherited]
 

setter

Definition at line 928 of file Socket.d.

References Socket::_blocking, Socket::handle(), Socket::sock, SOCKET_ERROR, version, and x.

AddressFamily addressFamily  )  [inline, inherited]
 

Definition at line 959 of file Socket.d.

References Socket::_family.

bit isAlive  )  [inline, inherited]
 

Definition at line 970 of file Socket.d.

References Socket::sock, and SOCKET_ERROR.

void bind Address  addr  )  [inline, inherited]
 

Definition at line 982 of file Socket.d.

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

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

void connect Address  to  )  [inline, inherited]
 

Definition at line 994 of file Socket.d.

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

Referenced by HttpClient::open(), SocketAppender::setAddress(), testClient(), testClusterServer(), testHttpClient(), testHttpClient2(), and testSocket().

void listen int  backlog  )  [inline, inherited]
 

need to bind() first

Definition at line 1026 of file Socket.d.

References Socket::sock, and SOCKET_ERROR.

Referenced by ServerSocket::this().

Socket createSocket socket_t  handle  )  [inline, protected, inherited]
 

MANGO: added

Reimplemented in ServerSocket.

Definition at line 1038 of file Socket.d.

References Socket.

Referenced by Socket::accept().

Socket accept  )  [inline, inherited]
 

Reimplemented in ServerSocket.

Definition at line 1048 of file Socket.d.

References Socket::_blocking, Socket::_family, Socket::createSocket(), INVALID_SOCKET, Socket::sock, and version.

Referenced by ServerSocket::accept().

void shutdown  )  [inline, inherited]
 

Definition at line 1074 of file Socket.d.

References Socket::sock.

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

void shutdown Shutdown  how  )  [inline, inherited]
 

Definition at line 1084 of file Socket.d.

References Socket::shutdown(), and Socket::sock.

void setLingerPeriod int  period  )  [inline, inherited]
 

MANGO: added

Reimplemented in ServerSocket.

Definition at line 1096 of file Socket.d.

References Socket::setOption().

Referenced by ServerSocket::createSocket().

void setAddressReuse bool  enabled  )  [inline, inherited]
 

MANGO: added

Definition at line 1114 of file Socket.d.

References Socket::setOption(), and x.

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

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

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

MANGO: Added

Definition at line 1130 of file Socket.d.

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

void closure  )  [inline, inherited]
 

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

MANGO: changed from close() to IResource.closure()

Reimplemented from Resource.

Definition at line 1155 of file Socket.d.

References printf(), Socket::sock, and version.

Referenced by MulticastSocket::leave().

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

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 1460 of file Socket.d.

References assert().

Referenced by Socket::poll(), and read().

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

Definition at line 1513 of file Socket.d.

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

maximum timeout

Definition at line 1528 of file Socket.d.

bit poll events   )  [inline, inherited]
 

Definition at line 1540 of file Socket.d.

References Socket::select().

Object getLock  )  [inherited]
 

Return the lock used by this resource

Reimplemented in Resource.

void setLock Object  lock  )  [inherited]
 

Set an alternate lock. Typically one would use this to synchronize multiple different Resources via a common object.

Reimplemented in Resource.

void acquire  )  [inherited]
 

hold a reference to this resource. The caller is now responsible for invoking close() upon this resource;

Reimplemented in Resource.

bool acquireIfOpen  )  [inherited]
 

If this resource is still open, acquire it and return true. This is a threadsafe test-and-set mechanism that fails only if the resource is already closed, or was never opened.

Note that you are responsible for invoking close() whenever this method returns true.

Reimplemented in Resource.

void close  )  [inherited]
 

release a reference to this resource

Reimplemented in Resource.

Referenced by SocketAppender::close(), HttpClient::close(), HttpBridge::cross(), ClusterThread::run(), and testClient().


Member Data Documentation

timeval tv [private]
 

Definition at line 64 of file SocketConduit.d.

Referenced by read(), and setTimeout().

SocketSet ss [private]
 

Definition at line 65 of file SocketConduit.d.

Referenced by read().

IConduitSource input [private]
 

Definition at line 66 of file SocketConduit.d.

Referenced by SocketConduit::VersionUseFreeList::closure(), and fixup().

IConduitSink output [private]
 

Definition at line 67 of file SocketConduit.d.

Referenced by SocketConduit::VersionUseFreeList::closure(), and fixup().

bool timeout [private]
 

Definition at line 68 of file SocketConduit.d.

Referenced by hadTimeout(), and read().


The documentation for this class was generated from the following file:
Generated on Mon Nov 14 11:00:02 2005 for Mango by  doxygen 1.4.0