MCPcopy Create free account
hub / github.com/apache/arrow / CreatePipe

Function CreatePipe

cpp/src/arrow/util/io_util.cc:1174–1213  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1172}
1173
1174Result<Pipe> CreatePipe() {
1175 bool ok;
1176 int fds[2];
1177 Pipe pipe;
1178
1179#if defined(_WIN32)
1180 ok = _pipe(fds, 4096, _O_BINARY) >= 0;
1181 if (ok) {
1182 pipe = {FileDescriptor(fds[0]), FileDescriptor(fds[1])};
1183 }
1184#elif defined(__linux__) && defined(__GLIBC__)
1185 // On Unix, we don't want the file descriptors to survive after an exec() call
1186 ok = pipe2(fds, O_CLOEXEC) >= 0;
1187 if (ok) {
1188 pipe = {FileDescriptor(fds[0]), FileDescriptor(fds[1])};
1189 }
1190#else
1191 auto set_cloexec = [](int fd) -> bool {
1192 int flags = fcntl(fd, F_GETFD);
1193 if (flags >= 0) {
1194 flags = fcntl(fd, F_SETFD, flags | FD_CLOEXEC);
1195 }
1196 return flags >= 0;
1197 };
1198
1199 ok = ::pipe(fds) >= 0;
1200 if (ok) {
1201 pipe = {FileDescriptor(fds[0]), FileDescriptor(fds[1])};
1202 ok &= set_cloexec(fds[0]);
1203 if (ok) {
1204 ok &= set_cloexec(fds[1]);
1205 }
1206 }
1207#endif
1208 if (!ok) {
1209 return IOErrorFromErrno(errno, "Error creating pipe");
1210 }
1211
1212 return pipe;
1213}
1214
1215Status SetPipeFileDescriptorNonBlocking(int fd) {
1216#if defined(_WIN32)

Callers 6

MakePipeMethod · 0.85
BackgroundReaderMethod · 0.85
SetupPipeWriterFunction · 0.85
TEST_FFunction · 0.85
InitMethod · 0.85
ChildAfterForkMethod · 0.85

Calls 2

FileDescriptorFunction · 0.85
IOErrorFromErrnoFunction · 0.85

Tested by 2

MakePipeMethod · 0.68
TEST_FFunction · 0.68