X-Git-Url: http://www.lcore.org/git/lcore.git/blobdiff_plain/eaf53edbc38a2987348e92205a2fd2f1982bc2e1..3bf8ed9f9545a956985b6c3c0658893910e01f75:/lcoretest.dpr diff --git a/lcoretest.dpr b/lcoretest.dpr old mode 100755 new mode 100644 index b84b8ec..288c0b4 --- a/lcoretest.dpr +++ b/lcoretest.dpr @@ -3,7 +3,7 @@ program lcoretest; uses lcore, lsocket, - {$ifdef win32} + {$ifdef mswindows} lcorewsaasyncselect in 'lcorewsaasyncselect.pas', {$else} lcoreselect, @@ -11,12 +11,19 @@ uses dnsasync, binipstuff, sysutils, - dnssync, + dnssync //we don't actually make any use of the units below in this app, we just //include it to check if it compiles ok ;) - lmessages, - unitfork; -{$ifdef win32} + {$ifndef mswindows} + , + {$ifndef nomessages} + lcoremessages, + unitwindowobject, + {$endif} + unitfork + {$endif} + ; +{$ifdef mswindows} {$R *.RES} {$endif} @@ -30,12 +37,16 @@ type procedure dnsrequestdone(sender:tobject;error : word); procedure sessionclosed(sender:tobject;error : word); end; + treleasetest=class(tlcomponent) + destructor destroy; override; + end; var listensocket : tlsocket; serversocket : tlsocket; clientsocket : tlsocket; sc : tsc; task : tltask; + firststage : boolean; procedure tsc.sessionavailable(sender: tobject;error : word); begin writeln('received connection'); @@ -86,11 +97,11 @@ end; procedure tsc.sessionconnected(sender: tobject;error : word); begin - + if error=0 then begin writeln('session is connected, local address is'+clientsocket.getxaddr); - if (clientsocket.addr = '127.0.0.1') or (clientsocket.addr = '::1') then begin + if firststage then begin clientsocket.sendstr('hello world'); end else begin clientsocket.sendstr('nick test'#13#10'user x x x x'#13#10); @@ -112,12 +123,12 @@ begin writeln('closing client socket'); clientsocket.close; - writeln('looking up irc.ipv6.p10link.net using dnsasync'); + writeln('looking up irc.p10link.net using dnsasync'); das := tdnsasync.Create(nil); das.onrequestdone := sc.dnsrequestdone; //das.forwardfamily := af_inet6; - das.forwardlookup('irc.ipv6.p10link.net'); - + das.forwardlookup('irc.p10link.net'); + end; procedure tsc.dnsrequestdone(sender:tobject;error : word); @@ -125,12 +136,13 @@ var tempbinip : tbinip; tempbiniplist : tbiniplist; begin - writeln('irc.ipv6.p10link.net resolved to '+das.dnsresult+' connecting client socket there'); + writeln('irc.p10link.net resolved to '+das.dnsresult+' connecting client socket there'); das.dnsresultbin(tempbinip); tempbiniplist := biniplist_new; biniplist_add(tempbiniplist,tempbinip); clientsocket.addr := tempbiniplist; clientsocket.port := '6667'; + firststage := false; clientsocket.connect; //writeln(clientsocket.getxaddr); das.free; @@ -140,6 +152,13 @@ procedure tsc.timehandler(sender:tobject); begin //writeln('got timer event'); end; + +destructor treleasetest.destroy; +begin + writeln('releasetest.destroy called'); + inherited destroy; +end; + procedure tsc.sessionclosed(sender:tobject;error : word); begin Writeln('session closed with error ',error); @@ -148,7 +167,13 @@ var timer : tltimer; ipbin : tbinip; dummy : integer; + iplist : tbiniplist; + releasetest : treleasetest; begin + lcoreinit; + releasetest := treleasetest.create(nil); + releasetest.release; + ipbin := forwardlookup('invalid.domain',5); writeln(ipbintostr(ipbin)); @@ -162,11 +187,12 @@ begin writeln('2001:200::8002:203:47ff:fea5:3085 reverses to '+reverselookup(ipbin,5)); writeln('creating and setting up listen socket'); listensocket := tlsocket.create(nil); - listensocket.addr := '::'; + listensocket.addr := ''; listensocket.port := '12345'; listensocket.onsessionavailable := sc.sessionavailable; writeln('listening'); listensocket.listen; + writeln('listen call returned'); writeln(listensocket.getxport); writeln('listen socket is number ', listensocket.fdhandlein); writeln('creating and setting up server socket'); @@ -174,12 +200,19 @@ begin serversocket.ondataavailable := sc.dataavailable; writeln('creating and setting up client socket'); clientsocket := tlsocket.create(nil); - clientsocket.addr := '::1';{'127.0.0.1';} + //try connecting to ::1 first and if that fails try 127.0.0.1 + iplist := biniplist_new; + ipstrtobin('::1',ipbin); + biniplist_add(iplist,ipbin); + ipstrtobin('127.0.0.1',ipbin); + biniplist_add(iplist,ipbin); + clientsocket.addr := iplist; clientsocket.port := '12345'; clientsocket.onsessionconnected := sc.sessionconnected; clientsocket.ondataAvailable := sc.dataavailable; clientsocket.onsessionclosed := sc.sessionclosed; writeln('connecting'); + firststage := true; clientsocket.connect; writeln('client socket is number ',clientsocket.fdhandlein); writeln('creating and setting up timer');