Exemple #1
0
static DBusMessage *profile_new_connection(DBusConnection *conn,
						DBusMessage *msg, void *data)
{
	DBusMessageIter args;
	const char *device;
	int fd;
	GIOChannel *io;

	dbus_message_iter_init(msg, &args);

	if (dbus_message_iter_get_arg_type(&args) != DBUS_TYPE_OBJECT_PATH)
		return invalid_args(msg);

	dbus_message_iter_get_basic(&args, &device);

	dbus_message_iter_next(&args);

	if (dbus_message_iter_get_arg_type(&args) != DBUS_TYPE_UNIX_FD)
		return invalid_args(msg);

	dbus_message_iter_get_basic(&args, &fd);

	io = g_io_channel_unix_new(fd);
	if (io == NULL)
		return invalid_args(msg);

	DBG("device %s", device);

	connect_event(io, NULL, data);

	return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
}
Exemple #2
0
//BEGIN conn_listener
net::nstream_proactor::conn_listener::conn_listener(
	dispatcher & Dispatcher_in,
	conn_container & Conn_Container_in,
	const endpoint & ep
):
	Dispatcher(Dispatcher_in),
	Conn_Container(Conn_Container_in),
	error(no_error)
{
	Listener.open(ep);
	Listener.set_non_blocking(true);
	socket_FD = Listener.socket();
	_info.reset(new conn_info(
		Conn_Container.new_conn_ID(),
		outgoing_dir,
		nstream_listen_tran,
		ep
	));
	if(Listener.is_open()){
		Dispatcher.connect(connect_event(_info));
		Conn_Container.monitor_read(socket_FD);
	}else{
		error = listen_error;
	}
}
Exemple #3
0
void net::nstream_proactor::conn_nstream::write()
{
	touch();
	if(half_open){
		if(N->is_open_async()){
			half_open = false;
			Dispatcher.connect(connect_event(_info));
			//send_buf always empty after connect
			Conn_Container.unmonitor_write(socket_FD);
			Conn_Container.monitor_read(socket_FD);
		}else{
			error = connect_error;
			Conn_Container.remove(_info->conn_ID);
		}
	}else{
		int n_bytes = N->send(send_buf);
		if(send_buf.empty()){
			Conn_Container.unmonitor_write(socket_FD);
		}
		if(n_bytes <= 0){
			error = connection_reset_error;
			Conn_Container.remove(_info->conn_ID);
		}else if(close_on_empty && send_buf.empty()){
			Conn_Container.remove(_info->conn_ID);
		}else{
			Dispatcher.send(send_event(_info, n_bytes, send_buf.size()));
		}
	}
};
Exemple #4
0
net::nstream_proactor::conn_nstream::conn_nstream(
	dispatcher & Dispatcher_in,
	conn_container & Conn_Container_in,
	boost::shared_ptr<nstream> N_in
):
	Dispatcher(Dispatcher_in),
	Conn_Container(Conn_Container_in),
	N(N_in),
	close_on_empty(false),
	half_open(false),
	timeout(std::time(NULL) + idle_timeout),
	error(no_error)
{
	socket_FD = N->socket();
	assert(N->is_open());
	_info.reset(new conn_info(
		Conn_Container.new_conn_ID(),
		incoming_dir,
		nstream_tran,
		N->local_ep(),
		N->remote_ep()
	));
	Dispatcher.connect(connect_event(_info));
	Conn_Container.monitor_read(socket_FD);
}
bool nabto_connect_event_from_gsp(message_event* event, nabto_packet_header* hdr) {
    if (nmc.context.state != NABTO_AS_ATTACHED) {
        NABTO_LOG_TRACE(("Received connect packet from the GSP but we are not attached yet, so we discard the packet."));
        return false;
    }

    return connect_event(event, hdr);
}
bool nabto_connect_event(message_event* event, nabto_packet_header* hdr)
{
    /**
     * We can get here if we got either a connect request or
     * if the connect request is a rendezvous event.
     *
     * If the first payload is an endpoint it's a rendezvous event.
     * If the request is a request for a new connection the first payload will be an IPX payload.
     */
    uint8_t type = 0;

    nabto_rd_payload(nabtoCommunicationBuffer+hdr->hlen, nabtoCommunicationBuffer + hdr->len, &type);

    if (type == NP_PAYLOAD_TYPE_EP) {
        return rendezvous_event(event, hdr);
    } 
    
    if (type == NP_PAYLOAD_TYPE_IPX) {
        return connect_event(event, hdr);
    }
    
    NABTO_LOG_ERROR(("U_CONNECT was neither a rendezvous nor a connect event."));
    return false;
}