linux-c-programming.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* Socket and STDIN pooling
@ 2006-02-14  5:26 Lejanson C. Go
  2006-02-14  6:36 ` Steve Graegert
  0 siblings, 1 reply; 4+ messages in thread
From: Lejanson C. Go @ 2006-02-14  5:26 UTC (permalink / raw)
  To: linux-c-programming

Hi,

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?


Lejanson

-- 
"The masses of people lead lives of quiet desperation,
           because they lack a sound plan
       through which to accumulate a fortune."
         -Napoleon Hill, Think and Grow Rich


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Socket and STDIN pooling
  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
  0 siblings, 1 reply; 4+ messages in thread
From: Steve Graegert @ 2006-02-14  6:36 UTC (permalink / raw)
  To: linux-c-programming

On 2/14/06, Lejanson C. Go <lejanson@ntsp.nec.co.jp> wrote:
> Hi,
>
> I have a question about pooling 2 sockets and stdin.

I suppose you mean "polling".

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

See (p)select(2) and poll(2) system calls.  Numerous examples on how
to utilize both functions can be found in the Net.

	\Steve

--

Steve Graegert <graegerts@gmail.com>
Software Consultant {C/C++ && Java && .NET}
Office: +49 9131 7123988
Mobile: +49 1520 9289212

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Socket and STDIN pooling
  2006-02-14  6:36 ` Steve Graegert
@ 2006-02-15  5:28   ` Ron Michael Khu
  2006-02-15  5:46     ` Ron Michael Khu
  0 siblings, 1 reply; 4+ messages in thread
From: Ron Michael Khu @ 2006-02-15  5:28 UTC (permalink / raw)
  To: linux-c-programming

select() with the 3 file descriptors :D

provided that the processing time for input (from stdin and the sockets)
is negligible.

if processing time is an issue...
you could try doing a fork() for the individual processing

Steve Graegert wrote:

>On 2/14/06, Lejanson C. Go <lejanson@ntsp.nec.co.jp> wrote:
>  
>
>>Hi,
>>
>>I have a question about pooling 2 sockets and stdin.
>>    
>>
>
>I suppose you mean "polling".
>
>  
>
>>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?
>>    
>>
>
>See (p)select(2) and poll(2) system calls.  Numerous examples on how
>to utilize both functions can be found in the Net.
>
>	\Steve
>
>--
>
>Steve Graegert <graegerts@gmail.com>
>Software Consultant {C/C++ && Java && .NET}
>Office: +49 9131 7123988
>Mobile: +49 1520 9289212
>-
>To unsubscribe from this list: send the line "unsubscribe linux-c-programming" in
>the body of a message to majordomo@vger.kernel.org
>More majordomo info at  http://vger.kernel.org/majordomo-info.html
>
>
>  
>


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Socket and STDIN pooling
  2006-02-15  5:28   ` Ron Michael Khu
@ 2006-02-15  5:46     ` Ron Michael Khu
  0 siblings, 0 replies; 4+ messages in thread
From: Ron Michael Khu @ 2006-02-15  5:46 UTC (permalink / raw)
  To: linux-c-programming


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





^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2006-02-15  5:46 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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 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).