[openbeosnetteam] Re: The gauntlet...

  • From: "David Reid" <dreid@xxxxxxxxxxxx>
  • To: <openbeosnetteam@xxxxxxxxxxxxx>
  • Date: Sat, 23 Feb 2002 11:42:51 -0000

> > BTW, you'll notice the sockets code lives in the net_server app -
> > this was a
> > design decision based on the amount of pools and the interactions it
> > makes.
> > Given we need them as an essential service I'm happy with this, but
> > if
> > you're not then please yell.
>
> That was what I meant before: IMO the socket stuff should live in the
> net_server.

Good.

> > BTW II, you'll see notes all over the place about locking. I haven't
> > done
> > much as Axel seems to be the master locksmith and I'm hoping we can
> > use his
> > locks, or maybe that he could have a look?
> > Sorry Axel, looks like it's over to you!!?!!

We'll have to talk about the locking I guess as it should be possible to do
it quite nicely and granular I think.

> I will have a look, but could you give a short overview what the code
> does right now? Since you've written it, you should know, and it would
> save me some time.
> Like what is inpcb.c for, soreserve(), etc. Thanks :-)

OK, quick overview...

Basically this is the BSD model that was developed for a kernel stack, with
some small changes.

When a user calls socket() in userland the call is routed to the stack with
additional parameters (process and a return value). The actual parameters
from the call are stored in a seperate structure. This bit I've changed as
we're all userland but it can be added back.

The userland socket is routed to socket() in the stack which does some setup
and calls socreate() which actually creates the socket and PCB. what's a
PCB? It's a Protocol Control Block. basically it handles the assigning of
ip/port to a socket and vice versa. Without them how would we know where the
data was to be sent? The PCB is created by calling userreq() in the
appropriate protocol with the PRU_ATTACH command. Each PCB is referenced to
it's head, and so far we only have the UDP head and we only make UDP PCB's.
We will eventually also create TCP PCB's. The code that's there has sockets
in socket.c, pcb's in inpcb.c and socket buffers in sockbuf.c. The code
should be reasonable OK to read? The principal is basically that at the
"top" of the stack we have a layer (PCB's) that take our socket data and
translate it into actual IP/port combinations as required
(multiplex/demultiplex). The socket layer then sits atop that.

Sending/recv'ing data gets even more complicated, but basically follows the
same logic where the userland call is translated into a stack call and then
passed down/up the stack as required. The socket maintains queue's of mbuf's
coming/going and code in socketbuf pushs/pops mbufs onto/off the queue's as
required.

I have sendto and recvfrom implemented but recvfrom doesn't yet work due to
some problem in the PCB's we create.

libsocket.so should basically implement the first stage of these calls. What
in BSD is userland would live in libsocket.so, in other words socket(),
bind(), connect(), sendto(), recvfrom(), closesocket(). These should then
call the appropriate call in the stack which will have the same name, so
should be easy to find :) We may want to rename the stack versions though :)

That may not help?

I'm away all weekend but will ty to catch up on Monday and will hopefully
get the code I have committed on Monday, fully working.

david



Other related posts: