Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c++ > #9345 > unrolled thread

Create an istream from an fd?

Started byNoah Roberts <roberts.noah@gmail.com>
First post2011-08-26 08:54 -0700
Last post2011-08-27 02:40 +0100
Articles 5 on this page of 25 — 8 participants

Back to article view | Back to comp.lang.c++


Contents

  Create an istream from an fd? Noah Roberts <roberts.noah@gmail.com> - 2011-08-26 08:54 -0700
    Re: Create an istream from an fd? Leigh Johnston <leigh@i42.co.uk> - 2011-08-26 17:05 +0100
    Re: Create an istream from an fd? Victor Bazarov <v.bazarov@comcast.invalid> - 2011-08-26 12:20 -0400
    Re: Create an istream from an fd? Vaclav Zeman <vzeman79@sh.cvut.cz> - 2011-08-26 18:34 +0200
    Re: Create an istream from an fd? Ian Collins <ian-news@hotmail.com> - 2011-08-27 08:48 +1200
    Re: Create an istream from an fd? "Alf P. Steinbach" <alf.p.steinbach:usenet@gmail.com> - 2011-08-27 01:26 +0200
      Re: Create an istream from an fd? Ian Collins <ian-news@hotmail.com> - 2011-08-27 11:30 +1200
        Re: Create an istream from an fd? "Alf P. Steinbach" <alf.p.steinbach:usenet@gmail.com> - 2011-08-27 02:46 +0200
          Re: Create an istream from an fd? Ian Collins <ian-news@hotmail.com> - 2011-08-28 10:52 +1200
            Re: Create an istream from an fd? James Kanze <james.kanze@gmail.com> - 2011-08-27 16:35 -0700
              Re: Create an istream from an fd? Nobody <nobody@nowhere.com> - 2011-08-28 04:31 +0100
                Re: Create an istream from an fd? Ian Collins <ian-news@hotmail.com> - 2011-08-28 15:56 +1200
                  Re: Create an istream from an fd? Nobody <nobody@nowhere.com> - 2011-08-28 20:03 +0100
                    Re: Create an istream from an fd? Ian Collins <ian-news@hotmail.com> - 2011-08-29 07:52 +1200
                Re: Create an istream from an fd? James Kanze <james.kanze@gmail.com> - 2011-08-29 03:54 -0700
                  Re: Create an istream from an fd? Leigh Johnston <leigh@i42.co.uk> - 2011-08-29 13:55 +0100
                  Re: Create an istream from an fd? Nobody <nobody@nowhere.com> - 2011-08-29 20:12 +0100
                    Re: Create an istream from an fd? Ian Collins <ian-news@hotmail.com> - 2011-08-30 07:49 +1200
                      Re: Create an istream from an fd? Nobody <nobody@nowhere.com> - 2011-08-30 04:40 +0100
                        Re: Create an istream from an fd? Ian Collins <ian-news@hotmail.com> - 2011-08-30 15:51 +1200
                          Re: Create an istream from an fd? Nobody <nobody@nowhere.com> - 2011-08-31 00:03 +0100
                            Re: Create an istream from an fd? Ian Collins <ian-news@hotmail.com> - 2011-08-31 11:55 +1200
                              Re: Create an istream from an fd? Nobody <nobody@nowhere.com> - 2011-09-02 00:50 +0100
              Re: Create an istream from an fd? Ian Collins <ian-news@hotmail.com> - 2011-08-28 16:04 +1200
    Re: Create an istream from an fd? Nobody <nobody@nowhere.com> - 2011-08-27 02:40 +0100

Page 2 of 2 — ← Prev page 1 [2]


#9519

FromNobody <nobody@nowhere.com>
Date2011-08-31 00:03 +0100
Message-ID<pan.2011.08.30.23.03.13.88000@nowhere.com>
In reply to#9459
On Tue, 30 Aug 2011 15:51:58 +1200, Ian Collins wrote:

> Descriptors are used where the 'file' isn't a regular file (or in the 
> case of popen, a pipe).  A FILE* isn't much use for a socket or a door 
> for instance.

I'm unfamiliar with "doors", but FILE* is perfectly useful for stream
(e.g. TCP) sockets. It's not useful for datagram (e.g. UDP) sockets, or if
you need to use send/sendto/sendmsg in place of write() (likewise for
reading).

[toc] | [prev] | [next] | [standalone]


#9525

FromIan Collins <ian-news@hotmail.com>
Date2011-08-31 11:55 +1200
Message-ID<9c5birF5dgU3@mid.individual.net>
In reply to#9519
On 08/31/11 11:03 AM, Nobody wrote:
> On Tue, 30 Aug 2011 15:51:58 +1200, Ian Collins wrote:
>
>> Descriptors are used where the 'file' isn't a regular file (or in the
>> case of popen, a pipe).  A FILE* isn't much use for a socket or a door
>> for instance.
>
> I'm unfamiliar with "doors",

http://en.wikipedia.org/wiki/Doors_%28computing%29

> but FILE* is perfectly useful for stream
> (e.g. TCP) sockets. It's not useful for datagram (e.g. UDP) sockets, or if
> you need to use send/sendto/sendmsg in place of write() (likewise for
> reading).

Yes, but going back the the original point, if a file descriptor has to 
be be converted to a FILE* by non-standard means, why not just provide a 
non-standard istream constructor that uses a file descriptor?  There's 
little point going though two conversions.

-- 
Ian Collins

[toc] | [prev] | [next] | [standalone]


#9635

FromNobody <nobody@nowhere.com>
Date2011-09-02 00:50 +0100
Message-ID<pan.2011.09.01.23.50.08.62000@nowhere.com>
In reply to#9525
On Wed, 31 Aug 2011 11:55:07 +1200, Ian Collins wrote:

> Yes, but going back the the original point, if a file descriptor has to 
> be be converted to a FILE* by non-standard means, why not just provide a 
> non-standard istream constructor that uses a file descriptor?  There's 
> little point going though two conversions.

The FILE* may have been obtained from an external library, or a FILE*
may be required by an external library.

Creating a streambuf atop a descriptor which is also used for a FILE*
means that you now have to keep both sets of buffers in sync.

[toc] | [prev] | [next] | [standalone]


#9389

FromIan Collins <ian-news@hotmail.com>
Date2011-08-28 16:04 +1200
Message-ID<9btt20FopsU7@mid.individual.net>
In reply to#9383
On 08/28/11 11:35 AM, James Kanze wrote:
> On Aug 27, 11:52 pm, Ian Collins<ian-n...@hotmail.com>  wrote:
>> On 08/27/11 12:46 PM, Alf P. Steinbach wrote:
>
>>> On 27.08.2011 01:30, Ian Collins wrote:
>>>> On 08/27/11 11:26 AM, Alf P. Steinbach wrote:
>>>>> On 26.08.2011 17:54, Noah Roberts wrote:
>>>>>> Is there a straight forward of creating an istream out of a file
>>>>>> descriptor? If there is I'd like to use it before going off and
>>>>>> making such a thing.
>
>>>>> Compiler-specific.
>
>>>> Compiler, or platform?
>
>>> Well, to be precise, it's specific to the standard library
>>> implementation. But usually one does not replace the one bundled with
>>> the compiler. So then it's compiler-specific.
>
>> How so?  There aren't any istream constructors or other members that
>> work with file descriptors.  I guess there could be library extensions,
>> but they are part of the "standard" library, are they?
>
>> My point was the notion of a "file descriptor" is platform specific, so
>> any streambuf derivative that uses one would also be platform specific.
>
> It's largely a quality of implementation issue.  As you say,
> there is no portable "file descriptor" type, so the standard
> doesn't provide a constructor for filebuf which takes one.  The
> implementor is left with three choices:
>
>   -- add the necessary constructor, as an extention (provided
>      that this doesn't cause ambiguities with an existing
>      constructor),
>
>   -- offer an additional stream type whose streambuf can be
>      constructed from a file descriptor, or
>
>   -- just ignore the issue.
>
>  From a QoI point of view, the first is preferrable, the second
> is fairly acceptable, and the last is very bad.  From a QoI
> point of view: all are fine according to the standard.

The compilers I use do the first approach, but do it in subtly different 
ways (such as who is responsible for closing the file?).  So I always 
use my own streambuf class.  A specialised streambuf has the further 
advantage of easy customisation for file like entities that aren't 
regular files.

-- 
Ian Collins

[toc] | [prev] | [next] | [standalone]


#9358

FromNobody <nobody@nowhere.com>
Date2011-08-27 02:40 +0100
Message-ID<pan.2011.08.27.01.40.19.93000@nowhere.com>
In reply to#9345
On Fri, 26 Aug 2011 08:54:29 -0700, Noah Roberts wrote:

> Is there a straight forward of creating an istream out of a file
> descriptor?  If there is I'd like to use it before going off and
> making such a thing.

There is no streambuf constructor which takes a descriptor (or a FILE* for
that matter).

This article:

	http://drdobbs.com/184401305

covers creating a streambuf atop a FILE*; you could use that in
conjunction with fdopen(). This has the advantage of leaving the buffering
to the stdio implementation.

[toc] | [prev] | [standalone]


Page 2 of 2 — ← Prev page 1 [2]

Back to top | Article view | comp.lang.c++


csiph-web