# HG changeset patch # User rick@minifunk # Date 1213326737 14400 # Node ID d3374d55398687b072f3f7458e62b989e74eb1b7 # Parent b5c7dc3922c6e1fedf797a30c3af3116be6192ff updates diff -r b5c7dc3922c6 -r d3374d553986 dreactor/core/ConnectionHandler.d --- a/dreactor/core/ConnectionHandler.d Sun Jun 08 01:52:15 2008 -0400 +++ b/dreactor/core/ConnectionHandler.d Thu Jun 12 23:12:17 2008 -0400 @@ -37,17 +37,14 @@ Standard Ctor, takes a transport **************************************************************************/ - this (Conduit trans, bool islistener = false) + this (Conduit trans, bool listener = false) { - state = State.init; transport = trans; ibuf_len = 0; obuf_len = 0; i_offset = 0; o_offset = 0; - isListener = islistener; } - /********************************************************************** @@ -236,6 +233,21 @@ return out_buffers.head()[o_offset .. $]; } + + /************************************************************************** + + listen + Enable listening on the socket attached to this connectionhandler + + **************************************************************************/ + int listen(IPv4Address addr) + { + transport.bind().listen(); + state = listening; + setConnectionHandler() + } + + /************************************************************************** Configuration functions @@ -255,7 +267,7 @@ } void remEvent(Event e) { - events_ &= ^e; + events_ ^= e; } State getState() {return state;} diff -r b5c7dc3922c6 -r d3374d553986 dreactor/core/SelectLoop.d --- a/dreactor/core/SelectLoop.d Sun Jun 08 01:52:15 2008 -0400 +++ b/dreactor/core/SelectLoop.d Thu Jun 12 23:12:17 2008 -0400 @@ -10,8 +10,6 @@ *******************************************************************************/ - - module dreactor.core.SelectLoop; import dreactor.transport.AsyncSocketConduit; diff -r b5c7dc3922c6 -r d3374d553986 dreactor/transport/AsyncSocketConduit.d --- a/dreactor/transport/AsyncSocketConduit.d Sun Jun 08 01:52:15 2008 -0400 +++ b/dreactor/transport/AsyncSocketConduit.d Thu Jun 12 23:12:17 2008 -0400 @@ -1,16 +1,16 @@ /******************************************************************************* - copyright: Copyright (c) 2004 Kris Bell. All rights reserved +copyright: Copyright (c) 2004 Kris Bell. All rights reserved - license: BSD style: $(LICENSE) +license: BSD style: $(LICENSE) - version: Mar 2004 : Initial release - version: Jan 2005 : RedShodan patch for timeout query - version: Dec 2006 : Outback release - - author: Kris, modified by Rick Richardson (May 2008) +version: Mar 2004 : Initial release +version: Jan 2005 : RedShodan patch for timeout query +version: Dec 2006 : Outback release -*******************************************************************************/ +author: Kris, modified by Rick Richardson (May 2008) + + *******************************************************************************/ module dreactor.transport.AsyncSocketConduit; @@ -20,239 +20,253 @@ private import tango.net.Socket; +import tango.net.Socket.Address; + /******************************************************************************* - A wrapper around the bare Socket to implement the IConduit abstraction - and add socket-specific functionality specifically for multiplexing via - poll and the ilk. + A wrapper around the bare Socket to implement the IConduit abstraction + and add socket-specific functionality specifically for multiplexing via + poll and the ilk. - AsyncSocketConduit data-transfer is typically performed in conjunction with - an IBuffer, but can happily be handled directly using void array where - preferred - -*******************************************************************************/ + AsyncSocketConduit data-transfer is typically performed in conjunction with + an IBuffer, but can happily be handled directly using void array where + preferred + + *******************************************************************************/ +alias IPv4Address Address; class AsyncSocketConduit : Conduit { - package Socket socket_; + package Socket socket_; - /*********************************************************************** - - Create a streaming Internet Socket + /*********************************************************************** + + Create a streaming Internet Socket - ***********************************************************************/ - /* overriding the enum from the IConduit interface */ - enum : uint - { - Eof = uint.max, /// the End-of-Flow identifer - Err = uint.max -1 // some error ocurred, Should disconnect - } + ***********************************************************************/ + /* overriding the enum from the IConduit interface */ + enum : uint + { + Eof = uint.max, /// the End-of-Flow identifer + Err = uint.max -1 // some error ocurred, Should disconnect + } - this () - { - this (SocketType.STREAM, ProtocolType.TCP); - } + this () + { + this (SocketType.STREAM, ProtocolType.TCP); + } - /*********************************************************************** - - Create an Internet Socket. Used by subclasses and by - ServerSocket; the latter via method allocate() below + /*********************************************************************** - ***********************************************************************/ + Create an Internet Socket. Used by subclasses and by + ServerSocket; the latter via method allocate() below + + ***********************************************************************/ - protected this (SocketType type, ProtocolType protocol, bool create=true) - { - socket_ = new Socket (AddressFamily.INET, type, protocol, create); - } + protected this (SocketType type, ProtocolType protocol, bool create=true) + { + socket_ = new Socket (AddressFamily.INET, type, protocol, create); + } - /*********************************************************************** + /*********************************************************************** - Return the name of this device + Return the name of this device - ***********************************************************************/ + ***********************************************************************/ - override char[] toString() - { - return socket.toString; - } + override char[] toString() + { + return socket.toString; + } - /*********************************************************************** + /*********************************************************************** + + Return the socket wrapper - Return the socket wrapper - - ***********************************************************************/ + ***********************************************************************/ - Socket socket () - { - return socket_; - } + Socket socket () + { + return socket_; + } - /*********************************************************************** + /*********************************************************************** + + Return a preferred size for buffering conduit I/O - Return a preferred size for buffering conduit I/O - - ***********************************************************************/ + ***********************************************************************/ - override uint bufferSize () - { - return 1024 * 8; - } + override uint bufferSize () + { + return 1024 * 8; + } - /*********************************************************************** + /*********************************************************************** - Models a handle-oriented device. + Models a handle-oriented device. - TODO: figure out how to avoid exposing this in the general - case + TODO: figure out how to avoid exposing this in the general + case - ***********************************************************************/ + ***********************************************************************/ - override Handle fileHandle () - { - return cast(Handle) socket_.fileHandle; - } + override Handle fileHandle () + { + return cast(Handle) socket_.fileHandle; + } - /*********************************************************************** + /*********************************************************************** - Is this socket still alive? + Is this socket still alive? + + ***********************************************************************/ - ***********************************************************************/ + override bool isAlive () + { + return socket_.isAlive; + } - override bool isAlive () - { - return socket_.isAlive; - } + /*********************************************************************** - /*********************************************************************** + Connect to the provided endpoint - Connect to the provided endpoint - - ***********************************************************************/ + ***********************************************************************/ - AsyncSocketConduit connect (Address addr) - { - socket_.connect (addr); - return this; - } + AsyncSocketConduit connect (Address addr) + { + socket_.connect (addr); + return this; + } - /*********************************************************************** + /*********************************************************************** - 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. - - ***********************************************************************/ + 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. + + ***********************************************************************/ + + AsyncSocketConduit bind (Address address) + { + socket_.bind (address); + return this; + } - AsyncSocketConduit bind (Address address) - { - socket_.bind (address); - return this; - } + /************************************************************************** + + Enable the socket for listening - /*********************************************************************** + **************************************************************************/ + AsyncSocketConduit listen() + { + socket_.listen(); + return this; + } + + /*********************************************************************** - 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: + 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 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. - - ***********************************************************************/ + - 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. - AsyncSocketConduit shutdown () - { - socket_.shutdown (SocketShutdown.BOTH); - return this; - } + ***********************************************************************/ - /*********************************************************************** - - Release this AsyncSocketConduit + AsyncSocketConduit shutdown () + { + socket_.shutdown (SocketShutdown.BOTH); + return this; + } - Note that one should always disconnect a AsyncSocketConduit - under normal conditions, and generally invoke shutdown - on all connected sockets beforehand + /*********************************************************************** + + Release this AsyncSocketConduit - ***********************************************************************/ + Note that one should always disconnect a AsyncSocketConduit + under normal conditions, and generally invoke shutdown + on all connected sockets beforehand - override void detach () - { - socket_.detach; + ***********************************************************************/ - // deallocate if this came from the free-list, - // otherwise just wait for the GC to handle it - if (fromList) - deallocate (this); - } + override void detach () + { + socket_.detach; - /*********************************************************************** - - Read content from the socket. + // deallocate if this came from the free-list, + // otherwise just wait for the GC to handle it + if (fromList) + deallocate (this); + } + + /*********************************************************************** - Returns the number of bytes read from the socket, or - IConduit.Eof where there's no more content available + Read content from the socket. + + 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 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 + Note also that a zero return value is not legitimate; + such a value indicates Eof - ***********************************************************************/ + ***********************************************************************/ - override uint read (void[] dst) - { - return read (dst, (void[] dst){return socket_.receive(dst);}); - } - - /*********************************************************************** + override uint read (void[] dst) + { + return read (dst, (void[] dst){return socket_.receive(dst);}); + } + + /*********************************************************************** - 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. + 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. - ***********************************************************************/ + ***********************************************************************/ - override uint write (void[] src) - { - int count = socket_.send (src); - if (count == 0) - count = Eof; - else if (count < 0) - count = Err; - return count; - } + override uint write (void[] src) + { + int count = socket_.send (src); + if (count == 0) + count = Eof; + else if (count < 0) + count = Err; + return count; + } - /*********************************************************************** - - Internal routine to handle socket read under a timeout. - Note that this is synchronized, in order to serialize - socket access + /*********************************************************************** + + Internal routine to handle socket read under a timeout. + Note that this is synchronized, in order to serialize + socket access - ***********************************************************************/ + ***********************************************************************/ - package final uint read (void[] dst, int delegate(void[]) dg) - { - // invoke the actual read op - int count = dg (dst); - if (count == 0) - return Eof; - else if (count < 0) - return Err; - - return count; - } - -} + package final uint read (void[] dst, int delegate(void[]) dg) + { + // invoke the actual read op + int count = dg (dst); + if (count == 0) + return Eof; + else if (count < 0) + return Err; + return count; + } + + } + diff -r b5c7dc3922c6 -r d3374d553986 dsss.conf --- a/dsss.conf Sun Jun 08 01:52:15 2008 -0400 +++ b/dsss.conf Thu Jun 12 23:12:17 2008 -0400 @@ -1,1 +1,2 @@ -[dreactor] +[test/test.d] +