Apache Mesos
read.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_READ_HPP__
14 #define __STOUT_OS_WINDOWS_READ_HPP__
15 
16 #include <io.h>
17 
18 #include <stout/result.hpp>
19 #include <stout/unreachable.hpp>
20 #include <stout/windows.hpp> // For order-dependent networking headers.
21 
22 #include <stout/os/socket.hpp>
23 #include <stout/os/windows/fd.hpp>
24 
25 
26 namespace os {
27 
28 inline ssize_t read(const WindowsFD& fd, void* data, size_t size)
29 {
30  CHECK_LE(size, UINT_MAX);
31 
32  switch (fd.type()) {
33  case WindowsFD::FD_CRT:
34  case WindowsFD::FD_HANDLE: {
35  return ::_read(fd.crt(), data, static_cast<unsigned int>(size));
36  }
37  case WindowsFD::FD_SOCKET: {
38  return ::recv(fd, (char*)data, static_cast<unsigned int>(size), 0);
39  }
40  }
41 
42  UNREACHABLE();
43 }
44 
45 } // namespace os {
46 
47 #endif // __STOUT_OS_WINDOWS_READ_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 recv(const os::WindowsFD &fd, void *buf, size_t len, int flags)
Definition: socket.hpp:145
#define UNREACHABLE()
Definition: unreachable.hpp:22
Result< std::string > read(int_fd fd, size_t size)
Definition: read.hpp:50
int crt() const
Definition: fd.hpp:97
Definition: fd.hpp:52