Apache Mesos
fcntl.hpp
Go to the documentation of this file.
1 // Licensed under the Apache License, Version 2.0 (the "License");
2 // you may not use this file except in compliance with the License.
3 // You may obtain a copy of the License at
4 //
5 // http://www.apache.org/licenses/LICENSE-2.0
6 //
7 // Unless required by applicable law or agreed to in writing, software
8 // distributed under the License is distributed on an "AS IS" BASIS,
9 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10 // See the License for the specific language governing permissions and
11 // limitations under the License.
12 
13 #ifndef __STOUT_OS_WINDOWS_FCNTL_HPP__
14 #define __STOUT_OS_WINDOWS_FCNTL_HPP__
15 
16 #include <glog/logging.h>
17 
18 #include <stout/nothing.hpp>
19 #include <stout/try.hpp>
20 #include <stout/windows.hpp>
21 
22 #include <stout/os/socket.hpp>
23 #include <stout/os/windows/fd.hpp>
24 
25 #define O_RDONLY _O_RDONLY
26 #define O_WRONLY _O_WRONLY
27 #define O_RDWR _O_RDWR
28 #define O_CREAT _O_CREAT
29 #define O_TRUNC _O_TRUNC
30 #define O_APPEND _O_APPEND
31 #define O_CLOEXEC _O_NOINHERIT
32 
33 namespace os {
34 
35 // NOTE: This is not supported on Windows.
36 inline Try<Nothing> cloexec(const WindowsFD& fd)
37 {
38  VLOG(2) << "`os::cloexec` has been called, but is a no-op on Windows";
39  return Nothing();
40 }
41 
42 
43 // NOTE: This is not supported on Windows.
45 {
46  VLOG(2) << "`os::unsetCloexec` has been called, but is a no-op on Windows";
47  return Nothing();
48 }
49 
50 
51 inline Try<bool> isCloexec(const WindowsFD& fd)
52 {
53  VLOG(2) << "`os::isCloexec` has been called, but is a stub on Windows";
54  return true;
55 }
56 
57 
58 inline Try<Nothing> nonblock(const WindowsFD& fd)
59 {
60  switch (fd.type()) {
61  case WindowsFD::FD_CRT:
62  case WindowsFD::FD_HANDLE: {
63  /* Do nothing. */
64  break;
65  }
66  case WindowsFD::FD_SOCKET: {
67  const u_long non_block_mode = 1;
68  u_long mode = non_block_mode;
69 
70  int result = ioctlsocket(fd, FIONBIO, &mode);
71  if (result != NO_ERROR) {
72  return WindowsSocketError();
73  }
74  break;
75  }
76  }
77  return Nothing();
78 }
79 
80 
81 // NOTE: This is not supported on Windows.
82 inline Try<bool> isNonblock(const WindowsFD& fd)
83 {
84  VLOG(2) << "`os::isNonblock` has been called, but is a stub on Windows";
85  return true;
86 }
87 
88 } // namespace os {
89 
90 #endif // __STOUT_OS_WINDOWS_FCNTL_HPP__
Definition: fd.hpp:54
Definition: nothing.hpp:16
Definition: fd.hpp:53
Type type() const
Definition: fd.hpp:121
Definition: fd.hpp:47
Definition: try.hpp:34
Try< bool > isNonblock(int fd)
Definition: fcntl.hpp:87
Definition: error.hpp:120
Try< bool > isCloexec(int fd)
Definition: fcntl.hpp:59
Try< Nothing > nonblock(int fd)
Definition: fcntl.hpp:71
Try< Nothing > cloexec(int fd)
Definition: fcntl.hpp:27
Try< Nothing > unsetCloexec(int fd)
Definition: fcntl.hpp:43
Try< mode_t > mode(const std::string &path, const FollowSymlink follow=FollowSymlink::FOLLOW_SYMLINK)
Definition: stat.hpp:126
Definition: fd.hpp:52