Apache Mesos
write.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_WRITE_HPP__
14 #define __STOUT_OS_WINDOWS_WRITE_HPP__
15 
16 #include <io.h>
17 
18 #include <stout/nothing.hpp>
19 #include <stout/try.hpp>
20 #include <stout/unreachable.hpp>
21 #include <stout/windows.hpp> // For order-dependent networking headers.
22 
23 #include <stout/os/socket.hpp>
24 #include <stout/os/windows/fd.hpp>
25 
26 
27 namespace os {
28 
29 inline ssize_t write(const WindowsFD& fd, const void* data, size_t size)
30 {
31  CHECK_LE(size, INT_MAX);
32 
33  switch (fd.type()) {
34  case WindowsFD::FD_CRT:
35  case WindowsFD::FD_HANDLE: {
36  return ::_write(fd.crt(), data, static_cast<unsigned int>(size));
37  }
38  case WindowsFD::FD_SOCKET: {
39  return ::send(fd, (const char*)data, static_cast<int>(size), 0);
40  }
41  }
42 
43  UNREACHABLE();
44 }
45 
46 } // namespace os {
47 
48 
49 #endif // __STOUT_OS_WINDOWS_WRITE_HPP__
SSIZE_T ssize_t
Definition: windows.hpp:192
Definition: fd.hpp:54
Definition: fd.hpp:53
Type type() const
Definition: fd.hpp:121
Try< Bytes > size(const std::string &path, const FollowSymlink follow=FollowSymlink::FOLLOW_SYMLINK)
Definition: stat.hpp:100
Definition: fd.hpp:47
ssize_t write(const WindowsFD &fd, const void *data, size_t size)
Definition: write.hpp:29
ssize_t send(const os::WindowsFD &fd, const void *buf, size_t len, int flags)
Definition: socket.hpp:136
#define UNREACHABLE()
Definition: unreachable.hpp:22
int crt() const
Definition: fd.hpp:97
Definition: fd.hpp:52