From: Ron Michael Khu <ronkhu@ntsp.nec.co.jp>
To: linux-c-programming@vger.kernel.org
Subject: Re: Socket and STDIN pooling
Date: Wed, 15 Feb 2006 13:46:30 +0800 [thread overview]
Message-ID: <43F2C036.4000302@hq.ntsp.nec.co.jp> (raw)
In-Reply-To: <43F2BC05.5030700@hq.ntsp.nec.co.jp>
>I have a question about pooling 2 sockets and stdin.
>I am currently making an application which accepts
>input from the stdin.
>It had a connection to a server connecting to 2ports.
>If for example the stdin is a blocking descriptor and
>the 2 other descriptors are to be checked real time
>how can it be done without using threads?
pseudo-code for polling multiple file descriptors:
( no error checking..)
set STDIN in mySet
set socket1 in mySet
set socket2 in mySet
for( ; ; )
{
copy mySet to mySet2
while ( select( largestFd, &mySet2, NULL, NULL, NULL ) > 0 )
{
for ( i=0; i<=largestFd; i++ )
{
if ( i is in mySet2)
{
<u can do a fork() here if u want>
switch( i )
{
case STDIN: <process input>; break;
case socket1: <process data>; break;
case socket2: <process data>; break;
}
}
}
}
}
Of coure there are many ways of traversing thru an fdset...
prev parent reply other threads:[~2006-02-15 5:46 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2006-02-14 5:26 Socket and STDIN pooling Lejanson C. Go
2006-02-14 6:36 ` Steve Graegert
2006-02-15 5:28 ` Ron Michael Khu
2006-02-15 5:46 ` Ron Michael Khu [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=43F2C036.4000302@hq.ntsp.nec.co.jp \
--to=ronkhu@ntsp.nec.co.jp \
--cc=linux-c-programming@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).