[phobos] RAII implementation for Socket and Selector

Masahiro Nakagawa repeatedly at gmail.com
Mon Jun 20 15:53:39 PDT 2011


Hi Jose.

Skim the code.

- Your Address struct seems to be a Resolver. I think std.net.dns or
   std.net.resolver is better.
- Will you provide Address representaion?
-- e.g.  
https://bitbucket.org/repeatedly/scrap/src/11fbb4a95602/socket.d#cl-598
--- This is half implementation. Lacks some functions such as isBroadcast,  
etc...
- How to define SSLSocket?
- I think 'self' is bad name. It's a not clear.

Later, I read Selector.


Masahiro

On Tue, 21 Jun 2011 05:38:10 +0900, Jose Armando Garcia  
<jsancio at gmail.com> wrote:

> Hi everyone,
>
> For the past few of days I have been working on a RAII implementation
> for Socket and Selector. Sockets are a ref counted wrapper around the
> socket handle which closes the handle once the ref count goes to zero.
> It provides safe methods for bind, connect, listen, accept, recv, send
> and close. The module also provides helper methods for creating
> sockets for a tcp server, tcp client, udp server and udp client. The
> helper method used the Address struct which is basically wrapper
> around getaddrinfo. As of right now the module provides support for
> ipv4 and ipv6.
>
> On top of Socket we have Selector which can be used to safely wait on
> more than one socket. To register on a selector call the register
> method in Socket. Use Socket.unregister to unregister the socket.
> Sockets are automatically unregistered when closed. The current
> implementation for selector only support epoll (sorry Windows and BSD
> users) but I am highly confident that it can be ported to other
> platforms. I plan to it at a future date but there are currently some
> serious issues with DMD and druntime that invalidate the strong/weak
> ref counting design.
>
> It works well enough to pass the unittests but I had to do a lot of
> hacks which I hope I can remove once DMD and druntime are fixed.
>
> I should also mention that the design was influenced by Java's NIO and
> Ruby's socket implementation.
>
> Here is the code:
> https://github.com/jsancio/phobos/blob/socket/std/net/socket.d. It
> doesn't have any documentation right now.
>
> I wont be able to work on it for the next couple of weeks but comments
> are welcome.
>
> Thanks!
> -Jose
> _______________________________________________
> phobos mailing list
> phobos at puremagic.com
> http://lists.puremagic.com/mailman/listinfo/phobos


More information about the phobos mailing list