Esempio n. 1
0
static void *switch_packet_driver_thread(void *args) {
  fd_set read_fds;
  int nfds = -1;
  int ret = 0;

  switch_packet_cpu_interface_create();
  assert(cpu_sock_fd != -1);

  switch_packet_create_pipe();

  while (TRUE) {
    FD_ZERO(&read_fds);
    FD_SET(cpu_sock_fd, &read_fds);
    FD_SET(pipe_fd[0], &read_fds);
    nfds = switch_packet_select_fd_get(&read_fds);
    ret = select(nfds, &read_fds, NULL, NULL, NULL);
    if (ret == -1) {
      perror("select called failed");
      return NULL;
    } else if (ret) {
      if (FD_ISSET(cpu_sock_fd, &read_fds)) {
        switch_packet_rx_from_hw();
      } else if (FD_ISSET(pipe_fd[0], &read_fds)) {
        switch_packet_read_from_pipe();
      } else {
        switch_packet_tx_from_hosts(read_fds);
      }
    }
  }
}
Esempio n. 2
0
static void *switch_packet_driver_thread(void *args) {
  fd_set read_fds;
  int nfds = -1;
  int ret = 0;

  switch_packet_cpu_interface_create();
  assert(cpu_sock_fd != -1);

  switch_packet_create_pipe();

  // Signal parent to continue
  pthread_mutex_lock(&packet_driver_mutex);
  packet_driver_done = true;
  pthread_cond_signal(&packet_driver_cond);
  pthread_mutex_unlock(&packet_driver_mutex );

  while (TRUE) {
    FD_ZERO(&read_fds);
    FD_SET(cpu_sock_fd, &read_fds);
    FD_SET(pipe_fd[0], &read_fds);
    nfds = switch_packet_select_fd_get(&read_fds);
    ret = select(nfds, &read_fds, NULL, NULL, NULL);
    if (ret == -1) {
      perror("select called failed");
      return NULL;
    } else if (ret) {
      if (FD_ISSET(cpu_sock_fd, &read_fds)) {
        switch_packet_rx_from_hw();
      } else if (FD_ISSET(pipe_fd[0], &read_fds)) {
        switch_packet_read_from_pipe();
      } else {
        switch_packet_tx_from_hosts(read_fds);
      }
    }
  }
}