Network I/O and streaming in D2

Adam Ruppe destructionator at gmail.com
Tue Jun 29 19:48:03 PDT 2010


My network thing is very simple: it opens a socket, then wraps it up
in a File struct, via FILE*. Then, you can treat it the same way.

Simple code, and I've been meaning to commit it to phobos for linux at
least, but stuff keeps coming up and I haven't gotten around to it
yet.

Now, there's some controversy on if std.stdio.File should rely on
FILE*, but that's really an implementation detail that we can fix up
later. I've been worrying about that which delays my plans to commit
even more, but I don't think we should right now. Some is better than
none here.


For curl, I had to use it for a personal project last week (needed SSL
support which I don't otherwise have - I've implemented simple HTTP
code on top of the File interface, but no encryption there, so
unsuitable for this task.) Here's the code:
http://arsdnet.net/dcode/curl.d

It is in my typical style of only porting and exposing the bare
minimum to do the job I cared about doing, but maybe it is a good
starting point for others.

The function that does work is:

string curl(string url, string data = null, string contentType =
"application/x-www-form-urlencoded")

If data is null, it does a GET of the url, otherwise a POST with the
given contentType. It returns the data received as a string.


More information about the Digitalmars-d mailing list