3
* (C) 1999-2007 Jack Lloyd
5
* Botan is released under the Simplified BSD License (see license.txt)
8
#include <botan/pipe.h>
9
#include <botan/exceptn.h>
15
* Write data from a pipe into a Unix fd
17
int operator<<(int fd, Pipe& pipe)
19
secure_vector<uint8_t> buffer(DEFAULT_BUFFERSIZE);
20
while(pipe.remaining())
22
size_t got = pipe.read(buffer.data(), buffer.size());
26
ssize_t ret = ::write(fd, &buffer[position], got);
28
throw Stream_IO_Error("Pipe output operator (unixfd) has failed");
30
position += static_cast<size_t>(ret);
31
got -= static_cast<size_t>(ret);
38
* Read data from a Unix fd into a pipe
40
int operator>>(int fd, Pipe& pipe)
42
secure_vector<uint8_t> buffer(DEFAULT_BUFFERSIZE);
45
ssize_t ret = ::read(fd, buffer.data(), buffer.size());
47
throw Stream_IO_Error("Pipe input operator (unixfd) has failed");
50
pipe.write(buffer.data(), static_cast<size_t>(ret));