Echo server: Difference between revisions
Content added Content deleted
m (→{{header|Ada}}) |
|||
Line 54: | Line 54: | ||
with Ada.IO_Exceptions; |
with Ada.IO_Exceptions; |
||
with GNAT.Sockets; |
with GNAT.Sockets; |
||
procedure |
procedure echo_server_multi is |
||
-- Multiple socket connections example based on Rosetta Code |
-- Multiple socket connections example based on Rosetta Code echo server. |
||
Tasks_To_Create : constant := 3; -- simultaneous socket connections. |
Tasks_To_Create : constant := 3; -- simultaneous socket connections. |
||
Line 66: | Line 66: | ||
subtype Index is integer range 1 .. Tasks_To_Create; |
subtype Index is integer range 1 .. Tasks_To_Create; |
||
protected type Info is |
protected type Info is |
||
procedure Push_Stack (Return_Task_Index : in |
procedure Push_Stack (Return_Task_Index : in Index); |
||
procedure Initialize_Stack; |
procedure Initialize_Stack; |
||
entry Pop_Stack (Get_Task_Index : out |
entry Pop_Stack (Get_Task_Index : out Index); |
||
private |
private |
||
Task_Stack : Integer_List; -- Stack of free-to-use tasks. |
Task_Stack : Integer_List; -- Stack of free-to-use tasks. |
||
Line 76: | Line 76: | ||
protected body Info is |
protected body Info is |
||
procedure Push_Stack (Return_Task_Index : in |
procedure Push_Stack (Return_Task_Index : in Index) is |
||
begin -- Performed by tasks that were popped, so won't overflow. |
begin -- Performed by tasks that were popped, so won't overflow. |
||
Stack_Pointer := Stack_Pointer + 1; |
Stack_Pointer := Stack_Pointer + 1; |
||
Line 82: | Line 82: | ||
end; |
end; |
||
entry Pop_Stack (Get_Task_Index : out |
entry Pop_Stack (Get_Task_Index : out Index) when Stack_Pointer /= 0 is |
||
begin -- guarded against underflow. |
begin -- guarded against underflow. |
||
Get_Task_Index := Task_Stack(Stack_Pointer); |
Get_Task_Index := Task_Stack(Stack_Pointer); |
||
Line 90: | Line 90: | ||
procedure Initialize_Stack is |
procedure Initialize_Stack is |
||
begin |
begin |
||
for I in Task_Stack' |
for I in Task_Stack'range loop |
||
Push_Stack (I); |
Push_Stack (I); |
||
end loop; |
end loop; |
||
Line 194: | Line 194: | ||
begin |
begin |
||
Echo_Server.Listen; |
Echo_Server.Listen; |
||
end |
end echo_server_multi; |
||
</lang> |
</lang> |
||