X-Git-Url: http://www.lcore.org/git/lcore.git/blobdiff_plain/968c333d05db5d5ecf3599f8e304c67e64f21159..85edf7ed5948e0efe59301680f79ea0bac4367e8:/lsocket.pas diff --git a/lsocket.pas b/lsocket.pas old mode 100755 new mode 100644 index b493ccd..6a4034d --- a/lsocket.pas +++ b/lsocket.pas @@ -22,7 +22,7 @@ changes by beware (20030903) beware (20030905) * if connect failed (conn refused) set state to connected and call internalclose, to get closed handler (instead of fdclose) -* (lcore) if closing the fd's in internalcose, set fd's to -1 because closing an fd makes it invalid +* (lcore) if closing the fd's in internalclose, set fds to -1 because closing an fd makes it invalid beware (20030927) * fixed: on connect failed, tried to close fdhandle's which were already set to -1, added check @@ -93,7 +93,7 @@ type //host : THostentry ; - //mainthread : boolean ; //for debuggin only + //mainthread : boolean ; //for debugging only addr:thostname; port:ansistring; localaddr:thostname; @@ -256,13 +256,16 @@ begin end else begin state :=wsconnecting; {$ifdef mswindows} + //beware: atleast on windows, wsaasyncselect set interest in events before connecting, or a connect error isn't seen if it happens immediately during connect + eventcore.rmasterset(fdhandlein,false); + eventcore.wmasterset(fdhandleout); //writeln(inaddr.inaddr.port); winsock.Connect(fdhandlein,winsock.psockaddr(@inADDR)^,getaddrsize); {$else} system_Connect(fdhandlein,inADDR,getaddrsize); + eventcore.rmasterset(fdhandlein,false); + eventcore.wmasterset(fdhandleout); {$endif} - eventcore.rmasterset(fdhandlein,false); - eventcore.wmasterset(fdhandleout); if trymoreips then connecttimeout.enabled := true; end; //sendq := ''; @@ -497,7 +500,7 @@ esocketexception.create('unable to listen'); if fdhandlein >= 0 then begin {one *can* get here without fd -beware} eventcore.rmasterclr(fdhandlein); - myfdclose(fdhandlein); // we musnt leak file discriptors + myfdclose(fdhandlein); // we musnt leak file descriptors eventcore.setfdreverse(fdhandlein,nil); fdhandlein := -1; end; @@ -532,9 +535,9 @@ end; function tlsocket.accept : longint; var - FromAddrSize : LongInt; // i don't realy know what to do with these at this + FromAddrSize : LongInt; // i don't really know what to do with these at this FromAddr : TInetSockAddrV; // at this point time will tell :) - a:integer; + a,acceptlasterror:integer; begin {$ifdef secondlistener} if (lastsessionfromsecond) then begin @@ -550,17 +553,20 @@ begin {$else} result := system_accept(fdhandlein,fromaddr,fromaddrsize); {$endif} + + if (result = -1) then acceptlasterror := {$ifdef mswindows}getlasterror{$else}socketerror{$endif} else acceptlasterror := 0; + //now we have accepted one request start monitoring for more again eventcore.rmasterset(fdhandlein,true); if result = -1 then begin - raise esocketexception.create('error '+inttostr({$ifdef mswindows}getlasterror{$else}socketerror{$endif})+' while accepting'); + raise esocketexception.create('error '+inttostr(acceptlasterror)+' while accepting'); end; - if result > absoloutemaxs then begin + if result > absolutemaxs then begin myfdclose(result); a := result; { result := -1;} - raise esocketexception.create('file discriptor out of range: '+inttostr(a)); + raise esocketexception.create('file descriptor out of range: '+inttostr(a)); end; end; @@ -673,14 +679,14 @@ begin exit; end; if (state =wsconnecting) and writetrigger then begin - // code for dealing with the reults of a non-blocking connect is + // code for dealing with the results of a non-blocking connect is // rather complex - // if just write is triggered it means connect suceeded + // if just write is triggered it means connect succeeded // if both read and write are triggered it can mean 2 things - // 1: connect ok and data availible + // 1: connect ok and data available // 2: connect fail // to find out which you must read from the socket and look for errors - // there if we read successfully we drop through into the code for fireing + // there if we read successfully we drop through into the code for firing // the read event if not readtrigger then begin state := wsconnected; @@ -697,7 +703,7 @@ begin exit; end; // if things went well here we are now in the state wsconnected with data sitting in our receive buffer - // so we drop down into the processing for data availible + // so we drop down into the processing for data available end; if fdhandlein >= 0 then begin if state = wsconnected then begin