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 
34 const short READ = 0x01;
35 
36 #ifndef ENABLE_LIBWINIO
37 
40 const short WRITE = 0x02;
41 #endif // ENABLE_LIBWINIO
42 
48 const size_t BUFFERED_READ_SIZE = 16*4096;
49 
62 
63 
73 
74 
85 // TODO(benh): Add a version which takes multiple file descriptors.
86 Future<short> poll(int_fd fd, short events);
87 
88 
106 Future<size_t> read(int_fd fd, void* data, size_t size);
107 
108 
121 
122 
136 Future<size_t> write(int_fd fd, const void* data, size_t size);
137 
138 
148 Future<Nothing> write(int_fd fd, const std::string& data);
149 
164  int_fd from,
165  Option<int_fd> to,
166  size_t chunk = 4096,
167  const std::vector<lambda::function<void(const std::string&)>>& hooks = {});
168 
169 } // namespace io {
170 } // namespace process {
171 
172 #endif // __PROCESS_IO_HPP__
const short READ
A possible event while polling.
Definition: io.hpp:34
Try< Bytes > size(const std::string &path, const FollowSymlink follow=FollowSymlink::FOLLOW_SYMLINK)
Definition: stat.hpp:130
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