Convert the Async.Epoll package to a generic package so I can easily deal with the Context_Type for callbacks
This commit is contained in:
parent
6dd93c3118
commit
0ab4fef37e
|
@ -7,12 +7,13 @@ use Ada.Text_IO,
|
|||
|
||||
package body Echo is
|
||||
procedure Call_Me_Back (Sock : Socket_Type;
|
||||
Ctx : Async.Epoll.Context_Type) is
|
||||
Ctx : Echo_State) is
|
||||
New_Sock : Socket_Type;
|
||||
Addr : Sock_Addr_Type := Ctx.Server_Addr;
|
||||
begin
|
||||
Put_Line (">>> Starting Call_Me_Back");
|
||||
|
||||
Accept_Socket(Sock, New_Sock);
|
||||
Accept_Socket(Sock, New_Sock, Addr);
|
||||
end Call_Me_Back;
|
||||
end Echo;
|
||||
|
||||
|
|
|
@ -2,10 +2,10 @@ with GNAT.Sockets;
|
|||
with Async.Epoll;
|
||||
|
||||
package Echo is
|
||||
type Echo_State is new Async.Epoll.Context_Type with record
|
||||
type Echo_State is record
|
||||
Server_Addr : GNAT.Sockets.Sock_Addr_Type;
|
||||
end record;
|
||||
|
||||
procedure Call_Me_Back (Sock : GNAT.Sockets.Socket_Type;
|
||||
Ctx : Async.Epoll.Context_Type);
|
||||
Ctx : Echo_State);
|
||||
end Echo;
|
||||
|
|
|
@ -19,7 +19,9 @@ procedure echoserver is
|
|||
Listen_Addr : constant String := "127.0.0.1";
|
||||
Listen_Port : constant Integer := 2046;
|
||||
|
||||
The_Hub : Async.Epoll.Hub := Async.Epoll.Create;
|
||||
package Epoll is new Async.Epoll (Context_Type => Echo.Echo_State);
|
||||
|
||||
The_Hub : Epoll.Hub := Epoll.Create;
|
||||
|
||||
begin
|
||||
Initialize; -- Initialize the GNAT.Sockets library
|
||||
|
@ -37,7 +39,7 @@ begin
|
|||
Put_Line (".. listening for connections");
|
||||
|
||||
declare
|
||||
Ctx : Async.Epoll.Callback_Tuple;
|
||||
Ctx : Epoll.Callback_Tuple;
|
||||
State : Echo.Echo_State;
|
||||
begin
|
||||
The_Hub.Enable_Tracing;
|
||||
|
|
|
@ -11,8 +11,10 @@ use Interfaces,
|
|||
|
||||
private with System;
|
||||
|
||||
generic
|
||||
type Context_Type is private;
|
||||
|
||||
package Async.Epoll is
|
||||
type Context_Type is tagged null record;
|
||||
type Callback_Type is access procedure (Sock : GNAT.Sockets.Socket_Type; Context : Context_Type);
|
||||
|
||||
-- Callback_Tuple is just an arbitrary record to carry the Callback_Type
|
||||
|
|
Loading…
Reference in New Issue