Example #1
0
void MiracBroker::try_connect()
{
    WDS_LOG("Trying to connect...");

    connect_wait_id_ = 0;
    network(new MiracNetwork());

    if (network_->Connect(peer_address_.c_str(), peer_port_.c_str())) {
        g_unix_fd_add(network_->GetHandle(), G_IO_OUT,
                      MiracBroker::send_cb, &network_source_ptr_);
    } else {
        g_unix_fd_add(network_->GetHandle(), G_IO_OUT,
                      MiracBroker::connect_cb, &network_source_ptr_);
    }
}
Example #2
0
void MiracBroker::SendRTSPData(const std::string& data) {
  WDS_VLOG("Sending RTSP message:\n%s", data.c_str());

  if (connection_ && !connection_->Send(data))
      g_unix_fd_add(connection_->GetHandle(), G_IO_OUT,
                    send_cb, &connection_source_ptr_);
}
Example #3
0
void MiracBroker::connection(MiracNetwork *connection)
{
    while (g_source_remove_by_user_data(&connection_source_ptr_))
        ;
    connection_.reset(connection);

    if (connection_)
        g_unix_fd_add(connection_->GetHandle(), G_IO_IN,
                      receive_cb, &connection_source_ptr_);
}
Example #4
0
MiracBroker::MiracBroker (const std::string& listen_port):
    connect_timer_(NULL)
{
    network_source_ptr_ = this;
    connection_source_ptr_ = this;

    network(new MiracNetwork());

    network_->Bind(NULL, listen_port.c_str());
    g_unix_fd_add(network_->GetHandle(), G_IO_IN,
                  MiracBroker::listen_cb, &network_source_ptr_);
}
static void
startup(void)
{
    guint id;

    if (pipe2(pfd, O_CLOEXEC) < 0) {
        SOL_WRN("pipe()");
        goto error;
    }

    if (!sol_glib_integration()) {
        SOL_WRN("sol_glib_integration()");
        goto error;
    }

    fork_run = sol_platform_linux_fork_run(on_fork, on_child_exit, NULL);
    if (!fork_run) {
        SOL_WRN("sol_platform_linux_fork_run()");
        goto error;
    }

    id = g_idle_add(on_idle, NULL);
    if (id == 0) {
        SOL_WRN("g_idle_add()");
        goto error;
    }

    id = g_timeout_add(100, on_timeout, NULL);
    if (id == 0) {
        SOL_WRN("g_timeout_add()");
        goto error;
    }

    id = g_unix_fd_add(pfd[0], G_IO_IN, on_fd, NULL);
    if (id == 0) {
        SOL_WRN("g_unix_fd_add()");
        goto error;
    }

    sol_timeout_add(5000, on_watchdog, NULL);
    return;

error:
    sol_quit_with_code(EXIT_FAILURE);
    return;
}
Example #6
0
gboolean
meta_xwayland_start (MetaXWaylandManager *manager,
                     struct wl_display   *wl_display)
{
  int xwayland_client_fd[2];
  int displayfd[2];
  gboolean started = FALSE;
  g_autoptr(GSubprocessLauncher) launcher = NULL;
  GSubprocessFlags flags;
  GSubprocess *proc;
  GError *error = NULL;

  if (!choose_xdisplay (manager))
    goto out;

  /* We want xwayland to be a wayland client so we make a socketpair to setup a
   * wayland protocol connection. */
  if (socketpair (AF_UNIX, SOCK_STREAM | SOCK_CLOEXEC, 0, xwayland_client_fd) < 0)
    {
      g_warning ("xwayland_client_fd socketpair failed\n");
      goto out;
    }

  if (socketpair (AF_UNIX, SOCK_STREAM | SOCK_CLOEXEC, 0, displayfd) < 0)
    {
      g_warning ("displayfd socketpair failed\n");
      goto out;
    }

  /* xwayland, please. */
  flags = G_SUBPROCESS_FLAGS_NONE;

  if (getenv ("XWAYLAND_STFU"))
    {
      flags |= G_SUBPROCESS_FLAGS_STDOUT_SILENCE;
      flags |= G_SUBPROCESS_FLAGS_STDERR_SILENCE;
    }

  launcher = g_subprocess_launcher_new (flags);

  g_subprocess_launcher_take_fd (launcher, xwayland_client_fd[1], 3);
  g_subprocess_launcher_take_fd (launcher, manager->abstract_fd, 4);
  g_subprocess_launcher_take_fd (launcher, manager->unix_fd, 5);
  g_subprocess_launcher_take_fd (launcher, displayfd[1], 6);

  g_subprocess_launcher_setenv (launcher, "WAYLAND_SOCKET", "3", TRUE);
  proc = g_subprocess_launcher_spawn (launcher, &error,
                                      XWAYLAND_PATH, manager->display_name,
                                      "-rootless", "-noreset",
                                      "-listen", "4",
                                      "-listen", "5",
                                      "-displayfd", "6",
                                      NULL);
  if (!proc)
    {
      g_error ("Failed to spawn Xwayland: %s", error->message);
      goto out;
    }

  g_subprocess_wait_async  (proc, NULL, xserver_died, NULL);
  g_unix_fd_add (displayfd[0], G_IO_IN, on_displayfd_ready, manager);
  manager->client = wl_client_create (wl_display, xwayland_client_fd[0]);

  /* We need to run a mainloop until we know xwayland has a binding
   * for our xserver interface at which point we can assume it's
   * ready to start accepting connections. */
  manager->init_loop = g_main_loop_new (NULL, FALSE);
  g_main_loop_run (manager->init_loop);

  started = TRUE;

out:
  if (!started)
    {
      unlink (manager->lock_file);
      g_clear_pointer (&manager->lock_file, g_free);
    }
  return started;
}