Re: [twsocket] TFtpCli strange logic

2011-02-12 Thread Arno Garrels
Francois PIETTE wrote:
 1) Command Open succeeds.
 2) After the server received command User it closes the connection
 (FIN/ACK).
 3) OnSessionClosed triggers with ErrCode 0.
 4) OnRequestDone triggers with ErrCode 0 and the status code from
 previous request.
 
 Would you agree that is a bug?
 
 If the server closes the connection as a reaction to a command except
 quit, then OnrequestDone should report a failure code, probably
 WSAECONNRESET. 

Do you see anything obviously wrong in this fix?


procedure TCustomFtpCli.ControlSocketSessionClosed(
Sender  : TObject;
ErrCode : Word);
var
LClosedState : TFtpState;
begin
LClosedState := FState;
if FConnected then begin
FConnected := FALSE;
if FState  ftpAbort then
StateChange(ftpNotConnected);
if Assigned(FOnSessionClosed) then
FOnSessionClosed(Self, ErrCode);
end;
if FState  ftpAbort then
StateChange(ftpInternalReady);
if FRequestType  ftpRqAbort then begin
if (ErrCode  0) or ((FRequestType  ftpQuitAsync) and   //==
   (LClosedState in [ftpWaitingBanner, ftpWaitingResponse])) then begin 
//==
FLastResponse  := '500 Control connection closed - ' +
   GetWinsockOrProxyErrorStr(ErrCode); // == New 
function, not related to this fix
FStatusCode:= 500;
FRequestResult :=  FStatusCode;{ 06 apr 2002 }
SetErrorMessage;
end;
TriggerRequestDone(FRequestResult);
end;
end;


-- 
Arno Garrels
--
To unsubscribe or change your settings for TWSocket mailing list
please goto http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket
Visit our website at http://www.overbyte.be


Re: [twsocket] TFtpCli strange logic

2011-02-12 Thread Francois PIETTE

Do you see anything obviously wrong in this fix?


I Don't.

   GetWinsockOrProxyErrorStr(ErrCode); // == New function, not related to 
this fix


I would name this function GetErrorMsgFromErrorCode since it is a general 
translation from an error number to a message. Probably the implementation 
should as well call the API to get Windows error message description from 
Windows error code. This way it is perfectly generic. We still have the 
problem of colliding error code which exists since the beginning.


--
francois.pie...@overbyte.be
The author of the freeware multi-tier middleware MidWare
The author of the freeware Internet Component Suite (ICS)
http://www.overbyte.be


- Original Message - 
From: Arno Garrels arno.garr...@gmx.de

To: ICS support mailing twsocket@elists.org
Sent: Saturday, February 12, 2011 10:41 AM
Subject: Re: [twsocket] TFtpCli strange logic



Francois PIETTE wrote:

1) Command Open succeeds.
2) After the server received command User it closes the connection
(FIN/ACK).
3) OnSessionClosed triggers with ErrCode 0.
4) OnRequestDone triggers with ErrCode 0 and the status code from
previous request.

Would you agree that is a bug?


If the server closes the connection as a reaction to a command except
quit, then OnrequestDone should report a failure code, probably
WSAECONNRESET.


Do you see anything obviously wrong in this fix?


procedure TCustomFtpCli.ControlSocketSessionClosed(
   Sender  : TObject;
   ErrCode : Word);
var
   LClosedState : TFtpState;
begin
   LClosedState := FState;
   if FConnected then begin
   FConnected := FALSE;
   if FState  ftpAbort then
   StateChange(ftpNotConnected);
   if Assigned(FOnSessionClosed) then
   FOnSessionClosed(Self, ErrCode);
   end;
   if FState  ftpAbort then
   StateChange(ftpInternalReady);
   if FRequestType  ftpRqAbort then begin
   if (ErrCode  0) or ((FRequestType  ftpQuitAsync) and   //==
  (LClosedState in [ftpWaitingBanner, ftpWaitingResponse])) then 
begin //==

   FLastResponse  := '500 Control connection closed - ' +
  GetWinsockOrProxyErrorStr(ErrCode); // == 
New function, not related to this fix

   FStatusCode:= 500;
   FRequestResult :=  FStatusCode;{ 06 apr 2002 }
   SetErrorMessage;
   end;
   TriggerRequestDone(FRequestResult);
   end;
end;


--
Arno Garrels
--
To unsubscribe or change your settings for TWSocket mailing list
please goto http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket
Visit our website at http://www.overbyte.be 


--
To unsubscribe or change your settings for TWSocket mailing list
please goto http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket
Visit our website at http://www.overbyte.be


Re: [twsocket] TFtpCli strange logic

2011-02-12 Thread Arno Garrels
Francois PIETTE wrote:

GetWinsockOrProxyErrorStr(ErrCode); // == New function, not
 related to this fix
 
 I would name this function GetErrorMsgFromErrorCode since it is a
 general translation from an error number to a message.

IMO, from the name it should be clear what range of error numbers
are expected to be translated. Maybe GetWinsockOrProxyErrorMsgFromErrorCode.

 Probably the
 implementation should as well call the API to get Windows error
 message description from Windows error code. 

Won't the API return localized messages? Not nice to have different
languages in log files or error messages.

 generic. We still have the problem of colliding error code which
 exists since the beginning. 

Can't this be solved by introducing a range reserved for component users?
And by introducing a global unit containing all those constants used by
ICS which might lead to conflicts, that would help us a lot to keep overview?
I found for instance SmtpProtocolError = 20600 in SmtpProt.pas yesterday.

-- 
Arno Garrels


 This way it is perfectly
 generic. We still have the problem of colliding error code which
 exists since the beginning. 
 
 --
 francois.pie...@overbyte.be
 The author of the freeware multi-tier middleware MidWare
 The author of the freeware Internet Component Suite (ICS)
 http://www.overbyte.be
 
 
 - Original Message -
 From: Arno Garrels arno.garr...@gmx.de
 To: ICS support mailing twsocket@elists.org
 Sent: Saturday, February 12, 2011 10:41 AM
 Subject: Re: [twsocket] TFtpCli strange logic
 
 
 Francois PIETTE wrote:
 1) Command Open succeeds.
 2) After the server received command User it closes the connection
 (FIN/ACK).
 3) OnSessionClosed triggers with ErrCode 0.
 4) OnRequestDone triggers with ErrCode 0 and the status code from
 previous request.
 
 Would you agree that is a bug?
 
 If the server closes the connection as a reaction to a command
 except quit, then OnrequestDone should report a failure code,
 probably WSAECONNRESET.
 
 Do you see anything obviously wrong in this fix?
 
 
 procedure TCustomFtpCli.ControlSocketSessionClosed(
Sender  : TObject;
ErrCode : Word);
 var
LClosedState : TFtpState;
 begin
LClosedState := FState;
if FConnected then begin
FConnected := FALSE;
if FState  ftpAbort then
StateChange(ftpNotConnected);
if Assigned(FOnSessionClosed) then
FOnSessionClosed(Self, ErrCode);
end;
if FState  ftpAbort then
StateChange(ftpInternalReady);
if FRequestType  ftpRqAbort then begin
if (ErrCode  0) or ((FRequestType  ftpQuitAsync) and  
   //== (LClosedState in [ftpWaitingBanner,
 ftpWaitingResponse])) then 
 begin //==
FLastResponse  := '500 Control connection closed - ' +
   GetWinsockOrProxyErrorStr(ErrCode); //
 == New function, not related to this fix
FStatusCode:= 500;
FRequestResult :=  FStatusCode;{ 06 apr 2002 }
SetErrorMessage;
end;
TriggerRequestDone(FRequestResult);
end;
 end;
 
 
 --
 Arno Garrels
 --
 To unsubscribe or change your settings for TWSocket mailing list
 please goto http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket
 Visit our website at http://www.overbyte.be
--
To unsubscribe or change your settings for TWSocket mailing list
please goto http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket
Visit our website at http://www.overbyte.be


Re: [twsocket] TFtpCli strange logic

2011-02-12 Thread Francois PIETTE

   GetWinsockOrProxyErrorStr(ErrCode); // == New function, not
related to this fix


I would name this function GetErrorMsgFromErrorCode since it is a
general translation from an error number to a message.


IMO, from the name it should be clear what range of error numbers
are expected to be translated. Maybe 
GetWinsockOrProxyErrorMsgFromErrorCode.


Indeed, but then when another range is created, a new function has to be 
created as well. No a good idea IMO.
Better to have a general purpose function to translate any error code to a 
message.
We could also imagine an optional argument with a set of message ranges to 
check, defaulting to all ranges.



Probably the
implementation should as well call the API to get Windows error
message description from Windows error code.


Won't the API return localized messages?


Probably.
FormatMessage 
(http://msdn.microsoft.com/en-us/library/ms679351(v=VS.85).aspx) has a 
dwLanguageId argument but probably most Windows do not have all languages 
installed. Maybe english messages are always there ?



Not nice to have different
languages in log files or error messages.


Agreed. But difficult to reach in a real application involving a lot of 
components/libraries anyway.




generic. We still have the problem of colliding error code which
exists since the beginning.


Can't this be solved by introducing a range reserved for component users?
And by introducing a global unit containing all those constants used by
ICS which might lead to conflicts, that would help us a lot to keep 
overview?

I found for instance SmtpProtocolError = 20600 in SmtpProt.pas yesterday.


According to windows documentation 
(http://msdn.microsoft.com/en-us/library/ms681381(v=vs.85).aspx), system 
error code are in the range 0-15999. So the error number I selected long 
time ago doesn't collide with Windows.


--
francois.pie...@overbyte.be
The author of the freeware multi-tier middleware MidWare
The author of the freeware Internet Component Suite (ICS)
http://www.overbyte.be

--
To unsubscribe or change your settings for TWSocket mailing list
please goto http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket
Visit our website at http://www.overbyte.be


[twsocket] TFtpCli strange logic

2011-02-11 Thread Arno Garrels
Hi,

1) Command Open succeeds.
2) After the server received command User it closes the connection (FIN/ACK).
3) OnSessionClosed triggers with ErrCode 0.
4) OnRequestDone triggers with ErrCode 0 and the status code from previous 
request.

Would you agree that is a bug?

-- 
Arno Garrels

 
--
To unsubscribe or change your settings for TWSocket mailing list
please goto http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket
Visit our website at http://www.overbyte.be