Kinetic C/C++ Client
 All Classes Functions Variables Pages
nonblocking_packet_receiver.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_PACKET_RECEIVER_H_
22 #define KINETIC_CPP_CLIENT_NONBLOCKING_PACKET_RECEIVER_H_
23 
24 #include <sys/select.h>
25 #include <cstdint>
26 
27 #include <queue>
28 #include <unordered_map>
29 #include <glog/logging.h>
30 
31 #include "kinetic/nonblocking_packet_service_interface.h"
32 #include "kinetic/connection_options.h"
33 #include "kinetic/hmac_provider.h"
34 #include "kinetic_client.pb.h"
35 #include "nonblocking_packet.h"
36 #include "socket_wrapper_interface.h"
37 
38 namespace kinetic {
39 
40 using com::seagate::kinetic::client::proto::Message;
41 using com::seagate::kinetic::client::proto::Command;
42 using com::seagate::kinetic::client::proto::Command_Status_StatusCode;
43 
44 using std::string;
45 using std::unique_ptr;
46 using std::deque;
47 using std::pair;
48 using std::unordered_map;
49 
50 enum NonblockingPacketServiceStatus {
51  kIdle, // nothing to do
52  kIoWait, // waiting for I/O to become possible
53  kError // irrecoverable error
54 };
55 
57  public:
58  virtual ~NonblockingReceiverInterface() {}
59  // The HandlerKey must be unique across the lifespan of the receiver.
60  virtual bool Enqueue(shared_ptr<HandlerInterface> handler, google::int64 sequence,
61  HandlerKey handler_key) = 0;
62  virtual NonblockingPacketServiceStatus Receive() = 0;
63  virtual int64_t connection_id() = 0;
64  virtual bool Remove(HandlerKey key) = 0;
65 };
66 
68  public:
69  explicit NonblockingReceiver(shared_ptr<SocketWrapperInterface> socket_wrapper,
70  HmacProvider hmac_provider, const ConnectionOptions &connection_options);
72  bool Enqueue(shared_ptr<HandlerInterface> handler, google::int64 sequence,
73  HandlerKey handler_key);
74  NonblockingPacketServiceStatus Receive();
75  int64_t connection_id();
76  bool Remove(HandlerKey key);
77 
78  private:
79  void CallAllErrorHandlers(KineticStatus error);
80 
81  shared_ptr<SocketWrapperInterface> socket_wrapper_;
82  HmacProvider hmac_provider_;
83  ConnectionOptions connection_options_;
84  NonblockingPacketReader *nonblocking_response_;
85  int64_t connection_id_;
86  shared_ptr<HandlerInterface> handler_;
87  Message message_;
88  Command command_;
89  unique_ptr<const string> value_;
90  unordered_map<google::protobuf::int64, pair<shared_ptr<HandlerInterface>, HandlerKey>> map_;
91  // handler_key is separate from message sequence so that we don't tie handler identification
92  // semantics to the message sequencing, since message sequence semantics are outside of our
93  // control.
94  unordered_map<HandlerKey, google::protobuf::int64> handler_to_message_seq_map_;
95  DISALLOW_COPY_AND_ASSIGN(NonblockingReceiver);
96 };
97 
98 } // namespace kinetic
99 
100 #endif // KINETIC_CPP_CLIENT_NONBLOCKING_PACKET_RECEIVER_H_
Wrapper class that handles computing HMACs. The supplied implementation uses openssl, but users can supply an alternate implementation that uses a different library (e. g. one providing specialized HW accelaration)
Definition: hmac_provider.h:33
Indicates whether a Kinetic operation (get, put, security, etc) put succeeded or failed. Unlike Status it provides details like whether the failure resulted from a version or an HMAC error.
Use this struct to pass all connection options to the KineticConnectionFactory.