non-threaded accept - Unix

This is a discussion on non-threaded accept - Unix ; 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 ...

+ Reply to Thread
Results 1 to 6 of 6

Thread: non-threaded accept

  1. non-threaded accept

    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



  2. Re: non-threaded accept

    On Oct 15, 4:11 pm, CptDondo 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


  3. Re: non-threaded accept

    In article <13h7svtsbag2805@corp.supernews.com>, CptDondo 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/D...nformation.htm


  4. Re: non-threaded accept

    Almond wrote:
    > In article <13h7svtsbag2805@corp.supernews.com>, CptDondo 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?


    Sounds more like security cameras.


  5. Re: non-threaded accept

    V Mon, 15 Oct 2007 17:01:38 -0700, David Schwartz napsal(a):

    > On Oct 15, 4:11 pm, CptDondo 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.


    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

  6. Re: non-threaded accept

    On Oct 16, 7:08 am, Captain Dondo wrote:
    > V Mon, 15 Oct 2007 17:01:38 -0700, David Schwartz napsal(a):
    >
    > > On Oct 15, 4:11 pm, CptDondo 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.

    >
    > 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


+ Reply to Thread