Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > A non-blocking socket reading function

Reply
Thread Tools

A non-blocking socket reading function

 
 
Mikael S. H.
Guest
Posts: n/a
 
      01-02-2006
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
 
Reply With Quote
 
 
 
 
Thomas J. Gritzan
Guest
Posts: n/a
 
      01-02-2006
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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: socket.unbind or socket.unlisten? - socket.error: (48, 'Addressalready in use') Steve Holden Python 1 02-03-2009 06:20 AM
Re: socket.unbind or socket.unlisten? - socket.error: (48, 'Addressalready in use') Steve Holden Python 0 02-01-2009 12:45 PM
Re: socket.unbind or socket.unlisten? - socket.error: (48, 'Addressalready in use') Laszlo Nagy Python 0 02-01-2009 07:37 AM
socket.unbind or socket.unlisten? - socket.error: (48, 'Addressalready in use') Laszlo Nagy Python 1 01-27-2009 05:05 PM
Re: socket.unbind or socket.unlisten? - socket.error: (48,'Address already in use') Jean-Paul Calderone Python 0 01-27-2009 01:41 PM



Advertisments