void WebSocketSinkManager::removePoll(int fd)
{
	g_io_channel_shutdown(m_ioChannelMap[fd],false,0);
	//printf("Shutting down IO Channel\n");
	DebugOut() << __SMALLFILE__ <<":"<< __LINE__ << "Shutting down IO Channel\n";
	g_source_remove(m_ioSourceMap[fd]); //Since the watch owns the GIOChannel, this should unref it enough to dissapear.

	//for (map<int,guint>::const_iterator i=m_ioSourceMap.cbegin();i!=m_ioSourceMap.cend();i++)
	for (map<int,guint>::iterator i=m_ioSourceMap.begin();i!=m_ioSourceMap.end();i++)
	{
		if((*i).first == fd)
		{
			//printf("Erasing source\n");
			DebugOut() << __SMALLFILE__ <<":"<< __LINE__ << "Erasing source\n";
			m_ioSourceMap.erase(i);
			i--;
			if (m_ioSourceMap.size() == 0)
			{
				break;
			}
		}
	}
	//for (map<int,GIOChannel*>::const_iterator i=m_ioChannelMap.cbegin();i!=m_ioChannelMap.cend();i++)
	for (map<int,GIOChannel*>::iterator i=m_ioChannelMap.begin();i!=m_ioChannelMap.end();i++)
	{
		if((*i).first == fd)
		{
			//printf("Erasing channel\n");
			DebugOut() << __SMALLFILE__ <<":"<< __LINE__ << "Erasing channel\n";
			m_ioChannelMap.erase(i);
			i--;
			if (m_ioChannelMap.size() == 0)
			{
				break;
			}
		}
	}
}
static void interrupt_connect_cb(GIOChannel *chan, GError *conn_err,
							gpointer user_data)
{
	struct input_device *idev = user_data;
	int err;

	if (conn_err) {
		err = -EIO;
		goto failed;
	}

	err = input_device_connected(idev);
	if (err < 0)
		goto failed;

	idev->intr_watch = g_io_add_watch(idev->intr_io,
					G_IO_HUP | G_IO_ERR | G_IO_NVAL,
					intr_watch_cb, idev);

	return;

failed:
	btd_service_connecting_complete(idev->service, err);

	/* So we guarantee the interrupt channel is closed before the
	 * control channel (if we only do unref GLib will close it only
	 * after returning control to the mainloop */
	if (!conn_err)
		g_io_channel_shutdown(idev->intr_io, FALSE, NULL);

	g_io_channel_unref(idev->intr_io);
	idev->intr_io = NULL;

	if (idev->ctrl_io) {
		g_io_channel_unref(idev->ctrl_io);
		idev->ctrl_io = NULL;
	}
}
Пример #3
0
/* Result must be freed */
X264_Gtk *
x264_gtk_load (void)
{
  X264_Gtk     *x264_gtk;
  GIOChannel   *file;
  GError       *error = NULL;
  gchar        *filename;

  x264_gtk = (X264_Gtk *)g_malloc0 (sizeof (X264_Gtk));
  if (!x264_gtk)
    return NULL;

  filename = x264_gtk_path ("x264.cfg");
  file = g_io_channel_new_file (filename, "r", &error);
  if (error) {
    g_print (_("x264.cfg: %s\n"), error->message);
    g_print (_("Loading default configuration\n"));
    _default_set (x264_gtk);
  }
  else {
    GIOStatus status;
    gchar    *data = NULL;
    gsize     length;

    g_print (_("Loading configuration from %s\n"), filename);
    g_io_channel_set_encoding (file, NULL, NULL);
    status = g_io_channel_read_to_end (file, &data, &length, &error);
    if ((status == G_IO_STATUS_NORMAL) &&
        (length == sizeof (X264_Gtk))) {
      memcpy (x264_gtk, data, length);
    }
    g_io_channel_shutdown (file, TRUE, NULL);
    g_io_channel_unref (file);
  }
  g_free (filename);

  return x264_gtk;
}
Пример #4
0
static void session_destroy(struct bluetooth_session *session)
{
	GSList *l;

	DBG("%p", session);

	if (g_slist_find(sessions, session) == NULL)
		return;

	sessions = g_slist_remove(sessions, session);

	if (session->adapter)
		send_method_call(session, session->adapter, BT_ADAPTER_IFACE,
						"ReleaseSession", NULL,
						DBUS_TYPE_INVALID);

	l = session->pending_calls;

	while (l) {
		DBusPendingCall *call = l->data;
		l = l->next;

		session->pending_calls = g_slist_remove(session->pending_calls, call);
		finalize_call(call);
	}

	if (session->io != NULL) {
		g_io_channel_shutdown(session->io, TRUE, NULL);
		g_io_channel_unref(session->io);
	}

	if (session->conn)
		dbus_connection_unref(session->conn);

	g_free(session->service);
	g_free(session->adapter);
	g_free(session);
}
Пример #5
0
static gboolean uart_event(GIOChannel *channel,
				GIOCondition cond, gpointer data)
{
	int uart_fd, ldisc;

	DBG("");

	uart_fd = g_io_channel_unix_get_fd(channel);

	if (cond & (G_IO_NVAL | G_IO_HUP | G_IO_ERR)) {
		connman_error("UART event 0x%x", cond);
		if (uart_watch > 0)
			g_source_remove(uart_watch);

		goto err;
	}

	if (read_command_complete(uart_fd, HCI_HDR_OPCODE) < 0)
		goto err;

	if (set_custom_baud_rate(uart_fd, baud_rate, 1) < 0)
		goto err;

	ldisc = N_TI_WL;
	if (ioctl(uart_fd, TIOCSETD, &ldisc) < 0)
		goto err;

	g_atomic_int_set(&install_count, 0);

	return FALSE;

err:
	g_atomic_int_set(&install_count, 0);
	g_io_channel_shutdown(channel, TRUE, NULL);
	g_io_channel_unref(channel);

	return FALSE;
}
Пример #6
0
static gboolean guard_timeout(gpointer data)
{
	struct sap_server *server = data;
	struct sap_connection *conn = server->conn;

	if (!conn)
		return FALSE;

	DBG("conn %p state %d pr 0x%02x", conn, conn->state,
						conn->processing_req);

	conn->timer_id = 0;

	switch (conn->state) {
	case SAP_STATE_DISCONNECTED:
		/* Client opened RFCOMM channel but didn't send CONNECT_REQ,
		 * in fixed time or client disconnected SAP connection but
		 * didn't closed RFCOMM channel in fixed time.*/
		if (conn->io) {
			g_io_channel_shutdown(conn->io, TRUE, NULL);
			g_io_channel_unref(conn->io);
			conn->io = NULL;
		}
		break;

	case SAP_STATE_GRACEFUL_DISCONNECT:
		/* Client didn't disconnect SAP connection in fixed time,
		 * so close SAP connection immediately. */
		disconnect_req(server, SAP_DISCONNECTION_TYPE_IMMEDIATE);
		break;

	default:
		error("Unexpected state (%d).", conn->state);
		break;
	}

	return FALSE;
}
Пример #7
0
static void avctp_control_confirm(struct avctp *session, GIOChannel *chan,
						struct btd_device *dev)
{
	const bdaddr_t *src;
	const bdaddr_t *dst;

	if (session->control != NULL) {
		error("Control: Refusing unexpected connect");
		g_io_channel_shutdown(chan, TRUE, NULL);

		/*
		 * Close AVCTP channel if remote tried connect
		 * at the same time
		 * AVRCP SPEC V1.5 4.1.1 Connection Establishment
		 */
		avctp_set_state(session, AVCTP_STATE_DISCONNECTED, -EAGAIN);
		return;
	}

	avctp_set_state(session, AVCTP_STATE_CONNECTING, 0);
	session->control = avctp_channel_create(session, chan, 2, NULL);

	src = btd_adapter_get_address(device_get_adapter(dev));
	dst = device_get_address(dev);

	session->auth_id = btd_request_authorization(src, dst,
							AVRCP_REMOTE_UUID,
							auth_cb, session);
	if (session->auth_id == 0)
		goto drop;

	session->control->watch = g_io_add_watch(chan, G_IO_ERR | G_IO_HUP |
						G_IO_NVAL, session_cb, session);
	return;

drop:
	avctp_set_state(session, AVCTP_STATE_DISCONNECTED, -EIO);
}
Пример #8
0
G_MODULE_EXPORT gboolean select_vex_for_import(GtkWidget *widget, gpointer data)
{
	MtxFileIO *fileio = NULL;
	gchar *filename = NULL;
	GIOChannel *iochannel = NULL;

	if (!DATA_GET(global_data,"interrogated"))
		return FALSE;

	fileio = g_new0(MtxFileIO ,1);
	fileio->external_path = g_strdup("MTX_VexFiles");
	fileio->title = g_strdup("Select your VEX file to import");
	fileio->parent = lookup_widget_f("main_window");
	fileio->on_top = TRUE;
	fileio->action = GTK_FILE_CHOOSER_ACTION_OPEN;

	filename = choose_file(fileio);
	if (filename == NULL)
	{
		update_logbar_f("tools_view","warning",_("NO FILE chosen for VEX import\n"),FALSE,FALSE,FALSE);
		return FALSE;
	}

	iochannel = g_io_channel_new_file(filename, "r+",NULL);
	if (!iochannel)
	{
		update_logbar_f("tools_view","warning",_("File open FAILURE! \n"),FALSE,FALSE,FALSE);
		return FALSE;
	}
	update_logbar_f("tools_view",NULL,_("VEX File Closed\n"),FALSE,FALSE,FALSE);
	gtk_entry_set_text(GTK_ENTRY(lookup_widget_f("tools_vex_comment_entry")),"");

	all_table_import(iochannel);
	g_io_channel_shutdown(iochannel,TRUE,NULL);
	g_io_channel_unref(iochannel);
	free_mtxfileio(fileio);
	return TRUE;
}
Пример #9
0
static void close_mcl(struct mcap_mcl *mcl, gboolean cache_requested)
{
	gboolean save = ((!(mcl->ctrl & MCAP_CTRL_FREE)) && cache_requested);

	RELEASE_TIMER(mcl);

	if (mcl->cc) {
		g_io_channel_shutdown(mcl->cc, TRUE, NULL);
		g_io_channel_unref(mcl->cc);
		mcl->cc = NULL;
	}

	if (mcl->wid) {
		g_source_remove(mcl->wid);
		mcl->wid = 0;
	}

	if (mcl->lcmd) {
		g_free(mcl->lcmd);
		mcl->lcmd = NULL;
	}

	if (mcl->priv_data)
		free_mcl_priv_data(mcl);

	g_slist_foreach(mcl->mdls, (GFunc) shutdown_mdl, NULL);

	mcap_sync_stop(mcl);

	mcl->state = MCL_IDLE;

	if (save)
		return;

	g_slist_foreach(mcl->mdls, (GFunc) mcap_mdl_unref, NULL);
	g_slist_free(mcl->mdls);
	mcl->mdls = NULL;
}
Пример #10
0
Файл: fbxkb.c Проект: kba/fbxkb
static void
tooltip_set()
{

    gchar *argv[] = { LIBEXECDIR "/fbxkb/options.sh", NULL };
    gchar *text;
    gint standard_output;
    gsize len;
    GIOChannel *gio;

    ENTER;
    if (!g_spawn_async_with_pipes(NULL, argv, NULL, 0, NULL, NULL, NULL, NULL,
                &standard_output, NULL, NULL))
        RET();
    gio = g_io_channel_unix_new (standard_output);
    if (g_io_channel_read_to_end(gio, &text, &len, NULL) == G_IO_STATUS_NORMAL) {
        g_strchomp(text);
        gtk_status_icon_set_tooltip_markup(icon, text);
    }
    g_io_channel_shutdown(gio, FALSE, NULL);
    g_free(text);
    RET();
}
Пример #11
0
static void session_destroy(struct bluetooth_session *session)
{
	DBG("%p", session);

	if (g_slist_find(sessions, session) == NULL)
		return;

	sessions = g_slist_remove(sessions, session);

	if (session->io != NULL) {
		g_io_channel_shutdown(session->io, TRUE, NULL);
		g_io_channel_unref(session->io);
	}

	if (session->sdp)
		sdp_close(session->sdp);

	if (session->sdp_record)
		sdp_record_free(session->sdp_record);

	g_free(session->service);
	g_free(session);
}
Пример #12
0
void StarDictClient::disconnect()
{
    clean_command();
    if (in_source_id_) {
        g_source_remove(in_source_id_);
        in_source_id_ = 0;
    }
    if (out_source_id_) {
        g_source_remove(out_source_id_);
        out_source_id_ = 0;
    }

    if (channel_) {
        g_io_channel_shutdown(channel_, TRUE, NULL);
        g_io_channel_unref(channel_);
        channel_ = NULL;
    }
	if (sd_ != -1) {
		Socket::close(sd_);
		sd_ = -1;
	}
    is_connected_ = false;
}
Пример #13
0
static void auth_cb(DBusError *derr, void *user_data)
{
	struct network_adapter *na = user_data;
	GError *err = NULL;

	if (derr) {
		error("Access denied: %s", derr->message);
		goto reject;
	}

	if (!bt_io_accept(na->setup->io, connect_event, na, NULL,
							&err)) {
		error("bt_io_accept: %s", err->message);
		g_error_free(err);
		goto reject;
	}

	return;

reject:
	g_io_channel_shutdown(na->setup->io, TRUE, NULL);
	setup_destroy(na);
}
int sap_server_unregister(const char *path)
{
	DBG("");
	if (!server)
		return -EINVAL;

	remove_record_from_server(server->record_id);

	if (server->conn)
		sap_conn_remove(server->conn);

	if (server->listen_io) {
		g_io_channel_shutdown(server->listen_io, TRUE, NULL);
		g_io_channel_unref(server->listen_io);
		server->listen_io = NULL;
	}

	g_dbus_unregister_interface(connection, path, SAP_SERVER_INTERFACE);

	sap_exit();

	return 0;
}
Пример #15
0
void avrcp_unregister(const bdaddr_t *src)
{
	struct avctp_server *server;

	server = find_server(servers, src);
	if (!server)
		return;

	servers = g_slist_remove(servers, server);

	remove_record_from_server(server->ct_record_id);
	remove_record_from_server(server->tg_record_id);

	g_io_channel_shutdown(server->io, TRUE, NULL);
	g_io_channel_unref(server->io);
	g_free(server);

	if (servers)
		return;

	dbus_connection_unref(connection);
	connection = NULL;
}
Пример #16
0
static void ext_io_destroy(gpointer p)
{
	struct ext_io *ext_io = p;
	struct ext_profile *ext = ext_io->ext;

	if (ext_io->io_id > 0)
		g_source_remove(ext_io->io_id);

	if (ext_io->io) {
		g_io_channel_shutdown(ext_io->io, FALSE, NULL);
		g_io_channel_unref(ext_io->io);
	}

	if (ext_io->auth_id != 0)
		btd_cancel_authorization(ext_io->auth_id);

	if (ext_io->new_conn) {
		dbus_pending_call_cancel(ext_io->new_conn);
		dbus_pending_call_unref(ext_io->new_conn);
		ext_cancel(ext);
	}

	if (ext_io->resolving)
		bt_cancel_discovery(adapter_get_address(ext_io->adapter),
					device_get_address(ext_io->device));

	if (ext_io->rec_handle)
		remove_record_from_server(ext_io->rec_handle);

	if (ext_io->adapter)
		btd_adapter_unref(ext_io->adapter);

	if (ext_io->device)
		btd_device_unref(ext_io->device);

	g_free(ext_io);
}
Пример #17
0
gint sock_connect_async_cancel(gint id)
{
	SockConnectData *conn_data = NULL;
	GList *cur;

	for (cur = sock_connect_data_list; cur != NULL; cur = cur->next) {
		if (((SockConnectData *)cur->data)->id == id) {
			conn_data = (SockConnectData *)cur->data;
			break;
		}
	}

	if (conn_data) {
		sock_connect_data_list = g_list_remove(sock_connect_data_list,
						       conn_data);

		if (conn_data->lookup_data)
			sock_get_address_info_async_cancel
				(conn_data->lookup_data);

		if (conn_data->io_tag > 0)
			g_source_remove(conn_data->io_tag);
		if (conn_data->channel) {
			g_io_channel_shutdown(conn_data->channel, FALSE, NULL);
			g_io_channel_unref(conn_data->channel);
		}

		sock_address_list_free(conn_data->addr_list);
		g_free(conn_data->hostname);
		g_free(conn_data);
	} else {
		g_warning("sock_connect_async_cancel: id %d not found.\n", id);
		return -1;
	}

	return 0;
}
Пример #18
0
/* camera_delete */
void camera_delete(Camera * camera)
{
	size_t i;

	camera_stop(camera);
	if(camera->pp_window != NULL)
		gtk_widget_destroy(camera->pp_window);
	if(camera->pr_window != NULL)
		gtk_widget_destroy(camera->pr_window);
	for(i = 0; i < camera->overlays_cnt; i++)
		cameraoverlay_delete(camera->overlays[i]);
	free(camera->overlays);
	if(camera->channel != NULL)
	{
		/* XXX we ignore errors at this point */
		g_io_channel_shutdown(camera->channel, TRUE, NULL);
		g_io_channel_unref(camera->channel);
	}
	if(camera->pixmap != NULL)
		g_object_unref(camera->pixmap);
	if(camera->gc != NULL)
		g_object_unref(camera->gc);
	if(camera->bold != NULL)
		pango_font_description_free(camera->bold);
	if(camera->fd >= 0)
		close(camera->fd);
	if((char *)camera->rgb_buffer != camera->raw_buffer)
		free(camera->rgb_buffer);
	for(i = 0; i < camera->buffers_cnt; i++)
		if(camera->buffers[i].start != MAP_FAILED)
			munmap(camera->buffers[i].start,
					camera->buffers[i].length);
	free(camera->buffers);
	free(camera->raw_buffer);
	string_delete(camera->device);
	object_delete(camera);
}
static void TestRead(gconstpointer user_data) {
  guint index = GPOINTER_TO_UINT(user_data);
  gint fds [] = { 0, 0 };
  GIOChannel *reader = NULL;
  WriterThreadContext thread_ctx = { NULL, NULL };
  GThread *thread = NULL;
  GError *error = NULL;
  EscalateMessage *message = NULL;
  GVariant *expected_values = CreateExampleMessageValues(index);

  g_assert(g_unix_open_pipe(fds, 0, NULL));
  reader = g_io_channel_unix_new(fds[0]);

  thread_ctx.channel = g_io_channel_unix_new(fds[1]);
  thread_ctx.contents = example_messages[index];
  thread = g_thread_new("Writer", (GThreadFunc) WriterThread, &thread_ctx);
  g_assert(thread);

  message = EscalateMessageRead(reader, &error);
  g_assert_no_error(error);
  g_assert(message);
  g_assert_cmpint(EscalateMessageGetType(message), ==,
                  example_message_types[index]);
  g_assert(g_variant_equal(expected_values, message->values));
  EscalateMessageUnref(message);

  message = EscalateMessageRead(reader, &error);
  g_assert_error(error, ESCALATE_MESSAGE_ERROR, ESCALATE_MESSAGE_ERROR_EOF);
  g_assert(!message);
  g_error_free(error);

  g_thread_join(thread);
  g_variant_unref(expected_values);
  g_io_channel_shutdown(reader, FALSE, NULL);
  g_io_channel_unref(reader);
  g_io_channel_unref(thread_ctx.channel);
}
/*
  We must save the binary data in separate files because
  mmap wants getpagesize() alignment.  If we append all
  the data to one file then we don't know the appropriate
  padding since the page size isn't fixed.
*/
static void
_file_index_id_save_entries (gpointer * _key,
    GstFileIndexId * ii, gchar * prefix)
{
  GError *err;
  gchar *path;
  GIOChannel *chan;

  if (!ii->array)
    return;

  err = NULL;
  path = g_strdup_printf ("%s/%d", prefix, ii->id);
  chan = g_io_channel_new_file (path, "w", &err);
  g_free (path);
  if (err)
    goto fail;

  g_io_channel_set_encoding (chan, NULL, &err);
  if (err)
    goto fail;

  g_io_channel_write_chars (chan,
      ii->array->data, ARRAY_TOTAL_SIZE (ii), NULL, &err);
  if (err)
    goto fail;

  g_io_channel_shutdown (chan, TRUE, &err);
  if (err)
    goto fail;

  g_io_channel_unref (chan);
  return;

fail:
  GST_ERROR ("%s", err->message);
}
Пример #21
0
static void free_context(struct context *ctx)
{
	if (!ctx)
		return;

	if (ctx->delimiter)
		g_string_free(ctx->delimiter, TRUE);

	if (ctx->comment)
		g_string_free(ctx->comment, TRUE);

	if (ctx->channel) {
		g_io_channel_shutdown(ctx->channel, FALSE, NULL);
		g_io_channel_unref(ctx->channel);
	}

	if (ctx->sample_buffer)
		g_free(ctx->sample_buffer);

	if (ctx->buffer)
		g_string_free(ctx->buffer, TRUE);

	g_free(ctx);
}
Пример #22
0
static void confirm_event_cb(GIOChannel *chan, gpointer user_data)
{
	struct input_server *server = user_data;
	bdaddr_t src, dst;
	GError *err = NULL;
	int ret;

	bt_io_get(chan, BT_IO_L2CAP, &err,
			BT_IO_OPT_SOURCE_BDADDR, &src,
			BT_IO_OPT_DEST_BDADDR, &dst,
			BT_IO_OPT_INVALID);
	if (err) {
		error("%s", err->message);
		g_error_free(err);
		goto drop;
	}

	if (server->confirm) {
		error("Refusing connection: setup in progress");
		goto drop;
	}

	server->confirm = g_io_channel_ref(chan);

	ret = btd_request_authorization(&src, &dst, HID_UUID,
					auth_callback, server);
	if (ret == 0)
		return;

	g_io_channel_unref(server->confirm);
	server->confirm = NULL;

drop:
	input_device_close_channels(&src, &dst);
	g_io_channel_shutdown(chan, TRUE, NULL);
}
void
bacon_message_connection_free (BaconMessageConnection *conn)
{
	GSList *child_conn;

	g_return_if_fail (conn != NULL);
	/* Only servers can accept other connections */
	g_return_if_fail (conn->is_server != FALSE ||
			  conn->accepted_connections == NULL);

	child_conn = conn->accepted_connections;
	while (child_conn != NULL) {
		bacon_message_connection_free (child_conn->data);
		child_conn = g_slist_next (child_conn);
	}
	g_slist_free (conn->accepted_connections);

	if (conn->conn_id) {
		g_source_remove (conn->conn_id);
		conn->conn_id = 0;
	}
	if (conn->chan) {
		g_io_channel_shutdown (conn->chan, FALSE, NULL);
		g_io_channel_unref (conn->chan);
	}

	if (conn->is_server != FALSE) {
		unlink (conn->path);
	}
	if (conn->fd != -1) {
		close (conn->fd);
	}

	g_free (conn->path);
	g_free (conn);
}
Пример #24
0
static void connect_cb(GIOChannel *chan, GError *err, gpointer user_data)
{
	struct a2dp_device *dev;
	bdaddr_t dst;
	char address[18];
	GError *gerr = NULL;
	GSList *l;

	if (err) {
		error("%s", err->message);
		return;
	}

	bt_io_get(chan, &gerr,
			BT_IO_OPT_DEST_BDADDR, &dst,
			BT_IO_OPT_INVALID);
	if (gerr) {
		error("%s", gerr->message);
		g_error_free(gerr);
		g_io_channel_shutdown(chan, TRUE, NULL);
		return;
	}

	ba2str(&dst, address);
	DBG("Incoming connection from %s", address);

	l = g_slist_find_custom(devices, &dst, device_cmp);
	if (l) {
		transport_connect_cb(chan, err, l->data);
		return;
	}

	dev = a2dp_device_new(&dst);
	bt_a2dp_notify_state(dev, HAL_A2DP_STATE_CONNECTING);
	signaling_connect_cb(chan, err, dev);
}
Пример #25
0
/* playerbackend_destroy */
void playerbackend_destroy(PlayerBackend * player)
{
	char const cmd[] = "\nquit\n";
	gsize written;
	size_t i;
	int status = 0;
	pid_t res;
	struct timespec ts = { 0, 500000 };

	if(player->read_id != 0)
		g_source_remove(player->read_id);
	if(player->write_id != 0)
		g_source_remove(player->write_id);
	if(player->timeout_id != 0)
		g_source_remove(player->timeout_id);
	g_io_channel_write_chars(player->channel[1], cmd, sizeof(cmd) - 1,
			&written, NULL);
	g_io_channel_shutdown(player->channel[1], FALSE, NULL);
	for(i = 0; i < 6; i++)
	{
		if(player->pid == -1)
			break;
		if((res = waitpid(player->pid, &status, WNOHANG)) == -1)
		{
			player_error(NULL, "waitpid", 0);
			break;
		}
		else if(res == 0)
			nanosleep(&ts, NULL);
		else if(WIFEXITED(status) || WIFSIGNALED(status))
			break;
		if(i == 4)
			kill(player->pid, SIGTERM);
	}
	object_delete(player);
}
Пример #26
0
static gboolean unix_accept(GIOChannel *chan, GIOCondition cond, gpointer data)
{
	struct sockaddr_un addr;
	socklen_t addrlen;
	int sk, cli_sk;
	GIOChannel *io;

	if (cond & G_IO_NVAL)
		return FALSE;

	if (cond & (G_IO_HUP | G_IO_ERR)) {
		g_io_channel_shutdown(chan, TRUE, NULL);
		return FALSE;
	}

	sk = g_io_channel_unix_get_fd(chan);

	memset(&addr, 0, sizeof(addr));
	addrlen = sizeof(addr);

	cli_sk = accept(sk, (struct sockaddr *) &addr, &addrlen);
	if (cli_sk < 0) {
		g_printerr("accept: %s (%d)\n", strerror(errno), errno);
		return TRUE;
	}

	g_print("Accepted new client connection on unix socket (fd=%d)\n",
								cli_sk);

	io = g_io_channel_unix_new(cli_sk);

	transport_accept(io);
	g_io_channel_unref(io);

	return TRUE;
}
Пример #27
0
static void auth_cb(DBusError *derr, void *user_data)
{
    struct serial_proxy *prx = user_data;
    GError *err = NULL;

    if (derr) {
        error("Access denied: %s", derr->message);
        goto reject;
    }

    if (!bt_io_accept(prx->rfcomm, connect_event_cb, prx, NULL,
                      &err)) {
        error("bt_io_accept: %s", err->message);
        g_error_free(err);
        goto reject;
    }

    return;

reject:
    g_io_channel_shutdown(prx->rfcomm, TRUE, NULL);
    g_io_channel_unref(prx->rfcomm);
    prx->rfcomm = NULL;
}
Пример #28
0
static void avctp_browsing_confirm(struct avctp *session, GIOChannel *chan,
						struct btd_device *dev)
{
	GError *err = NULL;

	if (session->control == NULL || session->browsing != NULL) {
		error("Browsing: Refusing unexpected connect");
		g_io_channel_shutdown(chan, TRUE, NULL);
		return;
	}

	if (bt_io_accept(chan, avctp_connect_browsing_cb, session, NULL,
								&err)) {
		avctp_set_state(session, AVCTP_STATE_BROWSING_CONNECTING, 0);
		session->browsing = avctp_channel_create(session, chan, 1,
							avctp_destroy_browsing);
		return;
	}

	error("Browsing: %s", err->message);
	g_error_free(err);

	return;
}
Пример #29
0
static void pnat_remove(struct btd_adapter *adapter)
{
	struct dun_server *server;
	GSList *match;
	bdaddr_t src;

	adapter_get_address(adapter, &src);

	match = g_slist_find_custom(servers, &src, server_cmp);
	if (match == NULL)
		return;

	server = match->data;

	servers = g_slist_delete_link(servers, match);

	disconnect(server);

	remove_record_from_server(server->record_handle);
	close(server->rfcomm_ctl);
	g_io_channel_shutdown(server->server, TRUE, NULL);
	g_io_channel_unref(server->server);
	g_free(server);
}
Пример #30
0
int UnLinkFifo(int tag, GIOChannel *gch)
{
	int retval = 0;
	
	if (g_source_remove(tag))
	{
		// Watch removed
		if(g_io_channel_shutdown(gch, FALSE, NULL) == G_IO_STATUS_NORMAL)
		{
			// Io channel shutdown, unref variable
			g_io_channel_unref(gch);
			retval = 1;
		}
		else
		{
			printf("Fifo: Error shutdown channel\n");
		}
	}
	else
	{
		printf("Fifo: Error removing watch\n");
	}
	return (retval);
}