text
stringlengths
0
234
function Get_Error return League.Strings.Universal_String is
use type GNAT.Sockets.Error_Type;
Option : constant GNAT.Sockets.Option_Type :=
GNAT.Sockets.Get_Socket_Option
(Self.Internal,
GNAT.Sockets.Socket_Level,
GNAT.Sockets.Error);
begin
if Option.Error = GNAT.Sockets.Success then
return League.Strings.Empty_Universal_String;
else
return League.Strings.To_Universal_String
(GNAT.Sockets.Error_Type'Wide_Wide_Image (Option.Error));
end if;
end Get_Error;
Prev : constant Network.Polls.Event_Set := Self.Events;
-- Active poll events
Input : constant Network.Polls.Event := Network.Polls.Input;
Output : constant Network.Polls.Event := Network.Polls.Output;
Listener : array (Input .. Output) of Network.Connections.Listener_Access
:= (others => Self.Listener);
Again : Boolean := True;
begin
Self.In_Event := True;
if Self.Promise.Is_Pending then
Self.Error := Get_Error;
if Self.Error.Is_Empty then
Self.Events := (others => False); -- no events before listener
Self.Promise.Resolve (Self'Unchecked_Access);
-- Usually it changes Listener
if Self.Listener.Assigned then
if not Self.Events (Polls.Output) then
Self.Events := not Write_Event; -- We can write now
Self.Listener.Can_Write;
else
Self.Events := (others => True);
end if;
end if;
if Self.Events /= Prev then
Self.Change_Watch (Self.Events);
end if;
else
Disconnect (Self.Error);
Self.Promise.Reject (Self.Error);
end if;
elsif Self.Is_Closed then
-- Connection has been closed, but some events arrive after that.
null;
else
pragma Assert (Self.Listener.Assigned);
pragma Assert (Self.Error.Is_Empty);
Self.Events := Self.Events and not Events;
-- Report read event to current listener
if Events (Input) then -- Have something to read
Self.Listener.Can_Read;
-- This can change Self.Events, Self.Listener or close
end if;
-- Report write event to current listener
if Events (Output)
and not Self.Events (Output) -- Have space to write
and Self.Listener = Listener (Output)
and not Self.Is_Closed
then
Self.Listener.Can_Write;
-- This can change Self.Events, Self.Listener or close
end if;
-- Now report to changed listener if any
while Again loop
Again := False;
if not Self.Events (Input) -- Can read
and Self.Listener /= Listener (Input)
and not Self.Is_Closed
then
Listener (Input) := Self.Listener;
Self.Listener.Can_Read;
Again := True;
end if;
if not Self.Events (Output) -- Can write
and Self.Listener /= Listener (Output)
and not Self.Is_Closed
then
Listener (Output) := Self.Listener;
Self.Listener.Can_Write;
Again := True;
end if;