www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - async socket programming in D?

reply "Bauss" <streetzproductionz hotmail.com> writes:
I know the socket has the nonblocking settings, but how would I 
actually go around using it in D? Is there a specific procedure 
for it to work correctly etc.


I've taken a look at splat.d but it seems to be very outdated, so 
that's why I went ahead and asked here as I'd probably have to 
end up writing my own wrapper.
Apr 20 2014
next sibling parent "Tolga Cakiroglu" <tcak pcak.com> writes:
On Sunday, 20 April 2014 at 22:44:28 UTC, Bauss wrote:
 I know the socket has the nonblocking settings, but how would I 
 actually go around using it in D? Is there a specific procedure 
 for it to work correctly etc.


 I've taken a look at splat.d but it seems to be very outdated, 
 so that's why I went ahead and asked here as I'd probably have 
 to end up writing my own wrapper.
The "Socket" class has "blocking" property that is boolean. Before starting to listening as a server socket, or connecting to a server as client, if you set it to "false", then you can use them (waiting for client with `accept` or receiving messages) as asynchronous. Already as you know, a client that is created from the `accept` method of non-blocking server socket is non-blocking as well. So you don't have to do anything about it.
Apr 20 2014
prev sibling parent reply Etienne Cimon <etcimon gmail.com> writes:
On 2014-04-20 18:44, Bauss wrote:
 I know the socket has the nonblocking settings, but how would I actually
 go around using it in D? Is there a specific procedure for it to work
 correctly etc.


 I've taken a look at splat.d but it seems to be very outdated, so that's
 why I went ahead and asked here as I'd probably have to end up writing
 my own wrapper.
I was actually working on this in a new event loop for vibe.d here: https://github.com/globecsys/vibe.d/tree/native-events/source/vibe/core/events I've left it without activity for a week b/c I'm currently busy making a (closed source) SSL library to replace openSSL in my projects, but I'll return to this one project here within a couple weeks at most. It doesn't build yet, but you can probably use some of it at least as a reference, it took me a while to harvest the info on windows and linux kernels for async I/O. Some interesting parts like that which you wanted are found here: https://github.com/globecsys/vibe.d/blob/native-events/source/vibe/core/events/epoll.d#L403 I think I was at handling a new connection or incoming data though, so you won't find accept() or read callbacks, but with it I think it was pretty much ready for async TCP.
Apr 20 2014
parent Etienne Cimon <etcimon gmail.com> writes:
On 2014-04-21 00:32, Etienne Cimon wrote:
 On 2014-04-20 18:44, Bauss wrote:
 I know the socket has the nonblocking settings, but how would I actually
 go around using it in D? Is there a specific procedure for it to work
 correctly etc.


 I've taken a look at splat.d but it seems to be very outdated, so that's
 why I went ahead and asked here as I'd probably have to end up writing
 my own wrapper.
I was actually working on this in a new event loop for vibe.d here: https://github.com/globecsys/vibe.d/tree/native-events/source/vibe/core/events I've left it without activity for a week b/c I'm currently busy making a (closed source) SSL library to replace openSSL in my projects, but I'll return to this one project here within a couple weeks at most. It doesn't build yet, but you can probably use some of it at least as a reference, it took me a while to harvest the info on windows and linux kernels for async I/O. Some interesting parts like that which you wanted are found here: https://github.com/globecsys/vibe.d/blob/native-events/source/vibe/core/events/epoll.d#L403 I think I was at handling a new connection or incoming data though, so you won't find accept() or read callbacks, but with it I think it was pretty much ready for async TCP.
But of course, nothing stops you from using vibe.d with libevent ;)
Apr 20 2014