|
Home > Archive > Unix Programming > October 2007 > non-threaded accept
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
non-threaded accept
|
|
| CptDondo 2007-10-15, 7:22 pm |
| I've got a conceptual problem I'm trying to work through.
I need to write a server that handles up to 8 connections, and sends out
a different mjpeg stream from each one. I am handling up to 8 cameras
and I have to serve them round-robin fasion; I cannot handle concurrent
access to 2 cameras so each read from a camera must complete before the
next one starts.
So the streams have to be generated by a single process, something like
this:
listen on 8 sockets
loop forever through 8 connections
when a connection is established, mark it active
when a connection is dropped, mark it inactive and clean up
if a connection is active, send image
I'm having some trouble figuring out how to accept the connections
without forking and how to clean up after the connection is dropped. I
haven't done this too often so I'm pretty much going "by the book" and
the book doesn't cover this. :-(
Thanks,
--Yan
| |
| David Schwartz 2007-10-15, 7:22 pm |
| On Oct 15, 4:11 pm, CptDondo <y...@NsOeSiPnAeMr.com> wrote:
> I'm having some trouble figuring out how to accept the connections
> without forking
If 'accept' says the listening socket is readable, call 'accept'. Make
sure to set the listening socket non-blocking.
> and how to clean up after the connection is dropped.
When 'read' returns zero, 'close' the socket and mark the connection
inactive.
DS
| |
| Almond 2007-10-16, 1:28 am |
| In article <13h7svtsbag2805@corp.supernews.com>, CptDondo <yan@NsOeSiPnAeMr.com> wrote:
>I've got a conceptual problem I'm trying to work through.
>
>I need to write a server that handles up to 8 connections, and sends out
>a different mjpeg stream from each one. I am handling up to 8 cameras
>and I have to serve them round-robin fasion; I cannot handle concurrent
>access to 2 cameras so each read from a camera must complete before the
>next one starts.
Selling sex?
--
Get yourself the most powerful tool for usenet you ever heard of.
NewsMaestro v. 4.0.1 Hail Democracy Release has been released.
Important feature additions and various improvements
and optimizations.
Web page:
http://newsmaestro.sourceforge.net/
NewsMaestro download page:
http://newsmaestro.sourceforge.net/...Information.htm
| |
| Golden California Girls 2007-10-16, 1:28 am |
| Almond wrote:
> In article <13h7svtsbag2805@corp.supernews.com>, CptDondo <yan@NsOeSiPnAeMr.com> wrote:
>
> Selling sex?
Sounds more like security cameras.
| |
| Captain Dondo 2007-10-16, 1:28 am |
| V Mon, 15 Oct 2007 19:31:10 -0700, Golden California Girls napsal(a):
> Almond wrote:
>
> Sounds more like security cameras.
Well it could be sex - if I get a mate for the reptiles. I'm sure mating
lizards could get me more visitors.
I'm trying to set up "24 hours in the life" of snakes and lizards. Could
include such kinky things as swallowing mice whole, eating live crickets
with your tongue, and laying naked under sunlamps. Whatever turns your
crank, I guess.
The platform is a small embedded box that serves images from the cameras
to a post-processing backend.
:-)
| |
| Captain Dondo 2007-10-16, 1:28 pm |
| V Mon, 15 Oct 2007 17:01:38 -0700, David Schwartz napsal(a):
> On Oct 15, 4:11 pm, CptDondo <y...@NsOeSiPnAeMr.com> wrote:
>
>
> If 'accept' says the listening socket is readable, call 'accept'. Make
> sure to set the listening socket non-blocking.
>
>
> When 'read' returns zero, 'close' the socket and mark the connection
> inactive.
I'm streaming so I never expect there to be any data to read. Do I look
for EBADF | EINVAL? Or EAGAIN?
Or should I be looking for write return values of EBADF | EINVAL? Or
EAGAIN?
Thanks,
--Yan
| |
| David Schwartz 2007-10-20, 1:31 am |
| On Oct 16, 7:08 am, Captain Dondo <y...@NsOeSiPnAeMr.com> wrote:
> V Mon, 15 Oct 2007 17:01:38 -0700, David Schwartz napsal(a):
>
>
>
>
>
>
> I'm streaming so I never expect there to be any data to read. Do I look
> for EBADF | EINVAL? Or EAGAIN?
When 'read' returns zero, 'close' the socket. Whether or not you're
expecting data, you still need to call 'read' when there's data to be
read.
> Or should I be looking for write return values of EBADF | EINVAL? Or
> EAGAIN?
You should be doing that too, but if the socket is readable, you
should call 'read'.
DS
|
|
|
|
|