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 
39 const short WRITE = 0x02;
40 
46 const size_t BUFFERED_READ_SIZE = 16*4096;
47 
55 // TODO(benh): Add a version which takes multiple file descriptors.
56 Future<short> poll(int_fd fd, short events);
57 
58 
69 Future<size_t> read(int_fd fd, void* data, size_t size);
70 
71 
84 
85 
98 Future<size_t> write(int_fd fd, const void* data, size_t size);
99 
100 
110 Future<Nothing> write(int_fd fd, const std::string& data);
111 
126  int_fd from,
127  Option<int_fd> to,
128  size_t chunk = 4096,
129  const std::vector<lambda::function<void(const std::string&)>>& hooks = {});
130 
131 } // namespace io {
132 } // namespace process {
133 
134 #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:100
const size_t BUFFERED_READ_SIZE
Buffered read chunk size.
Definition: io.hpp:46
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:39
Result< Process > process(pid_t pid)
Definition: freebsd.hpp:30
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:57