X-Git-Url: http://www.lcore.org/git/lcore.git/blobdiff_plain/4782a5c5afee47721cc617daa40dd29828342c2b..1c8b91ca0f6891a397357c7cf7d77af18c15937d:/lcorewsaasyncselect.pas diff --git a/lcorewsaasyncselect.pas b/lcorewsaasyncselect.pas old mode 100755 new mode 100644 index a978c23..6b4c01b --- a/lcorewsaasyncselect.pas +++ b/lcorewsaasyncselect.pas @@ -2,8 +2,14 @@ unit lcorewsaasyncselect; interface +procedure lcoreinit; + implementation -uses wcore,lcore,bsearchtree,sysutils,windows,winsock,pgtypes,messages,classes; + +uses + dnswin, //to call init + wcore,lcore,bsearchtree,sysutils,windows,winsock,pgtypes,messages,classes,lsocket; + type twineventcore=class(teventcore) public @@ -78,10 +84,10 @@ end; procedure twineventcore.rmasterset(fd : integer;islistensocket : boolean); begin if islistensocket then begin - //writeln('setting accept watch for socket number ',fd); +// writeln('setting accept watch for socket number ',fd); dowsaasyncselect(fd,FD_ACCEPT or FD_CLOSE,0); end else begin - //writeln('setting read watch for socket number',fd); +// writeln('setting read watch for socket number',fd); dowsaasyncselect(fd,FD_READ or FD_CLOSE,0); end; end; @@ -116,30 +122,33 @@ var writetrigger : boolean; lasio : tlasio; begin - //writeln('got a message'); +// writeln('got a message'); Result := 0; // This means we handled the message if (ahwnd=hwndlcore) and (aumsg=wm_user) then begin - //writeln('it appears to be a response to our wsaasyncselect'); +// writeln('it appears to be a response to our wsaasyncselect'); socket := awparam; event := alparam and $FFFF; error := alparam shr 16; - //writeln('socket=',socket,' event=',event,' error=',error); +// writeln('socket=',socket,' event=',event,' error=',error); readtrigger := false; writetrigger := false; lasio := findtree(@fdreverse,inttostr(socket)); if assigned(lasio) then begin if (error <> 0) or ((event and FD_CLOSE) <> 0) then begin - if lasio.state = wsconnecting then begin - lasio.onsessionconnected(lasio,error); + if (lasio.state = wsconnecting) and (error <> 0) then begin + if lasio is tlsocket then tlsocket(lasio).connectionfailedhandler(error) + end else begin + lasio.internalclose(error); end; - lasio.internalclose(error); end else begin if (event and (FD_READ or FD_ACCEPT)) <> 0 then readtrigger := true; if (event and (FD_WRITE)) <> 0 then writetrigger := true; if readtrigger or writetrigger then lasio.handlefdtrigger(readtrigger,writetrigger); end; - dowsaasyncselect(socket,0,0); //reset watches + // don't reset the event manually for listen sockets to avoid unwanted + // extra onsessionavailable events + if (taddrint(findtree(@fdwatches,inttostr(socket))) and (FD_ACCEPT)) = 0 then dowsaasyncselect(socket,0,0); // if not a listen socket reset watches end; end else if (ahwnd=hwndlcore) and (aumsg=wm_dotasks) then begin //writeln('processing tasks'); @@ -157,6 +166,7 @@ end; procedure winaddtask(ahandler:ttaskevent;aobj:tobject;awparam,alparam:longint); begin if not tasksoutstanding then PostMessage(hwndlcore,wm_dotasks,0,0); + tasksoutstanding := true; end; type twcoretimer = wcore.tltimer; @@ -193,9 +203,16 @@ var lpszClassName : 'lcoreClass'); GInitData: TWSAData; +var + inited:boolean; +procedure lcoreinit; begin + if (inited) then exit; + + dnswin.init; + eventcore := twineventcore.create; - if Windows.RegisterClass(MyWindowClass) = 0 then halt; + if Windows.RegisterClass(MyWindowClass) = 0 then halt; //writeln('about to create lcore handle, hinstance=',hinstance); hwndlcore := CreateWindowEx(WS_EX_TOOLWINDOW, MyWindowClass.lpszClassName, @@ -212,5 +229,12 @@ begin onaddtask := winaddtask; timerwrapperinterface := twintimerwrapperinterface.create(nil); - WSAStartup($200, GInitData); + WSAStartup(2, GInitData); + absolutemaxs := maxlongint; + + wcoreinit; + + inited := true; +end; + end.