[fpc-pascal] Re: WSAGetLastError returns 0 when it shouldn't but I cannot see why
Luca Olivetti
luca at ventoso.org
Mon Mar 3 10:14:46 CET 2008
En/na Luca Olivetti ha escrit:
> En/na L ha escrit:
>
>>> 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.
>>>
>> Aha.. I changed the by Value parameter to a CONST parameter in the
>> error procedure (Perror).. And this solves the issue..
>>
>> So something to do with calling by Value within a thread versus a
>> const (pointer?).
>
> This seriously worries me, since I use threads extensively, and I mostly
> use call by value parameters.
I finally had time to test this (do you remember that dilber strip where
he asks his PHB which one of the 3 projects he's juggling should be
finished on schedule, and the PHB replies he should finish them all on
schedule? well, I'm pretty much in the same situation now).
Changing my "procedure PError(msg:string)" to "procedure PError(const
msg:string)" in TSocketThread.Execute in project2 also fixes the problem.
This smells like a bug somewhere in fpc/rtl, since I don't think it
should make a difference.
Anyway, this gives me no clue on how to "fix" synapse.
Synapse does this:
function TBlockSocket.SockCheck(SockResult: Integer): Integer;
begin
ResetLastError;
if SockResult = integer(SOCKET_ERROR) then
begin
FLastError := synsock.WSAGetLastError;
FLastErrorDesc := GetErrorDescEx;
end;
Result := FLastError;
end;
then in a connect it wraps the connect call in SockCheck:
procedure TBlockSocket.Connect(IP, Port: string);
var
Sin: TVarSin;
begin
SetSin(Sin, IP, Port);
if FLastError = 0 then
begin
if FSocket = INVALID_SOCKET then
InternalCreateSocket(Sin);
SockCheck(synsock.Connect(FSocket, Sin));
if FLastError = 0 then
GetSins;
FBuffer := '';
FLastCR := False;
FLastLF := False;
end;
ExceptCheck;
DoStatus(HR_Connect, IP + ':' + Port);
end;
Changing
function TBlockSocket.SockCheck(SockResult: Integer): Integer;
to
function TBlockSocket.SockCheck(const SockResult: Integer): Integer;
does nothing.
Moreover, something really fishy is going on: look at the attached
project4 (now using synapse).
First I try outside a thread, and it correctly reports error 10060, then
inside a thread, where it reports 0, then again outside the thread (same
procedure) and this time it reports 0!
What's going on?
Bye
--
Luca
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: project4.lpr
URL: <http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20080303/61c86bec/attachment.ksh>
More information about the fpc-pascal
mailing list