D Paste by gim
Description: tango NetHost.getHostByAddr Issue
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 | module threads; const char[][] list = [ "deely.jogger.pl", "konieczny.be", "www.jakilinux.org", "www.mpk.krakow.pl", "www.microsoft.com", "www.gentoo.org", "debian.org", "ubuntu.com", "redhat.com", "www.google.com", "www.yahoo.co.uk", "www.youtube.com", "www.36cf.fan.pl", "www.wykop.pl", "www.digg.com", "www.wp.pl", "www.gazeta.pl", "www.onet.pl", "www.interia.pl", "www.techblog.pl", "last.fm", "wafel.com", "komiksiarnia.net", "clamav.net", "slashdot.org", "thinkgeek.com", ]; private import tango.core.Thread, tango.io.Stdout, tango.net.Socket, tango.util.log.Trace; class SimpleThread: Thread { private char [] addr; this (char[] iaddr) { super (&run); addr = iaddr; } void run() { try { auto ih = new NetHost; if (!ih.getHostByName (addr)) Trace.formatln( "couldn't resolve: {}", addr); else Trace.formatln ( ">> {} resolved: {:x8} ", addr, ih.addrList[0]); } catch( Exception e ) { Trace.formatln ( "Exception {} ({}) ", addr, e.msg); } } }; void main() { static SimpleThread [] ht; Stdout.print( "Starting application..." ).newline; foreach( s; list ) { Stdout.print( "Starting thread for: " )( s ).newline; auto ih = new SimpleThread( s ); ih.start(); ht ~= ih; } Stdout.print( "Resolving names..." ).newline; foreach( s; ht ) s.join(); Stdout.print( "Resolved." ).newline; } |