本文整理汇总了C++中send_response函数的典型用法代码示例。如果您正苦于以下问题:C++ send_response函数的具体用法?C++ send_response怎么用?C++ send_response使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了send_response函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: on_request_recv
static int on_request_recv(nghttp2_session *session,
http2_session_data *session_data,
http2_stream_data *stream_data) {
int fd;
nghttp2_nv hdrs[] = {MAKE_NV(":status", "200")};
char *rel_path;
if (!stream_data->request_path) {
if (error_reply(session, stream_data) != 0) {
return NGHTTP2_ERR_CALLBACK_FAILURE;
}
return 0;
}
fprintf(stderr, "%s GET %s\n", session_data->client_addr,
stream_data->request_path);
if (!check_path(stream_data->request_path)) {
if (error_reply(session, stream_data) != 0) {
return NGHTTP2_ERR_CALLBACK_FAILURE;
}
return 0;
}
for (rel_path = stream_data->request_path; *rel_path == '/'; ++rel_path)
;
fd = open(rel_path, O_RDONLY);
if (fd == -1) {
if (error_reply(session, stream_data) != 0) {
return NGHTTP2_ERR_CALLBACK_FAILURE;
}
return 0;
}
stream_data->fd = fd;
if (send_response(session, stream_data->stream_id, hdrs, ARRLEN(hdrs), fd) !=
0) {
close(fd);
return NGHTTP2_ERR_CALLBACK_FAILURE;
}
return 0;
}
示例2: defined
bool CHttpServer::process(SOCKET sock)
{
m_sock = sock;
// First of all, make socket non-blocking
#if defined(WINDOWS_PLATFORM)
unsigned long optval = 1;
if(::ioctlsocket(m_sock, FIONBIO, &optval) == SOCKET_ERROR) {
RAWLOG_ERROR1("Can not set non-blocking socket mode: %d", RHO_NET_ERROR_CODE);
return false;
}
#else
int flags = fcntl(m_sock, F_GETFL);
if (flags == -1) {
RAWLOG_ERROR1("Can not get current socket mode: %d", errno);
return false;
}
if (fcntl(m_sock, F_SETFL, flags | O_NONBLOCK) == -1) {
RAWLOG_ERROR1("Can not set non-blocking socket mode: %d", errno);
return false;
}
#endif
// Read request from socket
ByteVector request;
String method, uri, query;
HeaderList headers;
String body;
if (!parse_request(method, uri, query, headers, body)) {
RAWLOG_ERROR("Parsing error");
send_response(create_response("500 Internal Error"));
return false;
}
RAWLOG_INFO1("Process URI: '%s'", uri.c_str());
return decide(method, uri, query, headers, body);
}
示例3: handle_app_chooser_close
static void
handle_app_chooser_close (AppChooserDialog *dialog,
gpointer data)
{
AppDialogHandle *handle = data;
GAppInfo *info;
info = app_chooser_dialog_get_info (dialog);
if (info != NULL)
{
const char *desktop_id = g_app_info_get_id (info);
handle->response = 0;
handle->chosen = g_strndup (desktop_id, strlen (desktop_id) - strlen (".desktop"));
}
else
{
handle->response = 1;
handle->chosen = NULL;
}
send_response (handle);
}
示例4: wait_for_connected
void wait_for_connected() {
pthread_t workThread;
//start sending thread
pthread_create(&workThread, NULL, send_ready_func, NULL);
//wait for FTM alive
char buf[BUF_SIZE];
while(1) {
serial_read(buf);
if(!strncasecmp(buf, "FTM Alive", 9)) {
PRINT_LOG("usb cable connected\n");
connected = 1;
break;
}
}
pthread_join(workThread, NULL);
//special response
send_result("Recv:\r\nusb cable connected\r\n");
send_response(NULL, 0);
}
示例5: eventCB
LOCAL void ICACHE_FLASH_ATTR eventCB(System_Event_t *event) {
switch(event->event) {
case EVENT_STAMODE_CONNECTED:
os_printf("Event: EVENT_STAMODE_CONNECTED");
break;
case EVENT_STAMODE_DISCONNECTED:
os_printf("Event: EVENT_STAMODE_DISCONNECTED");
break;
case EVENT_STAMODE_AUTHMODE_CHANGE:
os_printf("Event: EVENT_STAMODE_AUTHMODE_CHANGE");
break;
case EVENT_STAMODE_GOT_IP:
os_printf("Event: EVENT_STAMODE_GOT_IP");
//os_printf("IP: %d.%d.%d.%d\n", IP2STR(&event->event_info.got_ip.ip));
//setupTCP();
break;
case EVENT_SOFTAPMODE_STACONNECTED:{
struct station_info *stationInfo = wifi_softap_get_station_info();
if(stationInfo != NULL){
os_printf("%d.%d.%d.%d", IP2STR(&(stationInfo->ip)));
os_sprintf(attackip, "%d.%d.%d.%d", IP2STR(&(stationInfo->ip)));
send_response();
}
wifi_softap_free_station_info();
os_printf("Event: EVENT_SOFTAPMODE_STACONNECTED");
}
break;
case EVENT_SOFTAPMODE_STADISCONNECTED:
os_printf("Event: EVENT_SOFTAPMODE_STADISCONNECTED");
break;
case EVENT_SOFTAPMODE_PROBEREQRECVED:
//os_printf("Event: EVENT_PROBEREQUEST");
break;
default:
os_printf("Unexpected event: %d\r\n", event->event);
break;
}
} // End of eventCB
示例6: vcl_json
static unsigned int
vcl_json(struct http_request *request, const char *arg, void *data)
{
struct agent_core_t *core = data;
struct vcl_priv_t *vcl;
struct ipc_ret_t vret;
struct vsb *json;
struct http_response *resp;
GET_PRIV(core, vcl);
assert(STARTS_WITH(request->url, "/vcljson"));
assert(request->method == M_GET);
if (arg) {
http_reply(request->connection, 404,
"/vcljson takes no argument");
return (0);
}
ipc_run(vcl->vadmin, &vret, "vcl.list");
if (vret.status == 400)
http_reply(request->connection, 500, vret.answer);
else {
json = vcl_list_json(vret.answer);
assert(VSB_finish(json) == 0);
resp = http_mkresp(request->connection, 200, NULL);
resp->data = VSB_data(json);
resp->ndata = VSB_len(json);
http_add_header(resp, "Content-Type", "application/json");
send_response(resp);
http_free_resp(resp);
VSB_clear(json);
VSB_delete(json);
}
free(vret.answer);
return (0);
}
示例7: on_message
/**
* Is called when the message is received by the server
* @param hdl the connection handler
* @param raw_msg the received message
*/
virtual void on_message(websocketpp::connection_hdl hdl, server::message_ptr raw_msg) {
LOG_DEBUG << "Received a message!" << END_LOG;
//Create an empty json message
incoming_msg * jmsg = new incoming_msg();
//De-serialize the message and then handle based on its type
try {
string raw_msg_str = raw_msg->get_payload();
LOG_DEBUG << "Received JSON msg: " << raw_msg_str << END_LOG;
//De-serialize the message
jmsg->de_serialize(raw_msg_str);
//Handle the request message based on its type
switch (jmsg->get_msg_type()) {
case msg_type::MESSAGE_TRANS_JOB_REQ:
translation_request(hdl, new trans_job_req_in(jmsg));
break;
case msg_type::MESSAGE_SUPP_LANG_REQ:
language_request(hdl, new supp_lang_req_in(jmsg));
break;
case msg_type::MESSAGE_PRE_PROC_JOB_REQ:
pre_process_request(hdl, new proc_req_in(jmsg));
break;
case msg_type::MESSAGE_POST_PROC_JOB_REQ:
post_process_request(hdl, new proc_req_in(jmsg));
break;
default:
THROW_EXCEPTION(string("Unsupported request type: ") + to_string(jmsg->get_msg_type()));
}
} catch (std::exception & e) {
//Send the error response, NOTE! This is not a JSON we are sending
//back, but just a string, as someone violated the protocol!
send_response(hdl, e.what());
}
}
示例8: account_dialog_done
static void
account_dialog_done (GtkWidget *widget,
int response,
const char *user_name,
const char *real_name,
const char *icon_file,
gpointer user_data)
{
AccountDialogHandle *handle = user_data;
g_clear_pointer (&handle->user_name, g_free);
g_clear_pointer (&handle->real_name, g_free);
g_clear_pointer (&handle->icon_uri, g_free);
switch (response)
{
default:
g_warning ("Unexpected response: %d", response);
/* Fall through */
case GTK_RESPONSE_DELETE_EVENT:
handle->response = 2;
break;
case GTK_RESPONSE_CANCEL:
handle->response = 1;
break;
case GTK_RESPONSE_OK:
handle->user_name = g_strdup (user_name);
handle->real_name = g_strdup (real_name);
if (icon_file)
handle->icon_uri = g_filename_to_uri (icon_file, NULL, NULL);
handle->response = 0;
break;
}
send_response (handle);
}
示例9: ftserve_login
/**
* Log in connected client
*/
int ftserve_login(int sock_control)
{
char buf[MAXSIZE];
char user[MAXSIZE];
char pass[MAXSIZE];
memset(user, 0, MAXSIZE);
memset(pass, 0, MAXSIZE);
memset(buf, 0, MAXSIZE);
// Wait to recieve username
if ( (recv_data(sock_control, buf, sizeof(buf)) ) == -1) {
perror("recv error\n");
exit(1);
}
int i = 5;
int n = 0;
while (buf[i] != 0)
user[n++] = buf[i++];
// tell client we're ready for password
send_response(sock_control, 331);
// Wait to recieve password
memset(buf, 0, MAXSIZE);
if ( (recv_data(sock_control, buf, sizeof(buf)) ) == -1) {
perror("recv error\n");
exit(1);
}
i = 5;
n = 0;
while (buf[i] != 0) {
pass[n++] = buf[i++];
}
return (ftserve_check_user(user, pass));
}
示例10: send_udf_failure
/**
* Send failure notification of general UDF execution, but check for special
* LDT errors and return specific Wire Protocol error codes for these cases:
* (1) Record not found (2)
* (2) LDR Collection item not found (125)
*
* All other errors get the generic 100 (UDF FAIL) code.
*
* Parse (Actually, probe) the error string, and if we see this pattern:
* FileName:Line# 4digits:LDT-<Error String>
* For example:
* .../aerospike-lua-core/src/ldt/lib_llist.lua:982: 0002:LDT-Top Record Not Found
* All UDF errors (LDT included), have the "filename:line# " prefix, and then
* LDT errors follow that with a known pattern:
* (4 digits, colon, LDT-<Error String>).
* We will check the error string by looking for specific markers after the
* the space that follows the filename:line#. If we see the markers, we will
* parse the LDT error code and use that as the wire protocol error if it is
* one of the special ones:
* (1) "0002:LDT-Top Record Not Found"
* (2) "0125:LDT-Item Not Found"
*/
static inline int
send_udf_failure(udf_call *call, int vtype, void *val, size_t vlen)
{
// We need to do a quick look to see if this is an LDT error string. If it
// is, then we'll look deeper. We start looking after the first space.
char * charptr;
char * valptr = (char *) val;
long error_code;
// Start with the space, if it exists, as the marker for where we start
// looking for the LDT error contents.
if ((charptr = strchr((const char *) val, ' ')) != NULL) {
// We must be at least 10 chars from the end, so if we're less than that
// we are obviously not looking at an LDT error.
if (&charptr[9] < &valptr[vlen]) {
if (memcmp(&charptr[5], ":LDT-", 5) == 0) {
error_code = strtol(&charptr[1], NULL, 10);
if (error_code == AS_PROTO_RESULT_FAIL_NOTFOUND ||
error_code == AS_PROTO_RESULT_FAIL_COLLECTION_ITEM_NOT_FOUND)
{
call->transaction->result_code = error_code;
cf_debug(AS_UDF, "LDT Error: Code(%ld) String(%s)",
error_code, (char *) val);
// Send an "empty" response, with no failure bin.
as_transaction * tr = call->transaction;
single_transaction_response(tr, tr->rsv.ns, NULL/*ops*/,
NULL /*bin*/, 0 /*nbins*/, 0, 0, NULL, NULL);
return 0;
}
}
}
}
cf_debug(AS_UDF, "Non-special LDT or General UDF Error(%s)", (char *) val);
call->transaction->result_code = AS_PROTO_RESULT_FAIL_UDF_EXECUTION;
return send_response(call, "FAILURE", 7, vtype, val, vlen);
}
示例11: answer_file
static void
answer_file(struct vmod_fsdirector_file_system *fs, struct stat *stat_buf,
const char *path)
{
mode_t mode = stat_buf->st_mode;
if (S_ISREG(mode)) {
if (stat_buf->st_size) {
send_response(fs, stat_buf, path);
}
else {
prepare_answer(&fs->htc, 204);
prepare_body(&fs->htc);
}
}
else if (S_ISLNK(mode)) {
send_redirect(fs, path);
}
else {
prepare_answer(&fs->htc, 404);
prepare_body(&fs->htc);
}
}
示例12: respond_to
/* Given a HTTP message and the size of the message
* Responds to the given socket with the approrpriate
* HTTP response. The space allocated for message should
* be at least 1 more than req_size */
status respond_to(char* buf, int confd)
{
char resource[BUFLEN+1],
*resource_line, *headers, *current;
int result;
current = buf;
/* Cut off the Resource line */
resource_line = strsep_str(¤t, "\r\n");
/* Get the resource, if error with parsing request line, send 400 response */
if ((result = parse_request_line(resource_line, resource)) != OK) {
printf("Recieved badly formatted request line from connection %d\n",confd);
return send_error(result, confd);
}
printf("request good\n");
headers = strsep_str(¤t, "\r\n\r\n");
printf("headers:%s\n",headers);
return send_response(resource, confd);
}
示例13: error_reply
static int error_reply(nghttp2_session *session,
http2_stream_data *stream_data) {
int rv;
ssize_t writelen;
int pipefd[2];
nghttp2_nv hdrs[] = {MAKE_NV(":status", "404")};
rv = pipe(pipefd);
if (rv != 0) {
warn("Could not create pipe");
rv = nghttp2_submit_rst_stream(session, NGHTTP2_FLAG_NONE,
stream_data->stream_id,
NGHTTP2_INTERNAL_ERROR);
if (rv != 0) {
warnx("Fatal error: %s", nghttp2_strerror(rv));
return -1;
}
return 0;
}
writelen = write(pipefd[1], ERROR_HTML, sizeof(ERROR_HTML) - 1);
close(pipefd[1]);
if (writelen != sizeof(ERROR_HTML) - 1) {
close(pipefd[0]);
return -1;
}
stream_data->fd = pipefd[0];
if (send_response(session, stream_data->stream_id, hdrs, ARRLEN(hdrs),
pipefd[0]) != 0) {
close(pipefd[0]);
return -1;
}
return 0;
}
示例14: get_pool
/// Mangelwurzel receives a response. It will add all the Via headers from the
/// original request back on and send the response on. It can also change
/// the response in various ways depending on the configuration that was
/// specified in the Route header of the original request.
/// - It can mangle the dialog identifiers using its mangalgorithm.
/// - It can mangle the Contact URI using its mangalgorithm.
/// - It can mangle the Record-Route and Route headers URIs.
void MangelwurzelTsx::on_rx_response(pjsip_msg* rsp, int fork_id)
{
pj_pool_t* pool = get_pool(rsp);
if (_config.dialog)
{
mangle_dialog_identifiers(rsp, pool);
}
if (_config.req_uri)
{
mangle_contact(rsp, pool);
}
if (_config.routes)
{
mangle_record_routes(rsp, pool);
mangle_routes(rsp, pool);
}
add_via_hdrs(rsp, pool);
send_response(rsp);
}
示例15: send_delete_res
void send_delete_res(int status, int num_msg)
{
response_t res;
res.status_code = status;
if (status == STATUS_OK)
{
res.data = malloc(sizeof(int));
if (res.data == NULL)
return;
*((int *) res.data) = num_msg;
res.data_len = sizeof(int);
}
else
{
res.data = NULL;
res.data_len = 0;
}
send_response(&res, CMD_DELETE);
if (res.data)
free(res.data);
}