comp.lang.ada
 help / color / mirror / Atom feed
* copy constructor for sockets
@ 2004-05-22 10:19 Andrew Carroll
  2004-05-22 11:55 ` Simon Wright
  0 siblings, 1 reply; 21+ messages in thread
From: Andrew Carroll @ 2004-05-22 10:19 UTC (permalink / raw)
  To: comp.lang.ada

I am wondering if it is possible to write a copy constructor for a
socket.
I did not see one in AdaSockets however I have never written a "copy
constructor" in Ada so I probably wouldn't know what to look for.

Maybe it violates some standard for socket communication to have a copy
constructor for a socket?

Just curious.

Andrew




^ permalink raw reply	[flat|nested] 21+ messages in thread
* copy constructor for sockets
@ 2004-05-22 21:18 Andrew Carroll
  2004-05-22 21:46 ` tmoran
                   ` (2 more replies)
  0 siblings, 3 replies; 21+ messages in thread
From: Andrew Carroll @ 2004-05-22 21:18 UTC (permalink / raw)
  To: comp.lang.ada

Okay,

I have written a small test server.  All it does is Accept() connections
and Get_line() and then a final Get().  It is just an experiment but I
want the server now to create a task (with a socket as one of it's
members) and initialize that socket.  There are two types of tasks
however and the distinction between which task to create comes from the
header information in the get_line() right after the Accept().  If it is
a GET header then I would create task type A, if it is a POST then I
would create task type B.

So, the server must accept the socket and do an initial read to get the
header information (GET or POST) to know which type of task to create.
Then I want to initialize the socket that is in the task type to be the
same as the socket in the server that was just accepted.  It would
probably need to be a "deep copy" of the socket because the server will
need to release the socket and the task will need to keep the socket.
By release I mean close() and by keep I mean use for communication.

The other option is to use an access yet I think it could be done
without it.

Doesn't the ":=" operator to a "deep copy"?

Andrew





^ permalink raw reply	[flat|nested] 21+ messages in thread
* copy constructor for sockets
@ 2004-05-24 11:28 Andrew Carroll
  2004-05-25  5:29 ` Simon Wright
  0 siblings, 1 reply; 21+ messages in thread
From: Andrew Carroll @ 2004-05-24 11:28 UTC (permalink / raw)
  To: comp.lang.ada

Wow, GREAT information!!  Thanks all!!

Steve, Matthew, Marius:
Accept() does block, as you expected.  At least with AdaSockets.

I have three tasks.  One is the "accepting" task and the other two tasks
just do various work depending on the "method" of an HTTP header
(obtained from the first Get_Line(<socket>)).  So, accept() initializes
the socket, does one Get_Line(<socket>) and then if the method is GET,
then I want to pass the socket to task 'A'.  If the method is POST then
I want to pass the socket to task 'B'.  In both cases, I want the task
to provide the HTTP user with a response and close the socket.

All the "accepting" task does is initialize sockets and create new
tasks.  Well, it will do other things but right now I am just
experimenting.  Your select() or poll() idea is beautiful!  Because
then, when an accept would occur, I can have the tasks ('A' or 'B')
handle the whole "session".  Question now is, how do I know which task
to assign it to for handling?  I cannot get into the HTTP header before
I "accept".  Hmmmm....Anyway...

I once downloaded AWS but never really read about it because I was
looking into the source code for other things about an idea I had, of
which I gave up on.  I went back to read about AWS recently and it
provides the Callbacks and Method ?API? which would accomplish what I am
trying to achieve.  I haven't investigated "how" they did it and in fact
I would rather drudge through this for learning purposes, at least for a
while.

So, in the end I think I will ask permission to use AWS and skip the
"accepting" task in my design.  Then place the task 'A' and task 'B'
implementations in the Callback based on Method from AWS.  (forgive me,
I do not have the AWS documentation open to give accurate API names)

Never the less I am learning some great things.  You mentioned that a
socket is a file descriptor (Unix) and I'm not quite sure I fully
understand the implications of that.  I "heard" that sockets were
designed in such a way that it would be "transparent", like working with
files.  Does that mean I can do a seek() on a socket?  When people throw
out the term "file descriptor" and start talking about "small positive
integers" I draw a blank as to how those are used for "communication"
over a network device in general.  After all, there are MANY small
positive integers on my computer.  I'm assuming the file descriptor (fd)
means something to the OS?  So somewhere in the kernel or "shell"
interrupt handler there is an else if (//it is a small positive integer)
{ //must be a socket, fire-up the RS-232 driver}?

I thought a socket was an abstraction from an address?  For example. the
address to a UART or RS-232 PIC.  A driver of which is written (probably
a module) to control that device.  So how does a fd relate to that
driver?  Or are you saying that somewhere in my /dev directory there is
a directory entry for my UART?  I can just arbitrarily (at risk of
destruction) send data to the UART through an entry in the /dev
directory?

I guess I'm just trying to fill in the holes of what I have learned thus
far.  Or maybe more appropriately what I have failed to learn.

Thanks again!!

Andrew Carroll
Carroll-Tech
720-273-6814
andrew@carroll-tech.net




^ permalink raw reply	[flat|nested] 21+ messages in thread

end of thread, other threads:[~2004-05-25 21:50 UTC | newest]

Thread overview: 21+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-05-22 10:19 copy constructor for sockets 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
  -- strict thread matches above, loose matches on Subject: below --
2004-05-22 21:18 Andrew Carroll
2004-05-22 21:46 ` tmoran
2004-05-23 11:21   ` Simon Wright
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
2004-05-24 11:28 Andrew Carroll
2004-05-25  5:29 ` Simon Wright

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox