예제 #1
0
파일: ui_config.c 프로젝트: rsenn/tichu
/* -------------------------------------------------------------------------- *
 * Speichert alle Konfigurationsdaten aus den Widgets von ui_config           *
 * -------------------------------------------------------------------------- */
int ui_config_save(void)
{
  int ret;
  
  ui_sound_save();
  
  ui_config_client_save();
  ui_config_card_save();
  ui_config_fan_save();
  ui_config_stack_save();
  
  /* Die .ini Datei speichern */
  ini_save(client_ini);
  
  /* ..und dann alle module neu konfigurieren */
  ret = client_configure();
  net_configure(client_ini);
  card_configure(client_ini);
  fan_configure(client_ini);
//  stack_configure(client_ini);

  return ret;
}
예제 #2
0
void *net_reader(pthread_addr_t pvarg)
{
  struct sockaddr_in addr;
#ifdef POLL_HAVE_SOLINGER
  struct linger ling;
#endif
  int listensd;
  int acceptsd;
  socklen_t addrlen;
  int optval;

  /* Configure uIP */

  net_configure();

  /* Create a new TCP socket */

  listensd = socket(PF_INET, SOCK_STREAM, 0);
  if (listensd < 0)
    {
      printf("net_reader: socket failure: %d\n", errno);
      goto errout;
    }

  /* Set socket to reuse address */

  optval = 1;
  if (setsockopt(listensd, SOL_SOCKET, SO_REUSEADDR, (void*)&optval, sizeof(int)) < 0)
    {
      printf("net_reader: setsockopt SO_REUSEADDR failure: %d\n", errno);
      goto errout_with_listensd;
    }

  /* Bind the socket to a local address */

  addr.sin_family      = AF_INET;
  addr.sin_port        = HTONS(LISTENER_PORT);
  addr.sin_addr.s_addr = INADDR_ANY;

  if (bind(listensd, (struct sockaddr*)&addr, sizeof(struct sockaddr_in)) < 0)
    {
      printf("net_reader: bind failure: %d\n", errno);
      goto errout_with_listensd;
    }

  /* Listen for connections on the bound TCP socket */

  if (listen(listensd, 5) < 0)
    {
      printf("net_reader: listen failure %d\n", errno);
      goto errout_with_listensd;
    }

  /* Connection loop */

  for (;;)
    {
      /* Accept only one connection */

      printf("net_reader: Accepting new connections on port %d\n", LISTENER_PORT);
      addrlen = sizeof(struct sockaddr_in);
      acceptsd = accept(listensd, (struct sockaddr*)&addr, &addrlen);
      if (acceptsd < 0)
        {
          printf("net_reader: accept failure: %d\n", errno);
          continue;
        }
      printf("net_reader: Connection accepted on sd=%d\n", acceptsd);

      /* Configure to "linger" until all data is sent when the socket is closed */

#ifdef POLL_HAVE_SOLINGER
      ling.l_onoff  = 1;
      ling.l_linger = 30;     /* timeout is seconds */
      if (setsockopt(acceptsd, SOL_SOCKET, SO_LINGER, &ling, sizeof(struct linger)) < 0)
        {
        printf("net_reader: setsockopt SO_LINGER failure: %d\n", errno);
        goto errout_with_acceptsd;
      }
#endif

      /* Handle incoming messsages on the connection. */

      net_receive(acceptsd);

      printf("net_reader: Closing sd=%d\n", acceptsd);
      close(acceptsd);
    }

#ifdef POLL_HAVE_SOLINGER
errout_with_acceptsd:
  close(acceptsd);
#endif
errout_with_listensd:
  close(listensd);
errout:
  return NULL;
}
예제 #3
0
void *net_listener(pthread_addr_t pvarg)
{
  struct net_listener_s nls;
  struct timeval timeout;
  int nsds;
  int ret;
  int i;

  /* Configure uIP */

  net_configure();

  /* Set up a listening socket */

  memset(&nls, 0, sizeof(struct net_listener_s));
  if (!net_mksocket(&nls))
    {
       return (void*)1;
    }

  /* Initialize the 'master' file descriptor set */

  FD_ZERO(&nls.master);
  nls.mxsd = nls.listensd;
  FD_SET(nls.listensd, &nls.master);

  /* Set up a 3 second timeout */

  timeout.tv_sec  = NET_LISTENER_DELAY;
  timeout.tv_usec = 0;

  /* Loop waiting for incoming connections or for incoming data
   * on any of the connect sockets.
   */

  for (;;)
    {
      /* Wait on select */

      message("net_listener: Calling select(), listener sd=%d\n", nls.listensd);
      memcpy(&nls.working, &nls.master, sizeof(fd_set));
      ret = select(nls.mxsd + 1, (FAR fd_set*)&nls.working, (FAR fd_set*)NULL, (FAR fd_set*)NULL, &timeout);
      if (ret < 0)
        {
          message("net_listener: select failed: %d\n", errno);
          break;
        }

      /* Check for timeout */

      if (ret == 0)
        {
          message("net_listener: Timeout\n");
          continue;
        }

      /* Find which descriptors caused the wakeup */

      nsds = ret;
      for (i = 0; i <= nls.mxsd && nsds > 0; i++)
        {
          /* Is this descriptor ready? */

          if (FD_ISSET(i, &nls.working))
            {
              /* Yes, is it our listener? */

              message("net_listener: Activity on sd=%d\n", i);

              nsds--;
              if (i == nls.listensd)
                {
                  (void)net_connection(&nls);
                }
              else
                {
                  net_incomingdata(&nls, i);
                }
            }
        }
    }

  /* Cleanup */

#if 0 /* Don't get here */
   for (i = 0; i <= nls.mxsd; +i++)
    {
      if (FD_ISSET(i, &nls.master))
        {
          close(i);
        }
    }
#endif
  return NULL;  /* Keeps some compilers from complaining */
}