D.gnu - [gdc-0.24_3 on freebsd8current/amd64 ]can't run socket.connect
- kevin (21/21) Jun 07 2008 import std.socket;
- downs (1/1) Jun 07 2008 (see subject)
- David Friedman (9/34) Jun 08 2008 Although the D spec says you can pass a string for a "%.*s" format, it
- kevin (20/58) Jun 08 2008 Sorry, I mean socket.connect can't work in freebsd 8/amd64.
import std.socket; import std.socketstream; int main() { Socket sock = new Socket(AddressFamily.INET, SocketType.STREAM, ProtocolType.IP); sock.connect(new InternetAddress("www.digitalmars.com", 80)); SocketStream ss = new SocketStream(sock); ss.writeString("GET /d/intro.html HTTP/1.1\r\n" "Host: www.digitalmars.com\r\n" "\r\n"); while(ss.readLine().length) {} //skip header while(!ss.eof()) { char[] line; printf("%.*s\n", ss.readLine()); } return 0; } ---------------------- I try to run this. I find it compile well.but when I run it., it core dump.
Jun 07 2008
kevin wrote:import std.socket; import std.socketstream; int main() { Socket sock = new Socket(AddressFamily.INET, SocketType.STREAM, ProtocolType.IP); sock.connect(new InternetAddress("www.digitalmars.com", 80)); SocketStream ss = new SocketStream(sock); ss.writeString("GET /d/intro.html HTTP/1.1\r\n" "Host: www.digitalmars.com\r\n" "\r\n"); while(ss.readLine().length) {} //skip header while(!ss.eof()) { char[] line; printf("%.*s\n", ss.readLine()); } return 0; } ---------------------- I try to run this. I find it compile well.but when I run it., it core dump.Although the D spec says you can pass a string for a "%.*s" format, it really only works on 32-bit targets. The argument for '*' is of type 'int', not 'size_t'. On a 64-bit target, passing a char[] really passes a 'size_t' and 'char*', which is not what printf expects. To be portable, you have to do this: string s2 = ss.readline(); printf("%.*s\n", cast(int) s2.length, s2.ptr); David
Jun 08 2008
David Friedman Wrote:kevin wrote:Sorry, I mean socket.connect can't work in freebsd 8/amd64. ........ writefln("Befor"); sock.connect(new InternetAddress("www.digitalmars.com", 80)); writefln("After"); I test this ,it just output "Befor" and then core dump. (gdb)s _D3gcx2GC8addRangeMFPvPvZv (this= 0x60e040, pbot=0x5386a8, ptop=0x551980) at ../.././../gcc-4.1-20071105/libphobos/internal/gc/gcx.d:751 751 in ../.././../gcc-4.1-20071105/libphobos/internal/gc/gcx.d (gdb) s _D3gcx2GC8addRangeMFPvPvZv (this=Variable "this" is not available. ) at ../.././../gcc-4.1-20071105/libphobos/internal/gc/gcx.d:748 748 in ../.././../gcc-4.1-20071105/libphobos/internal/gc/gcx.d (gdb) s Befor Program received signal SIGABRT, Aborted. 0x0000000800b7947c in kill () from /lib/libc.so.7import std.socket; import std.socketstream; int main() { Socket sock = new Socket(AddressFamily.INET, SocketType.STREAM, ProtocolType.IP); sock.connect(new InternetAddress("www.digitalmars.com", 80)); SocketStream ss = new SocketStream(sock); ss.writeString("GET /d/intro.html HTTP/1.1\r\n" "Host: www.digitalmars.com\r\n" "\r\n"); while(ss.readLine().length) {} //skip header while(!ss.eof()) { char[] line; printf("%.*s\n", ss.readLine()); } return 0; } ---------------------- I try to run this. I find it compile well.but when I run it., it core dump.Although the D spec says you can pass a string for a "%.*s" format, it really only works on 32-bit targets. The argument for '*' is of type 'int', not 'size_t'. On a 64-bit target, passing a char[] really passes a 'size_t' and 'char*', which is not what printf expects. To be portable, you have to do this: string s2 = ss.readline(); printf("%.*s\n", cast(int) s2.length, s2.ptr); David
Jun 08 2008