www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Non-blocking UDP calls using std.socket

reply "Andre Artus" <andre.artus gmail.com> writes:
I've written a small program that uses UdpSocket (std.socket) to 
query a DNS server for selected records.

It works as expected, but I would like to try a non-blocking 
approach.

The last time I wrote socket code (without a supporting library) 
was over a decade ago, and even then it was not my forté.

Does anyone know of a cross-platform (Mac, Win, *nix) D library 
that encapsulates the asynchronous calls in a simple API?

If I'm missing something in std.socket (that does the 
[non-blocking] trick) I would appreciate it being pointed out to 
me.

And, if it's not too much trouble, I would appreciate a code 
snippet or link to a sample.

Thanks,

Andre Artus
Dec 17 2014
next sibling parent reply Rikki Cattermole <alphaglosined gmail.com> writes:
On 17/12/2014 9:20 p.m., Andre Artus wrote:
 I've written a small program that uses UdpSocket (std.socket) to query a
 DNS server for selected records.

 It works as expected, but I would like to try a non-blocking approach.

 The last time I wrote socket code (without a supporting library) was
 over a decade ago, and even then it was not my forté.

 Does anyone know of a cross-platform (Mac, Win, *nix) D library that
 encapsulates the asynchronous calls in a simple API?

 If I'm missing something in std.socket (that does the [non-blocking]
 trick) I would appreciate it being pointed out to me.

 And, if it's not too much trouble, I would appreciate a code snippet or
 link to a sample.

 Thanks,

 Andre Artus
Have you looked at vibe.d? https://github.com/rejectedsoftware/vibe.d/blob/master/examples/udp/source/app.d
Dec 17 2014
parent reply "Andre Artus" <andre.artus gmail.com> writes:
-- snip --
 Have you looked at vibe.d?
 https://github.com/rejectedsoftware/vibe.d/blob/master/examples/udp/source/app.d
Thanks Rikki, I saw that before, but I was left with the impression that its doing blocking calls in a thread (which could very well be the simplest answer). I'll give it a bash. and the Task Parallel Library and the result was at least a ten fold speed increase. I would like to match, and preferably better, that performance in a D program. I realize that the task is predominantly network bound so D doesn't get much of its native advantage.
Dec 17 2014
parent "Marc =?UTF-8?B?U2Now7x0eiI=?= <schuetzm gmx.net> writes:
On Wednesday, 17 December 2014 at 09:37:47 UTC, Andre Artus wrote:
 -- snip --
 Have you looked at vibe.d?
 https://github.com/rejectedsoftware/vibe.d/blob/master/examples/udp/source/app.d
Thanks Rikki, I saw that before, but I was left with the impression that its doing blocking calls in a thread (which could very well be the simplest answer). I'll give it a bash.
It uses fibers to make it look as if it were a synchronous, blocking API, but under the hood it does asynchronous, non-blocking calls in an event loop.
Dec 17 2014
prev sibling parent reply Daniel =?UTF-8?B?S296w6Fr?= via Digitalmars-d-learn writes:
V Wed, 17 Dec 2014 08:20:42 +0000
Andre Artus via Digitalmars-d-learn <digitalmars-d-learn puremagic.com>
napsáno:

 I've written a small program that uses UdpSocket (std.socket) to 
 query a DNS server for selected records.
 
 It works as expected, but I would like to try a non-blocking 
 approach.
 
 The last time I wrote socket code (without a supporting library) 
 was over a decade ago, and even then it was not my forté.
 
 Does anyone know of a cross-platform (Mac, Win, *nix) D library 
 that encapsulates the asynchronous calls in a simple API?
 
 If I'm missing something in std.socket (that does the 
 [non-blocking] trick) I would appreciate it being pointed out to 
 me.
 
 And, if it's not too much trouble, I would appreciate a code 
 snippet or link to a sample.
 
 Thanks,
 
 Andre Artus
https://github.com/etcimon/libasync http://code.dlang.org/packages/libevent http://code.dlang.org/packages/libev http://code.dlang.org/packages/libuv
Dec 17 2014
parent "Andre Artus" <andre.artus gmail.com> writes:
-- snip --
 https://github.com/etcimon/libasync
 http://code.dlang.org/packages/libevent
 http://code.dlang.org/packages/libev
 http://code.dlang.org/packages/libuv
Thanks Daniel, These links look interesting. Perhaps libasync could do the trick.
Dec 17 2014