Luca wrote:

I don't think that synapse is to blame[*]: my test
program is also using the sockets unit directly, and stores SocketError
(which just calls WSAGetLastError) in a variable.



Found the problem using my brute force writeln('') skills. It is an issue with freepascal's stack or something to do with buggy threads methinks. As it is when you call lasterror within another procedure with local variables.. they are corrupted or something.

procedure PError(msg:string);
var e:integer;
begin
 e:=SocketError;
 writeln('PError: '+ msg, ' ', e);
end;

procedure TSocketThread.Execute;
var s:LongInt;
   SAddr:TInetSockAddr;
   Connected:boolean;
   e: integer;
begin
 Connected:=false;
 S:=fpSocket(AF_INET,SOCK_STREAM,0);
 Perror('Socket issue?');
 e:= socketerror;
 if e > -1 then
 begin
   SAddr.sin_family:=AF_INET;
   Saddr.sin_port:=htons(FPort);
   SAddr.sin_addr.s_addr:=StrToNetAddr(FAddress).s_addr;
   if fpconnect(S,@SAddr,SizeOf(SAddr))=0 then Connected:=true;
   e:=SocketError;
Writeln('Fuck: ',e); PError('Connect issue'); // THIS RESETS LASTERR, IT SHOULD NOT
 end else writeln('fpsocket issue');
 if Connected then fpShutdown(s,2);
 CloseSocket(s);
 FFinished:=True;
end;

_______________________________________________
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal

Reply via email to