I try to use a TIdUDPServer component in a workerthread of my app. All is
fine (data is received) until I close the app. I then get an exception of
class EIdSocketError. Message: 'Socket Error # 10004 Interrupted system
call'.
Call stack:
TIdThread.Execute
TIdUDPListener.Run
TIdStack.CheckForSocketError(-1)
TIdStack.CheckForSocketError(-1, (...))
TIdStack.RaiseSocketError(10004)
The exception only comes up when the app is run in the debugger, otherwise
it is swallowed. Should I ignore this behaviour or is there a problem?
BTW: I did read the paragraph about error 10038 during shutdown, but this is
10004, so I will not get tarred and feathered (I hope)...
Here is the relevant code of my workerthread:
{ TUdpThread }
procedure TUdpThread.Init(Port: Integer); // Is called after thread creation
before resuming the thread
begin
New(UdpContainer);
New(UdpHeaderRec);
UdpRcv := TIdUdpServer.Create(nil); // This is our receiver
UdpRcv.DefaultPort := Port;
end;
procedure TUdpThread.Execute;
var
RcvSize: Integer;
begin
UdpRcv.Active := True; // Activate receiver
while not Terminated do begin
if Assigned(UdpRcv) and UdpRcv.Active then begin
RcvSize := UdpRcv.ReceiveBuffer(UdpContainer^[SizeOf(TUdpHeaderRec)],
UdpContainerSize-SizeOf(TUdpHeaderRec), 200);
if (RcvSize > 0) and (RcvSize < UdpContainerSize-RcvSize) then begin
UdpHeaderRec^.Size := RcvSize;
Move(UdpHeaderRec^, UdpContainer^, SizeOf(TUdpHeaderRec));
if FBuf.BlockingWrite(UdpContainer) then
New(UdpContainer);
end;
end;
end;
end;
destructor TUdpThread.Destroy;
begin
FreeAndNil(UdpRcv); // Exception is raised when executing this line
FreeMem(UdpContainer);
Dispose(UdpHeaderRec);
inherited;
end;
Here is my main form's Destroy method:
procedure TMyFrm.FormDestroy(Sender: TObject);
begin
UdpThread.Terminate;
UdpBuf.ResetState;
UdpThread.WaitFor;
UdpBuf.Free;
UdpThread.Free;
end;
Yes. As designed.
>BTW: I did read the paragraph about error 10038 during shutdown, but this is
>10004, so I will not get tarred and feathered (I hope)...
10038 is the most common, but MS keeps changing the error that gets returned
with each OS. Which OS are you running?
--
Chad Z. Hower (Kudzu) - Church Hill, TN - Team Indy
"Programming is an art form that fights back"
Forget the Y2K problem, Lets fix the W2K problem.
http://www.pbe.com/Kudzu/ - Free Delphi/CBuilder components and articles
OK, fine.
>
> >BTW: I did read the paragraph about error 10038 during shutdown, but this
is
> >10004, so I will not get tarred and feathered (I hope)...
>
> 10038 is the most common, but MS keeps changing the error that gets
returned
> with each OS. Which OS are you running?
This is on W2K SP1
Thanks Chad
Stefan