static inline int send_failure_str(udf_call *call, const char *err_str, size_t len) { if (! err_str) { // Better than sending an as_string with null value. return send_failure(call, NULL); } as_string stack_s; as_string_init_wlen(&stack_s, (char *)err_str, len, false); return send_failure(call, as_string_toval(&stack_s)); }
/** * 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) LDT Collection item not found (125) * * All other errors get the generic 100 (UDF FAIL) code. */ static inline int send_udf_failure(udf_call *call, const as_string *s) { char *val = as_string_tostring(s); size_t vlen = as_string_len((as_string *)s); // TODO - make as_string_len() take const long error_code = ldt_get_error_code(val, vlen); if (error_code) { if (error_code == AS_PROTO_RESULT_FAIL_NOTFOUND || error_code == AS_PROTO_RESULT_FAIL_COLLECTION_ITEM_NOT_FOUND) { call->tr->result_code = error_code; // Send an "empty" response, with no failure bin. as_transaction * tr = call->tr; 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->tr->result_code = AS_PROTO_RESULT_FAIL_UDF_EXECUTION; return send_failure(call, as_string_toval(s)); }
void assign_home_agent(std::string const& hostname) { // If we're not connected, this object will eventually die and disappear. // (A disconnected signal will be emitted and the pollerconncetion will be removed from // the homeagentdb). Otherwise, we could get into an infinite loop. if ( connected_.load(boost::memory_order_acquire) ) bufwrite_->sendmsg( crawler_protocol::HOME_AGENT_ASSIGNMENT, hostname ); else send_failure( crawler_protocol::HOME_AGENT_ASSIGNMENT, hostname ); }
void connection::frame_sent(frame_bits frame_bit, const boost::system::error_code& error, std::size_t bytes_transfered) { // DLOG(INFO) << "Sent " << bytes_transfered << " bytes for frame type " << frame_bit; if (!(frame_bit & frame_bit_oob_threshold_update && ack_sends_needed_)) outstanding_non_packet_frames_ &= ~frame_bit; if (error) { send_failure(); return; } send_next_frame(); }
void connection::packet_sent(const boost::system::error_code& error, std::size_t bytes_transfered) { if (error) { send_failure(); return; } DLOG(INFO) << std::string(node_->id()) << " Sent " << bytes_transfered << " bytes of packet content"; node_->sent_content(remote_id(), bytes_transfered); packet_queue_.pop_front(); send_next_frame(); }
static int parse_client_line(const int client_socket, char *msg) { char *token; /* On récupère le premier mot, s'il est vide, on retourne direct */ if (!(token = strtok(msg, " "))) return MSG_OK; /***************************************************************************** * CMD_QUIT ****************************************************************************/ if (!strcmp(CMD_QUIT, token)) { send_ok(client_socket, DETAIL_RET_QUIT); return MSG_QUIT; } /***************************************************************************** * CMD_CREATE_PROCESS ****************************************************************************/ else if (!strcmp(CMD_CREATE_PROCESS, token)) { char *args[MAX_ARGS]; char **pc = args; /* On récup le nom du prog */ if (!(token = strtok(NULL, " "))) { send_failure(client_socket, DETAIL_RET_CREATE_PROCESS_SYNTAX); return MSG_ERR; } /* strtok renvoie un buffer static, on le copie */ /* *pc = args[0] = nom du programme */ if (!(*pc++ = strdup(token))) { perror("strdup"); return MSG_ERR; } /* La suite devient optionelle, c'est les arguments */ while ((token = strtok(NULL, " "))) { if ((*pc++ = strdup(token)) == NULL) { perror("strdup"); return MSG_ERR; } } *pc = NULL; /* Fin des arguments */ /* On crée le processus */ pid_t proc = create_process(args[0], args); /* Le processus n'a pas pu être créé */ if (proc == -1) { send_failure(client_socket, DETAIL_RET_CREATE_PROCESS_ERROR); return MSG_ERR; } send_ok(client_socket, itoa(proc)); return MSG_OK; } /***************************************************************************** * CMD_DESTROY_PROCESS ****************************************************************************/ else if (!strcmp(CMD_DESTROY_PROCESS, token)) { if ((token = strtok(NULL, " ")) == NULL) { send_failure(client_socket, DETAIL_RET_DESTROY_PROCESS_SYNTAX); return MSG_ERR; } pid_t process_to_kill = atoi(token); if (!process_exists(process_to_kill)) { send_failure(client_socket, DETAIL_RET_UNKNOWN_PROCESS); return MSG_ERR; } destroy_process(process_to_kill); send_ok(client_socket, NULL); return MSG_OK; } /***************************************************************************** * CMD_SEND_INPUT ****************************************************************************/ else if (!strcmp(CMD_SEND_INPUT, token)) { char buffer[MESSAGE_BUFFER_SIZE]; buffer[0] = '\0'; /* On récup le PID */ if ((token = strtok(NULL, " ")) == NULL) { send_failure(client_socket, DETAIL_RET_SEND_INPUT_SYNTAX); return MSG_ERR; } /* Il existe ? */ pid_t send_to_process = atoi(token); if (!process_exists(send_to_process)) { send_failure(client_socket, DETAIL_RET_UNKNOWN_PROCESS); return MSG_ERR; } /* Il est déjà terminé ? */ if (get_return_code(send_to_process) != PROCESS_NOT_TERMINATED) { send_failure(client_socket, DETAIL_RET_PROCESS_TERMINATED); return MSG_ERR; } /* Son stdin est ouvert ? */ if (!input_open(send_to_process)) { send_failure(client_socket, DETAIL_RET_INPUT_CLOSE); return MSG_ERR; } /* On récup' le message à envoyer */ /* TODO: Prendre la chaîne telle qu'elle, sans splitter puis merger avec un espace */ while ((token = strtok(NULL, " "))) { strcat(buffer, token); strcat(buffer, " "); } /* Si le message est vide, erreur ! */ if (strlen(buffer) == 0) { send_failure(client_socket, DETAIL_RET_SEND_INPUT_SYNTAX); return MSG_ERR; } /* Sinon on envoie ! */ send_input(send_to_process, buffer); send_ok(client_socket, NULL); return MSG_OK; } /***************************************************************************** * CMD_CLOSE_INPUT ****************************************************************************/ else if (!strcmp(CMD_CLOSE_INPUT, token)) { if ((token = strtok(NULL, " ")) == NULL) { send_failure(client_socket, DETAIL_RET_CLOSE_INPUT_SYNTAX); return MSG_ERR; } pid_t process_to_close_input = atoi(token); if (!process_exists(process_to_close_input)) { send_failure(client_socket, DETAIL_RET_UNKNOWN_PROCESS); return MSG_ERR; } close_input(process_to_close_input); send_ok(client_socket, NULL); return MSG_OK; } /***************************************************************************** * CMD_GET_OUTPUT ****************************************************************************/ else if (!strcmp(CMD_GET_OUTPUT, token)) { if ((token = strtok(NULL, " ")) == NULL) { send_failure(client_socket, DETAIL_RET_GET_OUTPUT_SYNTAX); return MSG_ERR; } pid_t process_to_get_output = atoi(token); if (!process_exists(process_to_get_output)) { send_failure(client_socket, DETAIL_RET_UNKNOWN_PROCESS); return MSG_ERR; } get_output(client_socket, process_to_get_output); send_ok(client_socket, NULL); return MSG_OK; } /***************************************************************************** * CMD_GET_ERROR ****************************************************************************/ else if (!strcmp(CMD_GET_ERROR, token)) { if ((token = strtok(NULL, " ")) == NULL) { send_failure(client_socket, DETAIL_RET_GET_ERROR_SYNTAX); return MSG_ERR; } pid_t process_to_get_error = atoi(token); if (!process_exists(process_to_get_error)) { send_failure(client_socket, DETAIL_RET_UNKNOWN_PROCESS); return MSG_ERR; } get_error(client_socket, process_to_get_error); send_ok(client_socket, NULL); return MSG_OK; } /***************************************************************************** * CMD_GET_RETURN_CODE ****************************************************************************/ else if (!strcmp(CMD_GET_RETURN_CODE, token)) { if ((token = strtok(NULL, " ")) == NULL) { send_failure(client_socket, DETAIL_RET_GET_RETURN_CODE_SYNTAX); return MSG_ERR; } pid_t process_to_get_ret = atoi(token); if (!process_exists(process_to_get_ret)) { send_failure(client_socket, DETAIL_RET_UNKNOWN_PROCESS); return MSG_ERR; } int ret = get_return_code(process_to_get_ret); if (ret == PROCESS_NOT_TERMINATED) { send_failure(client_socket, DETAIL_RET_GET_RETURN_CODE_ERROR); return MSG_ERR; } send_ok(client_socket, itoa(ret)); return MSG_OK; } /***************************************************************************** * CMD_LIST_PROCESS ****************************************************************************/ else if (!strcmp(CMD_LIST_PROCESS, token)) { list_process(client_socket); send_ok(client_socket, NULL); return MSG_OK; } /***************************************************************************** * CMD_GET_HELP ****************************************************************************/ else if (!strcmp(CMD_GET_HELP, token)) { send_basic(client_socket, help, strlen(help)); return MSG_OK; } /***************************************************************************** * COMMANDE INCONNUE ****************************************************************************/ else { send_failure(client_socket, DETAIL_RET_UNKNOWN_COMMAND); return MSG_UNKNOWN_COMMAND; } }