Botan 3.13.0
Crypto and TLS for C&
fd_unix.cpp
Go to the documentation of this file.
1/*
2* Pipe I/O for Unix
3* (C) 1999-2007 Jack Lloyd
4*
5* Botan is released under the Simplified BSD License (see license.txt)
6*/
7
8#include <botan/pipe.h>
9
10#include <botan/exceptn.h>
11#include <cerrno>
12#include <unistd.h>
13
14namespace Botan {
15
16/*
17* Write data from a pipe into a Unix fd
18*/
19int operator<<(int fd, Pipe& pipe) {
21 while(pipe.remaining() > 0) {
22 size_t got = pipe.read(buffer.data(), buffer.size());
23 size_t position = 0;
24 while(got > 0) {
25 const ssize_t ret = ::write(fd, &buffer[position], got);
26 if(ret < 0) {
27 if(errno == EINTR) {
28 continue;
29 }
30 throw Stream_IO_Error("Pipe output operator (unixfd) has failed");
31 }
32
33 position += static_cast<size_t>(ret);
34 got -= static_cast<size_t>(ret);
35 }
36 }
37 return fd;
38}
39
40/*
41* Read data from a Unix fd into a pipe
42*/
43int operator>>(int fd, Pipe& pipe) {
45 while(true) {
46 const ssize_t ret = ::read(fd, buffer.data(), buffer.size());
47 if(ret < 0) {
48 if(errno == EINTR) {
49 continue;
50 }
51 throw Stream_IO_Error("Pipe input operator (unixfd) has failed");
52 } else if(ret == 0) {
53 break;
54 }
55 pipe.write(buffer.data(), static_cast<size_t>(ret));
56 }
57 return fd;
58}
59
60} // namespace Botan
size_t read(uint8_t output[], size_t length) override
Definition pipe_rw.cpp:84
void write(const uint8_t in[], size_t length)
Definition pipe_rw.cpp:42
size_t remaining(message_id msg=DEFAULT_MESSAGE) const
Definition pipe_rw.cpp:129
std::ostream & operator<<(std::ostream &out, const OID &oid)
Definition asn1_oid.cpp:302
int operator>>(int fd, Pipe &pipe)
Definition fd_unix.cpp:43
std::vector< T, secure_allocator< T > > secure_vector
Definition secmem.h:128
constexpr size_t DefaultBufferSize
Definition types.h:150