MCPcopy Create free account
hub / github.com/catboost/catboost / Pipe

Method Pipe

util/system/pipe.cpp:34–65  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

32}
33
34void TPipeHandle::Pipe(TPipeHandle& reader, TPipeHandle& writer, EOpenMode mode) {
35 PIPEHANDLE fds[2];
36#ifdef _win_
37 int r = SocketPair(fds, false /* non-overlapped */, mode & CloseOnExec /* cloexec */);
38#elif defined(_linux_)
39 int r = pipe2(fds, mode & CloseOnExec ? O_CLOEXEC : 0);
40#else
41 int r = pipe(fds);
42#endif
43 if (r < 0) {
44 ythrow TFileError() << "failed to create a pipe";
45 }
46
47#if !defined(_win_) && !defined(_linux_)
48 // Non-atomic wrt exec
49 if (mode & CloseOnExec) {
50 for (int i = 0; i < 2; ++i) {
51 int flags = fcntl(fds[i], F_GETFD, 0);
52 if (flags < 0) {
53 ythrow TFileError() << "failed to get flags";
54 }
55 int r = fcntl(fds[i], F_SETFD, flags | FD_CLOEXEC);
56 if (r < 0) {
57 ythrow TFileError() << "failed to set flags";
58 }
59 }
60 }
61#endif
62
63 TPipeHandle(fds[0]).Swap(reader);
64 TPipeHandle(fds[1]).Swap(writer);
65}
66
67class TPipe::TImpl: public TAtomicRefCount<TImpl> {
68public:

Callers

nothing calls this directly

Calls 4

TPipeHandleClass · 0.85
SocketPairFunction · 0.50
SwapMethod · 0.45
GetHandleMethod · 0.45

Tested by

no test coverage detected