Esempio n. 1
0
 void SessionImpl::transmit( const Response& response, const function< void ( const error_code&, size_t ) >& callback ) const
 {
     auto hdrs = m_settings->get_default_headers( );
     
     if ( m_resource not_eq nullptr )
     {
         const auto m_resource_headers = m_resource->m_pimpl->m_default_headers;
         hdrs.insert( m_resource_headers.begin( ), m_resource_headers.end( ) );
     }
     
     hdrs.insert( m_headers.begin( ), m_headers.end( ) );
     
     auto response_headers = response.get_headers( );
     hdrs.insert( response_headers.begin( ), response_headers.end( ) );
     
     auto payload = make_shared< Response >( );
     payload->set_headers( hdrs );
     payload->set_body( response.get_body( ) );
     payload->set_version( response.get_version( ) );
     payload->set_protocol( response.get_protocol( ) );
     payload->set_status_code( response.get_status_code( ) );
     payload->set_status_message( response.get_status_message( ) );
     
     if ( payload->get_status_message( ).empty( ) )
     {
         payload->set_status_message( m_settings->get_status_message( payload->get_status_code( ) ) );
     }
     
     m_request->m_pimpl->m_socket->start_write( Http::to_bytes( payload ), callback );
 }
Esempio n. 2
0
gboolean DictClient::on_io_event(GIOChannel *ch, GIOCondition cond,
				 gpointer user_data)
{
	DictClient *dict_client = static_cast<DictClient *>(user_data);

	g_assert(dict_client);

	if (!dict_client->channel_) {
		g_warning("No channel available\n");
		return FALSE;
	}

	if (cond & G_IO_ERR) {
		gchar *mes =
			g_strdup_printf("Connection failed to the dictionary server at %s:%d",
					dict_client->host_.c_str(), dict_client->port_);
		on_error_.emit(mes);
		g_free(mes);
		return FALSE;
	}

	GError *err = NULL;
	gsize term, len;
	gchar *line;
	GIOStatus res;

	for (;;) {
		if (!dict_client->channel_)
			break;
		res = g_io_channel_read_line(dict_client->channel_, &line,
					     &len, &term, &err);
		if (res == G_IO_STATUS_ERROR) {
			if (err) {
				on_error_.emit("Error while reading reply from server: " +
					       std::string(err->message));
				g_error_free(err);
			}
			dict_client->disconnect();

			return FALSE;
		}

		if (!len)
			break;

		//truncate the line terminator before parsing
		line[term] = '\0';
		int status_code = get_status_code(line);
		bool res = dict_client->parse(line, status_code);
		g_free(line);
		if (!res) {
			dict_client->disconnect();
			return FALSE;
		}
	}

	return TRUE;
}
Esempio n. 3
0
void Cversion_check_handler::handle(const std::string& response)
{
	int status_code = get_status_code(response);
	if (status_code != 200)
		alert(Calert(Calert::error, "HTTP error: " + n(status_code)));
	m_version = atoi(get_message_body(response).c_str());
	if (m_version > m_server.version())
		alert(Calert(Calert::info, xbt_version2a(m_version) + " is now available!"));
}
Esempio n. 4
0
static void
postal_http_reply_error (PostalHttp   *http,
                         SoupMessage  *message,
                         const GError *error)
{
   JsonGenerator *g;
   JsonObject *obj;
   JsonNode *node;
   gchar *json_buf;
   gsize length;

   g_assert(SOUP_IS_MESSAGE(message));
   g_assert(error);

   obj = json_object_new();
   json_object_set_string_member(obj, "message", error->message);
   json_object_set_string_member(obj, "domain", g_quark_to_string(error->domain));
   json_object_set_int_member(obj, "code", error->code);

   node = json_node_new(JSON_NODE_OBJECT);
   json_node_set_object(node, obj);
   json_object_unref(obj);

   g = json_generator_new();
   json_generator_set_indent(g, 2);
   json_generator_set_pretty(g, TRUE);
   json_generator_set_root(g, node);
   json_node_free(node);
   json_buf = json_generator_to_data(g, &length);
   g_object_unref(g);

   soup_message_set_response(message,
                             "application/json",
                             SOUP_MEMORY_TAKE,
                             json_buf,
                             length);
   soup_message_set_status(message, get_status_code(error));
   soup_server_unpause_message(http->priv->server, message);
}
Esempio n. 5
0
static utility_retcode_t parse_status_line(struct rtsp_response *response)
{
	utility_retcode_t ret;
	char status_line[64];

	FUNC_ENTER;

	syscalls_memset(status_line, 0, sizeof(status_line));

	ret = utility_copy_token(status_line,
				 sizeof(status_line),
				 response->parsep,
				 "\r\n",
				 NULL);

	if (UTILITY_SUCCESS != ret) {
		ERRR("Failed to locate end of line in status line\n");
		ret = UTILITY_FAILURE;
		goto out;
	}

	INFO("Status line: \"%s\"\n", status_line);

	/* RTSP/1.0 200 OK We don't actually care about the version or
	 * the reason string */

	ret = get_status_code(response);
	if (UTILITY_SUCCESS != ret) {
		goto out;
	}

	ret = next_line(response);

out:
	FUNC_RETURN;
	return ret;
}
Esempio n. 6
0
Integer DAESolver::update_internal_state(Real a_step_interval)
{
    const VariableArray::size_type a_size(the_system_size_);

    the_state_flag_ = false;
    Real const a_previous_step_interval(get_step_interval());

    clear_variables();

    the_rejected_step_flag_ = false;

    for (FunctionArray::size_type c(the_function_differential_size_);
        c < the_system_size_; c++)
    {
        const FunctionArray::size_type an_index(
            c - the_function_differential_size_);

        the_activity_algebraic_buffer_[an_index] 
            = (*the_function_[c])(the_value_differential_,
                the_value_algebraic_, the_current_time_);
    }

    set_variable_velocity(the_taylor_series_[3]);

    if (the_jacobian_calculate_flag_)
    {
        calculate_jacobian();
        set_jacobian_matrix(a_step_interval);
    }
    else
    {
        if (a_previous_step_interval != a_step_interval)
        {
            set_jacobian_matrix(a_step_interval);
        }
    }

    UnsignedInteger count(0);
    for (;;)
    {
        std::pair< bool, Real > a_result(calculate_radauIIA(
            a_step_interval, a_previous_step_interval));

        if (a_result.first)
        {
            break;
        }

        if (++count >= 3)
        {
            break;
        }

        //comment: E-Cell3では
        //aStepInterval = a_result.first;
        //となっていたものを修正
        a_step_interval = a_result.second;

        the_rejected_step_flag_ = true;

        if (!the_jacobian_calculate_flag_)
        {
            calculate_jacobian();
            the_jacobian_calculate_flag_ = true;
        }

        set_jacobian_matrix(a_step_interval);
    }

    the_tolerable_step_interval_ = a_step_interval;


    // the_w_ will already be transformed to Z-form

    for (VariableArray::size_type c(0); c < a_size; ++c)
    {
        the_taylor_series_[3][c] = the_w_[c + a_size * 2];
        the_taylor_series_[3][c] /= a_step_interval;

        if (c < the_function_differential_size_)
        {
            the_value_differential_[c] = the_value_differential_buffer_[c];
        }
        else
        {
            const VariableArray::size_type an_index(
                c - the_function_differential_size_);
            the_value_algebraic_[an_index]
                = the_value_algebraic_buffer_[an_index];
        }
    }

    for (VariableArray::size_type c(0); c < a_size; c++)
    {
        const Real z1(the_w_[c]);
        const Real z2(the_w_[c + a_size]);
        const Real z3(the_w_[c + a_size * 2]);

        the_taylor_series_[0][c] = (13.0 + 7.0 * SQRT6) / 3.0 * z1
            + (13.0 - 7.0 * SQRT6) / 3.0 * z2
            + 1.0 / 3.0 * z3;
        the_taylor_series_[1][c] = - (23.0 + 22.0 * SQRT6) / 3.0 * z1
            + (-23.0 + 22.0 * SQRT6) / 3.0 * z2
            - 8.0 / 3.0 * z3;
        the_taylor_series_[2][c] = (10.0 + 15.0 * SQRT6) / 3.0 * z1 
            + (10.0 - 15.0 * SQRT6) / 3.0 * z2
            + 10.0 / 3.0 * z3;

        the_taylor_series_[0][c] /= a_step_interval;
        the_taylor_series_[1][c] /= a_step_interval;
        the_taylor_series_[2][c] /= a_step_interval;
    }

    the_state_flag_ = true;

    update_internal_state_differential_stepper(a_step_interval);

    //20100224追加
    return get_status_code();

}