\r
interface\r
\r
+procedure lcoreinit;\r
+\r
implementation\r
-uses wcore,lcore,bsearchtree,sysutils,windows,winsock,pgtypes,messages,classes;\r
+\r
+uses\r
+ dnswin, //to call init\r
+ wcore,lcore,bsearchtree,sysutils,windows,winsock,pgtypes,messages,classes,lsocket;\r
+\r
type\r
twineventcore=class(teventcore)\r
public\r
procedure twineventcore.rmasterset(fd : integer;islistensocket : boolean);\r
begin\r
if islistensocket then begin\r
- //writeln('setting accept watch for socket number ',fd);\r
+// writeln('setting accept watch for socket number ',fd);\r
dowsaasyncselect(fd,FD_ACCEPT or FD_CLOSE,0);\r
end else begin\r
- //writeln('setting read watch for socket number',fd);\r
+// writeln('setting read watch for socket number',fd);\r
dowsaasyncselect(fd,FD_READ or FD_CLOSE,0);\r
end;\r
end;\r
writetrigger : boolean;\r
lasio : tlasio;\r
begin\r
- //writeln('got a message');\r
+// writeln('got a message');\r
Result := 0; // This means we handled the message\r
if (ahwnd=hwndlcore) and (aumsg=wm_user) then begin\r
- //writeln('it appears to be a response to our wsaasyncselect');\r
+// writeln('it appears to be a response to our wsaasyncselect');\r
socket := awparam;\r
event := alparam and $FFFF;\r
error := alparam shr 16;\r
- //writeln('socket=',socket,' event=',event,' error=',error);\r
+// writeln('socket=',socket,' event=',event,' error=',error);\r
readtrigger := false;\r
writetrigger := false;\r
lasio := findtree(@fdreverse,inttostr(socket));\r
if assigned(lasio) then begin\r
if (error <> 0) or ((event and FD_CLOSE) <> 0) then begin\r
- if lasio.state = wsconnecting then begin\r
- lasio.onsessionconnected(lasio,error);\r
+ if (lasio.state = wsconnecting) and (error <> 0) then begin\r
+ if lasio is tlsocket then tlsocket(lasio).connectionfailedhandler(error)\r
+ end else begin\r
+ lasio.internalclose(error);\r
end;\r
- lasio.internalclose(error);\r
end else begin\r
if (event and (FD_READ or FD_ACCEPT)) <> 0 then readtrigger := true;\r
if (event and (FD_WRITE)) <> 0 then writetrigger := true;\r
\r
if readtrigger or writetrigger then lasio.handlefdtrigger(readtrigger,writetrigger);\r
end;\r
- dowsaasyncselect(socket,0,0); //reset watches\r
+ // don't reset the event manually for listen sockets to avoid unwanted\r
+ // extra onsessionavailible events\r
+ if (taddrint(findtree(@fdwatches,inttostr(socket))) and (FD_ACCEPT)) = 0 then dowsaasyncselect(socket,0,0); // if not a listen socket reset watches\r
end;\r
end else if (ahwnd=hwndlcore) and (aumsg=wm_dotasks) then begin\r
//writeln('processing tasks');\r
lpszClassName : 'lcoreClass');\r
GInitData: TWSAData;\r
\r
+var\r
+ inited:boolean;\r
+procedure lcoreinit;\r
begin\r
+ if (inited) then exit;\r
+\r
+ dnswin.init;\r
+\r
eventcore := twineventcore.create;\r
- if Windows.RegisterClass(MyWindowClass) = 0 then halt;\r
+ if Windows.RegisterClass(MyWindowClass) = 0 then halt;\r
//writeln('about to create lcore handle, hinstance=',hinstance);\r
hwndlcore := CreateWindowEx(WS_EX_TOOLWINDOW,\r
MyWindowClass.lpszClassName,\r
onaddtask := winaddtask;\r
timerwrapperinterface := twintimerwrapperinterface.create(nil);\r
\r
- WSAStartup($200, GInitData);\r
+ WSAStartup(2, GInitData);\r
+ absoloutemaxs := maxlongint;\r
+\r
+ wcoreinit;\r
+\r
+ inited := true;\r
+end;\r
+\r
end.\r