Commit e648d289 authored by Victor Zverovich's avatar Victor Zverovich

Fix FileDescriptor::pipe.

parent 8214a5ef
...@@ -95,17 +95,25 @@ void FileDescriptor::dup2(int fd, ErrorCode &ec) FMT_NOEXCEPT(true) { ...@@ -95,17 +95,25 @@ void FileDescriptor::dup2(int fd, ErrorCode &ec) FMT_NOEXCEPT(true) {
ec = ErrorCode(errno); ec = ErrorCode(errno);
} }
void FileDescriptor::pipe(FileDescriptor &read, FileDescriptor &write) { void FileDescriptor::pipe(FileDescriptor &read_fd, FileDescriptor &write_fd) {
// Close the descriptors first to make sure that assignments don't throw // Close the descriptors first to make sure that assignments don't throw
// and there are no leaks. // and there are no leaks.
read.close(); read_fd.close();
write.close(); write_fd.close();
int fds[2] = {}; int fds[2] = {};
if (::pipe(fds) != 0) #ifdef _WIN32
// Make the default pipe capacity same as on Linux 2.6.11+.
enum { DEFAULT_CAPACITY = 65536 };
int result = _pipe(fds, DEFAULT_CAPACITY, _O_BINARY);
#else
int result = ::pipe(fds);
#endif
if (result != 0)
fmt::ThrowSystemError(errno, "cannot create pipe"); fmt::ThrowSystemError(errno, "cannot create pipe");
// The following assignments don't throw because read and write are closed. // The following assignments don't throw because read_fd and write_fd
read = FileDescriptor(fds[0]); // are closed.
write = FileDescriptor(fds[1]); read_fd = FileDescriptor(fds[0]);
write_fd = FileDescriptor(fds[1]);
} }
OutputRedirector::OutputRedirector(FILE *file) : file_(file) { OutputRedirector::OutputRedirector(FILE *file) : file_(file) {
......
...@@ -204,7 +204,7 @@ class FileDescriptor { ...@@ -204,7 +204,7 @@ class FileDescriptor {
// Creates a pipe setting up read and write file descriptors for reading // Creates a pipe setting up read and write file descriptors for reading
// and writing respecively. Throws fmt::SystemError on error. // and writing respecively. Throws fmt::SystemError on error.
static void pipe(FileDescriptor &read, FileDescriptor &write); static void pipe(FileDescriptor &read_fd, FileDescriptor &write_fd);
}; };
#if !FMT_USE_RVALUE_REFERENCES #if !FMT_USE_RVALUE_REFERENCES
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment