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/int_fd.hpp>
23 #include <stout/os/socket.hpp>
24 
25 namespace os {
26 
27 inline Try<Nothing> cloexec(const int_fd& fd)
28 {
29  return Nothing();
30 }
31 
32 
33 inline Try<Nothing> unsetCloexec(const int_fd& fd)
34 {
35  return Nothing();
36 }
37 
38 
39 inline Try<bool> isCloexec(const int_fd& fd)
40 {
41  return true;
42 }
43 
44 
45 inline Try<Nothing> nonblock(const int_fd& fd)
46 {
47  switch (fd.type()) {
49  /* Do nothing. */
50  return Nothing();
51  }
53  const u_long non_block_mode = 1;
54  u_long mode = non_block_mode;
55 
56  int result = ::ioctlsocket(fd, FIONBIO, &mode);
57  if (result != NO_ERROR) {
58  return WindowsSocketError();
59  }
60  return Nothing();
61  }
62  }
63 
64  UNREACHABLE();
65 }
66 
67 
68 // NOTE: This is not supported on Windows.
69 inline Try<bool> isNonblock(const int_fd& fd)
70 {
71  VLOG(2) << "`os::isNonblock` has been called, but is a stub on Windows";
72  return true;
73 }
74 
75 } // namespace os {
76 
77 #endif // __STOUT_OS_WINDOWS_FCNTL_HPP__
Definition: nothing.hpp:16
Definition: check.hpp:33
Try< bool > isNonblock(int fd)
Definition: fcntl.hpp:87
Definition: error.hpp:123
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
#define UNREACHABLE()
Definition: unreachable.hpp:22
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:168
int int_fd
Definition: int_fd.hpp:35