[AWS] RST fix for accept socket
Björn Lundin
b.f.lundin at gmail.com
Tue Jan 10 13:15:00 CET 2012
Hi!
Using AWS on AIX (and perhaps some other platforms too) sometimes causes trouble
when the client sends RST, see Richard Steven's Unix network programming,
Volume 1, second edition chapter 5.11 'Connection Abort before accept Returns'
What happens is that the client initiates the connection, but for some
reason gets second thoughts.
On AIX, we leave accept with an error, and as is of now, the code does
note recover.
Below is a solution, but from AWS 1.4 I think. But looking at 2.8
sources, the procedure is rewritten,
but still suffers from the same weakness.
Patches were never my strong side, so I send in the whole procedure.
(and yes, the put_lines should obviously be removed, but we put them there to
confirm that this hack fixed it, and it does)
procedure Accept_Socket
(Socket : in Net.Socket_Type'Class;
New_Socket : in out Socket_Type)
is
Sock_Addr : Sockets.Sock_Addr_Type;
begin
if New_Socket.S = null then
New_Socket.S := new Socket_Hidden;
end if;
--Fix Start...
-- Sometimes the clients sends RST, which by some operating system are
-- handled locally in the accept procedure. This is not the case
on AIX, which will
-- raise [72] "Software caused connection abort"
-- We have added code that will ignore this error and
Accept_Socket will be runned again,
-- so incoming connections are accepted.
loop
begin
Sockets.Accept_Socket
(SFD (Socket_Type (Socket).S.all),
SFD (New_Socket.S.all), Sock_Addr);
exit;
exception
when E : AWS.Net.Socket_error | Gnat.Sockets.Socket_Error =>
if Ada.Strings.Fixed.Count(Ada.Exceptions.Exception_Message(e),
"[72]") > 0 then
Ada.Text_Io.Put_Line("Got error Accept_Socket [72]
Software caused connection abort");
else
Ada.Text_Io.Put_Line("Got error Accept_Socket " &
Ada.Exceptions.Exception_Message(e));
raise;
end if;
end;
end loop;
--Fix stop
Set_Cache (New_Socket);
exception
when E : others =>
Free (New_Socket);
Raise_Exception (E, "Accept_Socket");
end Accept_Socket;
--
/Björn
More information about the AWS
mailing list