Apache Mesos
io.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 __PROCESS_IO_HPP__
14 #define __PROCESS_IO_HPP__
15 
16 #include <cstring> // For size_t.
17 #include <string>
18 
19 #include <process/future.hpp>
20 
21 #include <stout/nothing.hpp>
22 #ifdef __WINDOWS__
23 #include <stout/windows.hpp>
24 #endif // __WINDOWS__
25 
26 namespace process {
27 namespace io {
28 
29 #ifndef ENABLE_LIBWINIO
30 
35 const short READ = 0x01;
36 
40 const short WRITE = 0x02;
41 #endif // ENABLE_LIBWINIO
42 
48 const size_t BUFFERED_READ_SIZE = 16*4096;
49 
62 
63 
73 
74 
75 #ifndef ENABLE_LIBWINIO
76 
83 // TODO(benh): Add a version which takes multiple file descriptors.
84 Future<short> poll(int_fd fd, short events);
85 #endif // ENABLE_LIBWINIO
86 
87 
99 Future<size_t> read(int_fd fd, void* data, size_t size);
100 
101 
114 
115 
129 Future<size_t> write(int_fd fd, const void* data, size_t size);
130 
131 
141 Future<Nothing> write(int_fd fd, const std::string& data);
142 
157  int_fd from,
158  Option<int_fd> to,
159  size_t chunk = 4096,
160  const std::vector<lambda::function<void(const std::string&)>>& hooks = {});
161 
162 } // namespace io {
163 } // namespace process {
164 
165 #endif // __PROCESS_IO_HPP__
const short READ
A possible event while polling.
Definition: io.hpp:35
Try< Bytes > size(const std::string &path, const FollowSymlink follow=FollowSymlink::FOLLOW_SYMLINK)
Definition: stat.hpp:121
const size_t BUFFERED_READ_SIZE
Buffered read chunk size.
Definition: io.hpp:48
Definition: check.hpp:33
Try< Nothing > prepare_async(int_fd fd)
Prepares a file descriptor to be ready for asynchronous IO.
Future< short > poll(int_fd fd, short events)
Returns the events (a subset of the events specified) that can be performed on the specified file des...
Future< Nothing > redirect(int_fd from, Option< int_fd > to, size_t chunk=4096, const std::vector< lambda::function< void(const std::string &)>> &hooks={})
Redirect output from the &#39;from&#39; file descriptor to the &#39;to&#39; file descriptor (or /dev/null if &#39;to&#39; is ...
Future< size_t > write(int_fd fd, const void *data, size_t size)
Performs a single non-blocking write by polling on the specified file descriptor until data can be be...
const short WRITE
A possible event while polling.
Definition: io.hpp:40
Definition: executor.hpp:48
Try< bool > is_async(int_fd fd)
Checks if io::prepare_async has been called on the file descriptor.
Future< size_t > read(int_fd fd, void *data, size_t size)
Performs a single non-blocking read by polling on the specified file descriptor until any data can be...
int int_fd
Definition: int_fd.hpp:35
Definition: future.hpp:58