Download Reference Manual
The Developer's Library for D
About Wiki Forums Source Search Contact

Socket Design Improvement Proposal

This page is intended to help with the design of a somewhat improved version of the current Socket as well as SocketConduit? and it's children.


  • To provide a way to manage timeouts on a socket rather than allowing the OS to manage this, eg. try and read or write data for 10 seconds before returning to the calling function.
  • To provide a way to interrupt the timeout loop for things such as shutdown, so that the application can give the connected peer an alert. Eg. An SMTP Daemon, when shutting down, should give a 400 temporary error, so the client tries to resend later.
  • To make the two previous features easily extensible so that they can be used with multiple protocols

SSL Socket Conduit

SSL Socket Conduit and associated modules are now in Tango trunk

Also, there's a known problem with OpenSSL and threads. Basically, if a thread throws an error within OpenSSL, it needs to clean up the error state before it exits using ERR_remove_state(0). I'm unsure the best way to deal with that.

Timeout Socket Conduit

Ticket #624 has an example implementation of the first two goals shown above.



However, TimeoutSocketConduit?.d (see ticket #624) is very similar to SocketConduit?.d and might be a good basis for a new design. It adds a few new functions to the existing SocketConduit?.d:

  • Constructor that takes a delegate that's called to check if we should exit the timeout loop
  • A timeSlice property used to set how often the timeout loop should check for shutdown
  • The setTimeout sets the default timeout so you can use the regular connect/read/write functions (without having to change code)
  • New changes to connect, read, write that take a TimeSpan? specifying the custom timeout you wish (different from the default)