A non-blocking socket reading function

Discussion in 'C++' started by Mikael S. H., Jan 2, 2006.

  1. Mikael S. H.

    Mikael S. H. Guest

    Hello comp.lang.c++.

    My friend and I are trying to make a simple IRC client. It'll work
    mostly like irssi, by having "signals", which you can "tie" a function
    to. These functions get executed whenever a certain event happens, such
    as "message received" or "got opped".

    The problem is, that I haven't been able to do this, *and* add
    "timeouts", which would execute a function after a certain piece of
    time. Whenever I'm trying to read from the socket, it stops program
    execution if no message is to be received, and only continues when it does.

    I've thought about making a threaded version, so another process will
    constantly read from the socket, putting any messages there are into a
    variable, which the main program would read. This would mean, that you
    would simply get NULL from the socket_read() function, if there is no
    message.

    That is not an easy task, I found out.

    I have never seen this much frightening documentation about a subject in
    my life. I have tried to read into Mutex's, threadsafe functions and
    void pointer casting of arguments, but it all fails miserably to even
    make the slightest sense.

    Is threading the best solution to this problem?

    How would some code look, just in general?

    Thank you all in advance,
    Mikael S. Høilund.

    --
    GOD I love the internet...

    m k e @ l i d . r
    i a l a m n e o g
     
    Mikael S. H., Jan 2, 2006
    #1
    1. Advertising

  2. Mikael S. H. schrieb:
    > My friend and I are trying to make a simple IRC client. It'll work
    > mostly like irssi, by having "signals", which you can "tie" a function
    > to. These functions get executed whenever a certain event happens, such
    > as "message received" or "got opped".
    >
    > The problem is, that I haven't been able to do this, *and* add
    > "timeouts", which would execute a function after a certain piece of
    > time. Whenever I'm trying to read from the socket, it stops program
    > execution if no message is to be received, and only continues when it does.
    >
    > I've thought about making a threaded version, so another process will
    > constantly read from the socket, putting any messages there are into a
    > variable, which the main program would read. This would mean, that you
    > would simply get NULL from the socket_read() function, if there is no
    > message.


    This is offtopic here, since plain C++ doesn't know about sockets or
    threads. Ask in a newsgroup about your operation system.

    <OT>
    You don't need threads for this. Read about the functions select() and
    poll().
    </OT>

    Thomas
     
    Thomas J. Gritzan, Jan 2, 2006
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Hendra Gunawan
    Replies:
    1
    Views:
    12,946
    Allan Herriman
    Apr 8, 2004
  2. Andre Kelmanson

    blocking i/o vs. non blocking i/o (performance)

    Andre Kelmanson, Oct 10, 2003, in forum: C Programming
    Replies:
    3
    Views:
    984
    Valentin Tihomirov
    Oct 12, 2003
  3. Tim Black
    Replies:
    1
    Views:
    1,260
    Alan Kennedy
    Aug 3, 2004
  4. nukleus
    Replies:
    14
    Views:
    886
    Chris Uppal
    Jan 22, 2007
  5. Serge Savoie
    Replies:
    4
    Views:
    287
    Serge Savoie
    Oct 1, 2008
Loading...

Share This Page