0.9.8.10
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
ResponseCallback.cc
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2007-2015 Hypertable, Inc.
3  *
4  * This file is part of Hypertable.
5  *
6  * Hypertable is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 3
9  * of the License, or any later version.
10  *
11  * Hypertable is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19  * 02110-1301, USA.
20  */
21 
29 #include <Common/Compat.h>
30 
31 #include "CommBuf.h"
32 #include "CommHeader.h"
33 #include "Protocol.h"
34 #include "ResponseCallback.h"
35 
36 #include <Common/Error.h>
37 
38 #include <limits>
39 
40 using namespace Hypertable;
41 
42 int ResponseCallback::error(int error, const String &msg) {
43  CommHeader header;
45  CommBufPtr cbp;
46  size_t max_msg_size = std::numeric_limits<int16_t>::max();
47  if (msg.length() < max_msg_size)
48  cbp = Protocol::create_error_message(header, error, msg.c_str());
49  else {
50  cbp = Protocol::create_error_message(header, error, msg.substr(0, max_msg_size).c_str());
51  }
52  return m_comm->send_response(m_event->addr, cbp);
53 }
54 
56  CommHeader header;
58  CommBufPtr cbp(new CommBuf(header, 4));
59  cbp->append_i32(Error::OK);
60  return m_comm->send_response(m_event->addr, cbp);
61 }
62 
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
virtual int response_ok()
Sends a a simple success response back to the client which is just the 4-byte error code Error::OK...
static CommBufPtr create_error_message(CommHeader &header, int error, const char *msg)
Creates a standard error message response.
Definition: Protocol.cc:81
Comm * m_comm
Comm pointer.
std::shared_ptr< CommBuf > CommBufPtr
Smart pointer to CommBuf.
Definition: CommBuf.h:305
Compatibility Macros for C/C++.
int send_response(const CommAddress &addr, CommBufPtr &cbuf)
Sends a response message back over a connection.
Definition: Comm.cc:343
Hypertable definitions
Header for messages transmitted via AsyncComm.
Definition: CommHeader.h:40
Declarations for CommBuf.
virtual int error(int error, const String &msg)
Sends a standard error response back to the client.
Declarations for Protocol.
Message buffer for holding data to be transmitted over a network.
Definition: CommBuf.h:79
EventPtr m_event
Smart pointer to event object.
Declarations for CommHeader.
Declarations for ResponseCallback.
Error codes, Exception handling, error logging.