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 // NOTE: Windows does not support the semantics of close-on-exec. Instead, by
32 // default we set all handles to be non-inheritable.
33 #define O_CLOEXEC 0
34 
35 namespace os {
36 
37 inline Try<Nothing> cloexec(const WindowsFD& fd)
38 {
39  return Nothing();
40 }
41 
42 
44 {
45  return Nothing();
46 }
47 
48 
49 inline Try<bool> isCloexec(const WindowsFD& fd)
50 {
51  return true;
52 }
53 
54 
55 inline Try<Nothing> nonblock(const WindowsFD& fd)
56 {
57  switch (fd.type()) {
58  case WindowsFD::FD_CRT:
59  case WindowsFD::FD_HANDLE: {
60  /* Do nothing. */
61  break;
62  }
63  case WindowsFD::FD_SOCKET: {
64  const u_long non_block_mode = 1;
65  u_long mode = non_block_mode;
66 
67  int result = ::ioctlsocket(fd, FIONBIO, &mode);
68  if (result != NO_ERROR) {
69  return WindowsSocketError();
70  }
71  break;
72  }
73  }
74  return Nothing();
75 }
76 
77 
78 // NOTE: This is not supported on Windows.
79 inline Try<bool> isNonblock(const WindowsFD& fd)
80 {
81  VLOG(2) << "`os::isNonblock` has been called, but is a stub on Windows";
82  return true;
83 }
84 
85 } // namespace os {
86 
87 #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: check.hpp:33
Try< bool > isNonblock(int fd)
Definition: fcntl.hpp:87
Definition: error.hpp:120
Try< bool > isCloexec(int fd)
Definition: fcntl.hpp:59
Definition: posix_signalhandler.hpp:23
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