Botan 3.4.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 <unistd.h>
12
13namespace Botan {
14
15/*
16* Write data from a pipe into a Unix fd
17*/
18int operator<<(int fd, Pipe& pipe) {
20 while(pipe.remaining()) {
21 size_t got = pipe.read(buffer.data(), buffer.size());
22 size_t position = 0;
23 while(got) {
24 ssize_t ret = ::write(fd, &buffer[position], got);
25 if(ret < 0) {
26 throw Stream_IO_Error("Pipe output operator (unixfd) has failed");
27 }
28
29 position += static_cast<size_t>(ret);
30 got -= static_cast<size_t>(ret);
31 }
32 }
33 return fd;
34}
35
36/*
37* Read data from a Unix fd into a pipe
38*/
39int operator>>(int fd, Pipe& pipe) {
41 while(true) {
42 ssize_t ret = ::read(fd, buffer.data(), buffer.size());
43 if(ret < 0) {
44 throw Stream_IO_Error("Pipe input operator (unixfd) has failed");
45 } else if(ret == 0) {
46 break;
47 }
48 pipe.write(buffer.data(), static_cast<size_t>(ret));
49 }
50 return fd;
51}
52
53} // namespace Botan
size_t read(uint8_t output[], size_t length) override
Definition pipe_rw.cpp:79
void write(const uint8_t in[], size_t length)
Definition pipe_rw.cpp:37
size_t remaining(message_id msg=DEFAULT_MESSAGE) const
Definition pipe_rw.cpp:124
#define BOTAN_DEFAULT_BUFFER_SIZE
Definition build.h:391
std::ostream & operator<<(std::ostream &out, const OID &oid)
Definition asn1_oid.cpp:140
int operator>>(int fd, Pipe &pipe)
Definition fd_unix.cpp:39
std::vector< T, secure_allocator< T > > secure_vector
Definition secmem.h:61