2
* SocketStreamにforeachを拡張
4
module nazo.socketstream;
5
import std.socketstream, std.socket, std.stream, std.stdio;
7
class SocketStream:std.socketstream.SocketStream{
8
const uint buffsize=500;
9
this(Socket sock,uint buffsize=buffsize.init){
12
this(Socket sock,FileMode mode,uint buffsize=buffsize.init){
15
int opApply(int delegate(inout ubyte[] buff) dg){
17
ubyte[] buf=new ubyte[buffsize];
18
while((buf.length=read(buf))>0){
19
// std.stdio.writefln(buf.length);
29
import std.stdio, std.string;
32
auto ih=new InternetHost;
33
ih.getHostByName("www.ietf.org");
34
auto ia = new InternetAddress(ih.addrList[0], 80);
35
auto tcp = new TcpSocket(ia.addressFamily());
37
auto sock = new SocketStream(tcp);
38
sock.write(cast(ubyte[])"GET /home.html\r\nAccept-Language: ja-jp,ja;q=0.8,en-us;q=0.5,en;q=0.3\r\n\r\n");
40
foreach(ubyte[] buf;sock){
43
assert(find(cast(string)data,"<html")>=0);
44
assert(find(cast(string)data,"</html>")>=0);