Re: client server communication and system() call
- From: scott@xxxxxxxxxxxxx (Scott Lurndal)
- Date: Wed, 21 May 2008 00:04:10 GMT
phil-news-nospam@xxxxxxxx writes:
On Tue, 20 May 2008 10:08:45 +0500 arnuld <sunrise@xxxxxxxxxxxxxxxx> wrote:
|> On Mon, 19 May 2008 12:52:11 +0200, Rainer Weikusat wrote:
|
|> Just in case this isn't clear without it: The dup2-call can be used to
|> cause an existing descriptor to refer to the file description
|> associated with another descriptor. In this particular case, it would
|> likely look like
|>
|> dup2(accepted_fd, STDOUT_FILENO)
|>
|> executed in a forked process. This means that another process started
|> from the one where the redirection is executed will use the
|> established TCP-connection whenever it prints anything on its
|> 'standard output channel'.
|
|
| it works fine :)
|
| dup2( accept_fd, 1 );
| system( store_in );
|
| but Googling also gives this alternative where the poster claims that
| use of dup2 is reduant and I should use this one:
|
| close(1);
| dup( accept_fd );
| system( store_in );
|
|
| what say ?
That depends on STDIN being open. In most all cases it probably is.
Otherwise you could find that dup() puts the new descriptor at 0 and
you don't get any of the output. So go with the dup2() solution.
Even worse, in a multithreaded program, there is no guarantee that
another thread didn't do an open between the close and the dup. Always
use dup2.
scott
.
- Follow-Ups:
- Re: client server communication and system() call
- From: phil-news-nospam
- Re: client server communication and system() call
- References:
- client server communication and system() call
- From: arnuld
- Re: client server communication and system() call
- From: Rainer Weikusat
- Re: client server communication and system() call
- From: arnuld
- Re: client server communication and system() call
- From: Rainer Weikusat
- Re: client server communication and system() call
- From: Rainer Weikusat
- Re: client server communication and system() call
- From: arnuld
- Re: client server communication and system() call
- From: phil-news-nospam
- client server communication and system() call
- Prev by Date: Re: aio_read/write versus O_NONBLOCK
- Next by Date: What's the substitution of brk system call in POSIX standard?
- Previous by thread: Re: client server communication and system() call
- Next by thread: Re: client server communication and system() call
- Index(es):
Relevant Pages
|