Kinetic C/C++ Client
 All Classes Functions Variables Pages
byte_stream.h
1 /*
2  * kinetic-cpp-client
3  * Copyright (C) 2014 Seagate Technology.
4  *
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU General Public License
7  * as published by the Free Software Foundation; either version 2
8  * of the License, or (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18  *
19  */
20 
21 #ifndef KINETIC_CPP_CLIENT_BYTE_STREAM_H_
22 #define KINETIC_CPP_CLIENT_BYTE_STREAM_H_
23 
24 #include "openssl/ssl.h"
25 
26 #include "common.h"
27 #include "incoming_value.h"
28 #include "outgoing_value.h"
29 
30 namespace kinetic {
31 
33  public:
34  virtual ~ByteStreamInterface() {}
35  virtual bool Read(void *buf, size_t n) = 0;
36  virtual bool Write(const void *buf, size_t n) = 0;
37  virtual IncomingValueInterface *ReadValue(size_t n) = 0;
38  virtual bool WriteValue(const OutgoingValueInterface &value, int* err) = 0;
39 };
40 
42  public:
43  PlainByteStream(int fd, IncomingValueFactoryInterface &value_factory);
44  bool Read(void *buf, size_t n);
45  bool Write(const void *buf, size_t n);
46  IncomingValueInterface *ReadValue(size_t n);
47  bool WriteValue(const OutgoingValueInterface &value, int* err);
48 
49  private:
50  int fd_;
51  IncomingValueFactoryInterface &value_factory_;
52  DISALLOW_COPY_AND_ASSIGN(PlainByteStream);
53 };
54 
56  public:
57  explicit SslByteStream(SSL *ssl);
58  virtual ~SslByteStream();
59  bool Read(void *buf, size_t n);
60  bool Write(const void *buf, size_t n);
61  IncomingValueInterface *ReadValue(size_t n);
62  bool WriteValue(const OutgoingValueInterface &value, int* err);
63 
64  private:
65  SSL *ssl_;
66  DISALLOW_COPY_AND_ASSIGN(SslByteStream);
67 };
68 
69 } // namespace kinetic
70 
71 #endif // KINETIC_CPP_CLIENT_BYTE_STREAM_H_