diff dreactor/transport/AsyncSocketConduit.d @ 3:e3dbc9208822

basic tests working
author rick@minifunk
date Tue, 08 Jul 2008 11:21:09 -0400
parents d3374d553986
children d6a3cfe7c3de
line wrap: on
line diff
--- a/dreactor/transport/AsyncSocketConduit.d	Thu Jun 12 23:12:17 2008 -0400
+++ b/dreactor/transport/AsyncSocketConduit.d	Tue Jul 08 11:21:09 2008 -0400
@@ -20,8 +20,6 @@
 
 private import  tango.net.Socket;
 
-import tango.net.Socket.Address;
- 
 /*******************************************************************************
 
   A wrapper around the bare Socket to implement the IConduit abstraction
@@ -33,23 +31,16 @@
   preferred
 
  *******************************************************************************/
-alias IPv4Address Address;
 
 class AsyncSocketConduit : Conduit
 {
-    package Socket                  socket_;
+    package Socket 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
-    }
 
     this ()
     {
@@ -65,7 +56,8 @@
 
     protected this (SocketType type, ProtocolType protocol, bool create=true)
     {
-       socket_ = new Socket (AddressFamily.INET, type, protocol, create);
+        socket_ = new Socket (AddressFamily.INET, type, protocol, create);
+        socket_.blocking(false);
     }
 
     /***********************************************************************
@@ -159,9 +151,9 @@
         Enable the socket for listening
 
     **************************************************************************/
-    AsyncSocketConduit listen()
+    AsyncSocketConduit listen(int backlog = 255)
     {
-        socket_.listen();
+        socket_.listen(backlog);
         return this;
     }
 
@@ -202,11 +194,6 @@
     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);
     }
 
     /***********************************************************************
@@ -215,58 +202,26 @@
 
      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
+     
+     Return IConduit.Eof if there is an error with the socket.
 
     ***********************************************************************/
-
     override uint read (void[] dst)
     {
-       return read (dst, (void[] dst){return socket_.receive(dst);});
+       // invoke the actual read op
+       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.
-
+     socket. 
     ***********************************************************************/
 
     override uint write (void[] src)
     {
-       int count = socket_.send (src);
-       if (count == 0)
-           count = Eof;
-       else if (count < 0)
-           count = Err;
-       return count;
+       return socket_.send (src);
     }
-
-    /***********************************************************************
-
-     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;
-    }
-
-    }
-