Beispiel #1
0
void DirectIP::OnKeyDown(const ::SDL_KeyboardEvent& key)
{
	switch(key.keysym.sym)
	{
		case SDLK_UP:
			if(!addr.empty())
				SetNextActivity(new Fade(new Game(true, addr, connection_ptr()), world, eye), true);
			break;
		case SDLK_DOWN:
			if(!addr.empty())
				SetNextActivity(new Fade(new Game(false, addr, connection_ptr()), world, eye), true);
			break;
		case SDLK_ESCAPE:
			SetNextActivity(new Fade(new Menu, world, eye), true);
			break;
		default:
			break;
	}
	// Hantera input, sortera bort oönskade tecken.
	HandleInput(key, addr);
	addr = StripCharacters(addr, "abcdefghijklmnopqrstuvwxyz,!?+-:/ =");

	if(addr.size() >= max_addr_len)
		addr = addr.substr(0, max_addr_len);

	world[0] = object_ptr(new Text(addr, Letter(Size(0.05,0.07,0.0), 0.03, 2.5, Color(0,0,0)),
		Point(2.4, 2, 1+MILLI), Size(1.3, 0.2,0), Color(0.3,0.3,0.3), Rotation(), false));
}
Beispiel #2
0
connection_ptr Engine::get_connection(int fd)
{
	boost::mutex::scoped_lock lock(connection_mutex);
	connection_map::iterator it = connections.find(fd);
	if (it == connections.end()) return connection_ptr();
	return it->second;
}
Beispiel #3
0
void mltds_ct_con_finalize(value connection)
{
    CS_CONNECTION* conn = connection_ptr(connection);

    ct_close(conn, CS_FORCE_CLOSE);
    ct_con_drop(conn);
}
	void on_close(connection_ptr con) {
		m_con = connection_ptr();
		con->stop_heartbeat();

		con->alog().at(log::alevel::DEVEL)<<"client was disconnected sid "<<  con->m_endpoint.m_strSid <<log::endl;

	}
Beispiel #5
0
typename endpoint<connection,config>::connection_ptr
endpoint<connection,config>::create_connection() {
    m_alog.write(log::alevel::devel,"create_connection");
    //scoped_lock_type lock(m_state_lock);

    /*if (m_state == STOPPING || m_state == STOPPED) {
        return connection_ptr();
    }*/

    //scoped_lock_type guard(m_mutex);
    // Create a connection on the heap and manage it using a shared pointer
    connection_ptr con = lib::make_shared<connection_type>(m_is_server,
        m_user_agent, lib::ref(m_alog), lib::ref(m_elog), lib::ref(m_rng));

    connection_weak_ptr w(con);

    // Create a weak pointer on the heap using that shared_ptr.
    // Cast that weak pointer to void* and manage it using another shared_ptr
    // connection_hdl hdl(reinterpret_cast<void*>(new connection_weak_ptr(con)));

    con->set_handle(w);

    // Copy default handlers from the endpoint
    con->set_open_handler(m_open_handler);
    con->set_close_handler(m_close_handler);
    con->set_fail_handler(m_fail_handler);
    con->set_ping_handler(m_ping_handler);
    con->set_pong_handler(m_pong_handler);
    con->set_pong_timeout_handler(m_pong_timeout_handler);
    con->set_interrupt_handler(m_interrupt_handler);
    con->set_http_handler(m_http_handler);
    con->set_validate_handler(m_validate_handler);
    con->set_message_handler(m_message_handler);

    if (m_open_handshake_timeout_dur != config::timeout_open_handshake) {
        con->set_open_handshake_timeout(m_open_handshake_timeout_dur);
    }
    if (m_close_handshake_timeout_dur != config::timeout_close_handshake) {
        con->set_close_handshake_timeout(m_close_handshake_timeout_dur);
    }
    if (m_pong_timeout_dur != config::timeout_pong) {
        con->set_pong_timeout(m_pong_timeout_dur);
    }
    if (m_max_message_size != config::max_message_size) {
        con->set_max_message_size(m_max_message_size);
    }
    con->set_max_http_body_size(m_max_http_body_size);

    lib::error_code ec;

    ec = transport_type::init(con);
    if (ec) {
        m_elog.write(log::elevel::fatal,ec.message());
        return connection_ptr();
    }

    return con;
}
connection_ptr ConnectionManager::Find(const sock_t sockfd)
{
    map<sock_t, connection_ptr>::iterator iter = m_connection_map.find(sockfd);

    if(iter == m_connection_map.end())
        return connection_ptr();

    return iter->second;
}
typename endpoint<connection,config>::connection_ptr
endpoint<connection,config>::create_connection() {
    m_alog.write(log::alevel::devel,"create_connection");
    //scoped_lock_type lock(m_state_lock);

    /*if (m_state == STOPPING || m_state == STOPPED) {
        return connection_ptr();
    }*/

    // Create a connection on the heap and manage it using a shared pointer
    connection_ptr con(new connection_type(m_is_server,m_user_agent,m_alog,
        m_elog, m_rng));

    connection_weak_ptr w(con);

    // Create a weak pointer on the heap using that shared_ptr.
    // Cast that weak pointer to void* and manage it using another shared_ptr
    // connection_hdl hdl(reinterpret_cast<void*>(new connection_weak_ptr(con)));

    // con->set_handle(hdl);

    //
    con->set_handle(w);

    // Copy default handlers from the endpoint
    con->set_open_handler(m_open_handler);
    con->set_close_handler(m_close_handler);
    con->set_fail_handler(m_fail_handler);
    con->set_ping_handler(m_ping_handler);
    con->set_pong_handler(m_pong_handler);
    con->set_pong_timeout_handler(m_pong_timeout_handler);
    con->set_interrupt_handler(m_interrupt_handler);
    con->set_http_handler(m_http_handler);
    con->set_validate_handler(m_validate_handler);
    con->set_message_handler(m_message_handler);

    con->set_termination_handler(
        lib::bind(
            &type::remove_connection,
            this,
            lib::placeholders::_1
        )
    );

    lib::error_code ec;

    ec = transport_type::init(con);
    if (ec) {
        m_elog.write(log::elevel::fatal,ec.message());
        return connection_ptr();
    }

    scoped_lock_type lock(m_mutex);
    m_connections.insert(con);

    return con;
}
Beispiel #8
0
connection_ptr Engine::open_connection(std::string host, int port)
{
	std::string port_str = boost::lexical_cast<std::string>(port);
	int fd = SocketUtils::socket_connection_new(host.c_str(), port_str.c_str(), 0);
	if (fd < 0) return connection_ptr();
	SocketUtils::make_socket_non_blocking(fd);
	connection_ptr conn = add_connection(fd);
	return conn;
}
Beispiel #9
0
CAMLprim value mltds_ct_connect(value connection, value servername)
{
    CAMLparam2(connection, servername);

    retval_inspect( "ct_connect",
                    ct_connect(connection_ptr(connection),
                               String_val(servername),
                               string_length(servername)));

    CAMLreturn(Val_unit);
}
Beispiel #10
0
/* Since only one option is meaningful, simplify to a bool */
CAMLprim value mltds_ct_close( value conn, value force )
{
    CAMLparam2(conn, force);
    CS_INT option = CS_UNUSED;
    if ( Bool_val(force) ) option = CS_FORCE_CLOSE;

    retval_inspect( "ct_close",
                    ct_close(connection_ptr(conn),
                             option) );

    CAMLreturn(Val_unit);
}
Beispiel #11
0
acceptor::acceptor( boost::asio::io_service& IOservice,
		    const std::string& host, unsigned short port, unsigned maxConnections,
		    const net::LocalEndpointConfig& localEndpointConfig_,
		    const types::AddressRestriction& addressRestriction_,
		    GlobalConnectionList& globalList,
		    _Wolframe::ServerHandler& srvHandler ) :
	m_IOservice( IOservice ),
	m_strand( m_IOservice ),
	m_acceptor( m_IOservice ),
	m_connList( maxConnections, globalList ),
	m_localEndpointConfig( localEndpointConfig_ ),
	m_addressRestriction( addressRestriction_ ),
	m_srvHandler( srvHandler )
{
	// Open the acceptor(s) with the option to reuse the address (i.e. SO_REUSEADDR).
	boost::asio::ip::tcp::endpoint endpoint;
	try	{
		boost::asio::ip::tcp::resolver resolver( m_IOservice );
		boost::asio::ip::tcp::resolver::query query( host, "7661" );
		endpoint = *resolver.resolve( query );
	}
	catch ( std::exception& e )	{
		LOG_FATAL << "Unable to resolve host '" << host << "' (" << e.what() << ")";
		exit( ErrorCode::FAILURE );
	}
	endpoint.port( port );

	LocalEndpointR local( new LocalTCPendpoint( host, port, m_localEndpointConfig));
	ConnectionHandler *handler = m_srvHandler.newConnection( local);
	m_newConnection = connection_ptr( new connection( m_IOservice, &m_connList, handler ));

	try	{
		m_acceptor.open( endpoint.protocol() );
		m_acceptor.set_option( boost::asio::ip::tcp::acceptor::reuse_address( true ));
		m_acceptor.bind( endpoint );
		m_acceptor.listen();
	}
	catch ( std::exception& e )	{
		LOG_FATAL << "Unable to listen on " << endpoint << " (" << e.what() << ")";
		exit( ErrorCode::FAILURE );
	}

	m_identifier = m_acceptor.local_endpoint().address().to_string()
			+ ":" + boost::lexical_cast<std::string>( m_acceptor.local_endpoint().port() );

	m_acceptor.async_accept( m_newConnection->socket(),
				 m_strand.wrap( boost::bind( &acceptor::handleAccept,
							     this,
							     boost::asio::placeholders::error )));
	LOG_INFO << "Accepting connections on " << m_identifier;
}
Beispiel #12
0
CAMLprim value mltds_ct_con_setstring(value conn, value field, value newval)
{
    CAMLparam3(conn, field, newval);

    retval_inspect( "ct_con_props",
                    ct_con_props(connection_ptr(conn),
                                 CS_SET,
                                 conprop_of_value(field),
                                 String_val(newval),
                                 string_length(newval),
                                 NULL));

    CAMLreturn(Val_unit);
}
Beispiel #13
0
CAMLprim value mltds_ct_cmd_alloc(value conn)
{
    CAMLparam1(conn);
    CS_COMMAND* command;
    CAMLlocal1(result);

    retval_inspect( "ct_cmd_alloc",
                    ct_cmd_alloc(connection_ptr(conn), &command) );

    result = alloc_custom(&command_operations, sizeof(CS_COMMAND*), 0, 1);
    command_ptr(result) = command;

    CAMLreturn(result);
}
Beispiel #14
0
CAMLprim value mltds_ct_con_alloc(value context)
{
    CAMLparam1(context);
    CS_CONNECTION* conn;
    CAMLlocal1(result);

    retval_inspect( "ct_con_alloc", ct_con_alloc(context_ptr(context), &conn) );

    retval_inspect( "ct_diag",
                    ct_diag(conn, CS_INIT, CS_UNUSED, CS_UNUSED, NULL) );

    result = alloc_custom(&connection_operations, sizeof(CS_CONNECTION*), 0, 1);
    connection_ptr(result) = conn;

    CAMLreturn(result);
}
Beispiel #15
0
connection_ptr Engine::add_connection(int fd)
{
	int s;
	struct epoll_event event;
	event.data.fd = fd;
	event.events = EPOLLIN | EPOLLET;
	s = epoll_ctl(epoll_fd, EPOLL_CTL_ADD, fd, &event);
	if (s == -1)
	{
		DLOG(ERROR) << "Error in epoll_ctl";
		return connection_ptr();
	}
	connection_ptr conn = boost::make_shared<Connection>(fd);
	conn->me = conn;
	connection_mutex.lock();
	connections[fd] = conn;
	connection_mutex.unlock();
	return conn;
}
Beispiel #16
0
CAMLexport value mltds_add_messages_client(value vconnection, value vlist)
{
  CAMLparam2(vconnection, vlist);
  CS_CONNECTION* conn = connection_ptr(vconnection);
  CS_INT msgcount;
  CS_INT msgno;

  retval_inspect(
    "ct_diag",
    ct_diag(conn, CS_STATUS, CS_CLIENTMSG_TYPE, CS_UNUSED, &msgcount));

  for(msgno = msgcount; msgno > 0; msgno--)
    vlist = cons(get_client_message(conn, msgno), vlist);

  retval_inspect(
    "ct_diag",
    ct_diag(conn, CS_CLEAR, CS_CLIENTMSG_TYPE, CS_UNUSED, NULL));
  CAMLreturn(vlist);
}