|
Boost Users : |
From: Tomasz Noiñski (noix_at_[hidden])
Date: 2007-07-30 09:56:25
Hi,
I'm trying to use boost::iostreams for a project I'm writing and I have
a problem:
It seems that the destructor of
boost::iostreams::stream<boost::iostreams::file_descriptor_source> closes
the file descriptor.
I really need to be able to close this file descriptor manually and I
can't find any way to do it.
Note that file_descriptor_source has a constructor parameter specifying if
the descriptor should be closed in file_descriptor_source destructor or
not. It perfectly works - it's boost::iostreams::stream destructor that
forces closing the description, not file_descriptor_source destructor.
A short code illustrating this problem (for Linux):
--- 8< ---
#include <iostream>
#include <boost/iostreams/device/file_descriptor.hpp>
#include <boost/iostreams/stream.hpp>
#include <cstring>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <errno.h>
using namespace std;
using namespace boost::iostreams;
int main() {
int fd = open("/etc/fstab", O_RDONLY);
clog << "fd=" << fd << endl;
{
file_descriptor_source source(fd, false);
stream<file_descriptor_source> strm(source);
string s;
strm >> s;
clog << "first line: " << s << endl;
}
int closeRet = close(fd);
int closeErrno = errno;
clog << "closing result: " << closeRet << ", "
<< strerror(closeErrno) << endl;
}
--- 8< ---
The behaviour I would expect is the close() at the end succeeding.
However, it returns -1 with errno=EBADF.
Is this the expected behaviour or a bug?
TIA,
Noix
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net