Kinetic C/C++ Client
 All Classes Functions Variables Pages
nonblocking_string.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_NONBLOCKING_STRING_H_
22 #define KINETIC_CPP_CLIENT_NONBLOCKING_STRING_H_
23 
24 #include <string>
25 #include <memory>
26 
27 #include "kinetic/common.h"
28 #include "socket_wrapper_interface.h"
29 
30 namespace kinetic {
31 
32 using std::shared_ptr;
33 using std::unique_ptr;
34 using std::string;
35 
36 enum NonblockingStringStatus {
37  kInProgress,
38  kDone,
39  kFailed
40 };
41 
43  public:
44  NonblockingStringReader(shared_ptr<SocketWrapperInterface> socket_wrapper, size_t size, unique_ptr<const string> &s);
46  NonblockingStringStatus Read();
47 
48  private:
49  shared_ptr<SocketWrapperInterface> socket_wrapper_;
50  const size_t size_;
51  unique_ptr<const string> &s_;
52  char *const buf_;
53  size_t bytes_read_;
54  DISALLOW_COPY_AND_ASSIGN(NonblockingStringReader);
55 };
56 
58  public:
59  NonblockingStringWriter(shared_ptr<SocketWrapperInterface> socket_wrapper, const shared_ptr<const string> s);
60  NonblockingStringStatus Write();
61 
62  private:
63  shared_ptr<SocketWrapperInterface> socket_wrapper_;
64  const shared_ptr<const string> s_;
65  size_t bytes_written_;
66  DISALLOW_COPY_AND_ASSIGN(NonblockingStringWriter);
67 };
68 
69 } // namespace kinetic
70 
71 #endif // KINETIC_CPP_CLIENT_NONBLOCKING_STRING_H_