Re: Socket Programming
From: Thomas F. Bur*** (tfb_at_famine.OCF.Berkeley.EDU)
Date: 05/15/04
- Next message: Ray Dillinger: "Re: Need help with a decision!"
- Previous message: Jonathan Steinhart: "Re: question"
- In reply to: Peter Seibel: "Re: Socket Programming"
- Next in thread: Peter Herth: "Re: Socket Programming"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: 15 May 2004 11:00:54 -0700
Peter Seibel <peter@javamonkey.com> writes:
> tfb@famine.OCF.Berkeley.EDU (Thomas F. Bur***) writes:
>
> > Peter Seibel <peter@javamonkey.com> writes:
> >
> >> So I want to make sure I understand what happens under the covers
> >> here--each time a new cliet connects the SERVE-EVENT mechanism notices
> >> that there's stuff to do with *SERVER-SOCKET* and calls
> >> SERVE-CONNECTION to deal with it.
> >
> > Yep.
> >
> >> Within that call you make potentially blocking I/O calls such as to
> >> the database, etc. What happens if another connection comes in
> >> before the first call to SERVE-CONNECTION returns?
> >
> > It calls SERVE-CONNECTION. If you're dealing with connections from
> > the open internet, you want to have a counter that your handler checks
> > before accepting a client, to keep a maximum number on the number of
> > connections you're serving, so you have a base case for your
> > recursion.
>
> So doesn't that mean that within SERVE-CONNECTION I still have to take
> care of synchronizing access to shared data (such as the database
> connection pool)? I.e. I'm still running a multi-threaded app It just
> happens that I'm not spinning up the threads.
You do have to synchronize access to shared resources. However, the
only time another handle gets a chance to run is when you do I/O and
it blocks, or when you call SERVE-EVENT. This makes synchronization a
lot easier; eg, you have to worry about individual db connections, but
not access to the pool itself, unless you do something crazy like find
the index of the connection you want to use, do some I/O, then try to
remove it from the pool.
> Also does this imply a thread-per-connection under the
> covers. Because that's not a great way to write a scalable server.
Nope, it's a facility from the days before most Unixes had threads.
--
/|_ .-----------------------.
,' .\ / | No to Imperialist war |
,--' _,' | Wage class war! |
/ / `-----------------------'
( -. |
| ) |
(`-. '--.)
`. )----'
- Next message: Ray Dillinger: "Re: Need help with a decision!"
- Previous message: Jonathan Steinhart: "Re: question"
- In reply to: Peter Seibel: "Re: Socket Programming"
- Next in thread: Peter Herth: "Re: Socket Programming"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]