I have no problem with Adam joining. As far as the network library, do we want
to increase our dependency on the C FILE* structure/api? I would not want
that. I don't know a lot of network solutions that put a socket fd inside a
FILE *, there's probably good reason for that.
As long as there's a non-buffered solution that allows socket-like functions
accessible, I'm cool with File wrapping a socket. That is, there should be a
way to create a socket with the API that doesn't use File.
I hope we will eventually get a D-only solution for File. Good news is, any
future improvements to File automatically translate to what Adam is working on.
-Steve
----- Original Message ----
From: Andrei Alexandrescu <[email protected]>
To: Discuss the phobos library for D <[email protected]>
Sent: Sun, March 28, 2010 7:21:20 PM
Subject: [phobos] Fwd: [Issue 4025] New: Making network with the std.stdio.File
interface
I'm quite hopeful about this development. If we have anything for the network in
D2, that would be great, and integration with File will reuse a ton of
work.
I'm considering extending Adam an offer to join Phobos. He has
donated a Windows machine for building and running Phobos and generally seems to
know what he's talking about. If he'll join the project, my hope is to attract
him to dedicate more time to it.
Please cast your vote by replying
(silence = abstaining, i.e. you're not for or
against).
Andrei
-------- Original Message
--------
Subject: [Issue 4025] New: Making network with the std.stdio.File
interface
Date: Sun, 28 Mar 2010 22:51:45 +0000 (UTC)
From:
ymailto="mailto:[email protected]"
href="mailto:[email protected]">[email protected]
Organization:
Digital Mars
To:
href="mailto:[email protected]">[email protected]
Newsgroups:
digitalmars.D.bugs
http://d.puremagic.com/issues/show_bug.cgi?id=4025
Summary: Making network with the std.stdio.File
interface
Product: D
Version: 2.041
Platform: Other
OS/Version: Linux
Status: NEW
Severity: enhancement
Priority:
P2
Component: Phobos
AssignedTo:
href="mailto:[email protected]">[email protected]
ReportedBy:
href="mailto:[email protected]">[email protected]
---
Comment #0 from Adam D. Ruppe <
href="mailto:[email protected]">[email protected]>
2010-03-28 15:51:43 PDT ---
I've written a small module that opens a network
connection, then wraps it in
the File struct, allowing you to use the byLine,
etc., ranges on it, as well as
writef/readln/etc.
It is Linux only,
but should be pretty easy to port to other operating systems.
Ideally, I'd
like to eventually be able to use File for talking
to processes too, on all D
platforms.
Here's the code I have for
now:
==============
public import std.stdio;
import
std.string;
import std.conv;
version(linux):
import
std.c.linux.linux;
import std.c.linux.socket;
alias std.c.linux.socket
sock;
alias std.c.linux.linux linux;
enum int PF_INET = 2;
enum int
AF_INET = PF_INET;
extern(C) FILE* fdopen(int, const(char)*);
File
openNetwork(string host, ushort port) {
hostent* h;
sockaddr_in addr;
h =
gethostbyname(std.string.toStringz(host));
if(h is
null)
throw new
StdioException("gethostbyname");
int s = socket(PF_INET,
SOCK_STREAM, 0);
if(s == -1)
throw new StdioException("socket");
scope(failure)
close(s);
addr.sin_family = AF_INET;
addr.sin_port =
htons(port);
std.c.string.memcpy(&addr.sin_addr.s_addr,
h.h_addr, h.h_length);
if(sock.connect(s, cast(sockaddr*)
&addr, addr.sizeof) == -1)
throw new
StdioException("Connect failed");
FILE* fp = fdopen(s,
"w+".ptr);
File f;
auto imp = new
File.Impl(fp, 1, host ~ ":" ~ to!string(port));
f.p =
imp;
return
f;
}
_______________________________________________
phobos mailing
list
href="mailto:[email protected]">[email protected]
http://lists.puremagic.com/mailman/listinfo/phobos
_______________________________________________
phobos mailing list
[email protected]
http://lists.puremagic.com/mailman/listinfo/phobos