0.9.8.10
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
PhantomUpdate.cc
Go to the documentation of this file.
1 
22 #include <Common/Compat.h>
23 
24 #include "PhantomUpdate.h"
25 
26 #include <AsyncComm/CommBuf.h>
27 #include <AsyncComm/CommHeader.h>
28 
29 #include <Common/Error.h>
30 
31 using namespace Hypertable;
33 using namespace std;
34 
36  CommHeader header;
37  header.initialize_from_request_header(m_event->header);
38  size_t len = m_range.encoded_length() + 4 + 4;
39  CommBufPtr cbp(new CommBuf(header, len));
40  cbp->append_i32(Error::OK);
41  m_range.encode(cbp->get_data_ptr_address());
42  cbp->append_i32(m_fragment);
43  return m_comm->send_response(m_event->addr, cbp);
44 }
45 
47  return response();
48 }
49 
50 int PhantomUpdate::error(int error, const String &msg) {
51  CommHeader header;
52  header.initialize_from_request_header(m_event->header);
53  CommBufPtr cbp;
54  String message;
55  size_t max_msg_size = std::numeric_limits<int16_t>::max();
56  size_t len = 4 + m_range.encoded_length() + 4;
57 
58  if (msg.length() < max_msg_size) {
60  cbp = make_shared<CommBuf>(header, len);
61  cbp->append_i32(error);
62  cbp->append_str16(msg.c_str());
63  }
64  else {
65  String substr = msg.substr(0, max_msg_size);
67  cbp = make_shared<CommBuf>(header, len);
68  cbp->append_i32(error);
69  cbp->append_str16(substr.c_str());
70  }
71  m_range.encode(cbp->get_data_ptr_address());
72  cbp->append_i32(m_fragment);
73 
74  return m_comm->send_response(m_event->addr, cbp);
75 }
76 
void initialize_from_request_header(CommHeader &req_header)
Initializes header from req_header.
Definition: CommHeader.h:128
std::string String
A String is simply a typedef to std::string.
Definition: String.h:44
STL namespace.
size_t encoded_length_str16(const char *str)
Computes the encoded length of a string16 encoding.
std::shared_ptr< CommBuf > CommBufPtr
Smart pointer to CommBuf.
Definition: CommBuf.h:305
Compatibility Macros for C/C++.
virtual int response_ok()
Sends a a simple success response back to the client which is just the 4-byte error code Error::OK...
Hypertable definitions
Header for messages transmitted via AsyncComm.
Definition: CommHeader.h:40
virtual int error(int error, const String &msg)
Sends a standard error response back to the client.
Declarations for CommBuf.
Message buffer for holding data to be transmitted over a network.
Definition: CommBuf.h:79
Declarations for CommHeader.
Error codes, Exception handling, error logging.