From: Simon Wright <simon@pushface.org>
Subject: Re: copy constructor for sockets
Date: 23 May 2004 12:21:32 +0100
Date: 2004-05-23T12:21:32+01:00 [thread overview]
Message-ID: <x7vvfinie2r.fsf@smaug.pushface.org> (raw)
In-Reply-To: _SPrc.95520$536.16845336@attbi_s03
tmoran@acm.org writes:
> Remember that a task is a thread of control, not a sequence of
> instructions. From that viewpoint, your server needs to fire up a
> task/thread, and that thread needs to find out whether it should execute
> the Get or the Put sequence of instructions. You can pass the server
> socket to the task during the rendezvous, and let the task create a socket
> and do the socket-accept.
Is it really possible to have multiple accept()s? You live and learn!
(I thought you could only have one accept(), which blocks until a
client connect()s and then returns a new socket ... so, with your
design, what is the server doing while the task calls accept()?
I know you can use select() or poll() to block until an accept() would
succeed, is that the idea?
> That lets the server get back to waiting for
> calls as quickly as possible, while the task does the Get_Line (which
> could potentially take a while) and calls an appropriate Handle_Get or
> Handle_Post procedure. You can see an example of this in Smplsrvr (part
> of the free Claw download at www.rrsoftware.com). You might also want to
> see how AWS does it.
>
> > Doesn't the ":=" operator to a "deep copy"?
> If the object is Limited, ":=" is illegal. (That's the case for Claw
> Sockets.) If it's Controlled, then ":=" does a bit pattern copy followed
> by a call on Adjust, which may do nothing, may modify pointers or
> whatever, or may do a deep copy - whatever it wants. If the object is not
> Controlled, and isn't Limited, then ":=" just does a bitwise copy.
That applies recursively to components, of course (remembering that a
type with limited components has to be limited, of course).
I don't know AdaSockets, but GNAT.Sockets (3.15p) has
type Socket_Type is private;
which means that assignment is available, and, in the private part,
type Socket_Type is new Integer;
and in the body (eg)
procedure Accept_Socket
(Server : Socket_Type;
Socket : out Socket_Type;
Address : out Sock_Addr_Type)
is
Res : C.int;
Sin : aliased Sockaddr_In;
Len : aliased C.int := Sin'Size / 8;
begin
Res := C_Accept (C.int (Server), Sin'Address, Len'Access);
if Res = Failure then
Raise_Socket_Error (Socket_Errno);
end if;
Socket := Socket_Type (Res);
Address.Addr := To_Inet_Addr (Sin.Sin_Addr);
Address.Port := Port_Type (Network_To_Port (Sin.Sin_Port));
end Accept_Socket;
so you can see that it's extremely close to the C accept(2); the
socket is essentially a file descriptor, in Unix terms anyway.
So assignment works (for this binding) as it would in C.
--
Simon Wright 100% Ada, no bugs.
next prev parent reply other threads:[~2004-05-23 11:21 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2004-05-22 21:18 copy constructor for sockets Andrew Carroll
2004-05-22 21:46 ` tmoran
2004-05-23 11:21 ` Simon Wright [this message]
2004-05-24 18:26 ` tmoran
2004-05-25 5:10 ` Simon Wright
2004-05-25 6:37 ` tmoran
2004-05-23 9:43 ` Mark Lorenzen
2004-05-23 11:27 ` Simon Wright
-- strict thread matches above, loose matches on Subject: below --
2004-05-24 11:28 Andrew Carroll
2004-05-25 5:29 ` Simon Wright
2004-05-22 10:19 Andrew Carroll
2004-05-22 11:55 ` Simon Wright
2004-05-22 18:39 ` tmoran
2004-05-23 21:04 ` Matthew Heaney
2004-05-24 7:13 ` Marius Amado Alves
2004-05-24 3:23 ` Matthew Heaney
2004-05-24 4:53 ` Simon Wright
2004-05-24 5:20 ` tmoran
2004-05-25 4:53 ` Simon Wright
2004-05-24 12:36 ` Matthew Heaney
2004-05-25 21:50 ` Robert I. Eachus
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox