示例#1
0
/* Thread: main */
int
remote_pairing_init(void)
{
  int ret;

  remote_list = NULL;

#ifdef USE_EVENTFD
  pairing_efd = eventfd(0, EFD_CLOEXEC | EFD_NONBLOCK);
  if (pairing_efd < 0)
    {
      DPRINTF(E_FATAL, L_REMOTE, "Could not create eventfd: %s\n", strerror(errno));

      return -1;
    }
#else
# if defined(__linux__)
  ret = pipe2(pairing_pipe, O_CLOEXEC | O_NONBLOCK);
# else
  ret = pipe(pairing_pipe);
# endif
  if (ret < 0)
    {
      DPRINTF(E_FATAL, L_REMOTE, "Could not create pairing pipe: %s\n", strerror(errno));

      return -1;
    }

# ifndef __linux__
  ret = fcntl(pairing_pipe[0], F_SETFL, O_NONBLOCK);
  if (ret < 0)
    {
      DPRINTF(E_FATAL, L_REMOTE, "Could not set O_NONBLOCK: %s\n", strerror(errno));

      goto pairing_pipe_fail;
    }
# endif
#endif /* USE_EVENTFD */

  ret = mdns_browse("_touch-remote._tcp", touch_remote_cb);
  if (ret < 0)
    {
      DPRINTF(E_FATAL, L_REMOTE, "Could not browse for Remote services\n");

      goto mdns_browse_fail;
    }

#ifdef USE_EVENTFD
  event_set(&pairingev, pairing_efd, EV_READ, pairing_cb, NULL);
#else
  event_set(&pairingev, pairing_pipe[0], EV_READ, pairing_cb, NULL);
#endif
  event_base_set(evbase_main, &pairingev);
  event_add(&pairingev, NULL);

  return 0;

#ifndef __linux__
 pairing_pipe_fail:
#endif
 mdns_browse_fail:
#ifdef USE_EVENTFD
  close(pairing_efd);
#else
  close(pairing_pipe[0]);
  close(pairing_pipe[1]);
#endif

  return -1;
}
示例#2
0
/* Thread: main */
int
remote_pairing_init(void)
{
  int ret;

  remote_list = NULL;

#ifdef HAVE_EVENTFD
  pairing_efd = eventfd(0, EFD_CLOEXEC | EFD_NONBLOCK);
  if (pairing_efd < 0)
    {
      DPRINTF(E_FATAL, L_REMOTE, "Could not create eventfd: %s\n", strerror(errno));

      return -1;
    }
#else
# ifdef HAVE_PIPE2
  ret = pipe2(pairing_pipe, O_CLOEXEC | O_NONBLOCK);
# else
  if ( pipe(pairing_pipe) < 0 ||
       fcntl(pairing_pipe[0], F_SETFL, O_CLOEXEC | O_NONBLOCK) < 0 ||
       fcntl(pairing_pipe[1], F_SETFL, O_CLOEXEC | O_NONBLOCK) < 0 )
    ret = -1;
  else
    ret = 0;
# endif
  if (ret < 0)
    {
      DPRINTF(E_FATAL, L_REMOTE, "Could not create pairing pipe: %s\n", strerror(errno));

      return -1;
    }
#endif /* HAVE_EVENTFD */

  // No ipv6 for remote at the moment
  ret = mdns_browse("_touch-remote._tcp", AF_INET, touch_remote_cb);
  if (ret < 0)
    {
      DPRINTF(E_FATAL, L_REMOTE, "Could not browse for Remote services\n");

      goto mdns_browse_fail;
    }

#ifdef HAVE_EVENTFD
  pairingev = event_new(evbase_main, pairing_efd, EV_READ, pairing_cb, NULL);
#else
  pairingev = event_new(evbase_main, pairing_pipe[0], EV_READ, pairing_cb, NULL);
#endif
  if (!pairingev)
    {
      DPRINTF(E_FATAL, L_REMOTE, "Out of memory for pairing event\n");

      goto pairingev_fail;
    }

  event_add(pairingev, NULL);

  return 0;

 pairingev_fail:
 mdns_browse_fail:
#ifdef HAVE_EVENTFD
  close(pairing_efd);
#else
  close(pairing_pipe[0]);
  close(pairing_pipe[1]);
#endif

  return -1;
}