Exemplo n.º 1
0
Arquivo: main.cpp Projeto: nrj123/pvb
void init(int ac, char **av)
{
  setlocale(LC_NUMERIC, "C");
  opt.arg_debug           = 0;     // default command line args
  opt.arg_localini        = 0;
  opt.arg_ini[0]          = '\0';
  opt.arg_font[0]         = '\0';
  opt.arg_host[0]         = '\0';
  opt.arg_disable         = 0;
  opt.arg_x               = -1;
  opt.arg_y               = -1;
  opt.arg_w               = -1;
  opt.arg_h               = -1;
  opt.arg_log             = 0;
  opt.arg_fillbackground  = 0;
  for(int i=0; i<ac; i++)  // read command line args
  {
    if(strncmp(av[i],"-h",2) == 0 || strncmp(av[i],"--",2) == 0)
    {
      printf("pvbrowser %s (C) Lehrig Software Engineering, [email protected]\n", VERSION);
      printf("usage:   pvbrowser <-debug<=level>> <-log> <-ini=filename> <-font=name<:size>> <host<:port></mask>> <-disable> <-geometry=x:y:w:h> <-global_strut=width:height> <-delay=milliseconds>\n");
      printf("example: pvbrowser\n");
      printf("example: pvbrowser localhost\n");
      printf("example: pvbrowser localhost:5050\n");
      printf("example: pvbrowser -font=courier localhost\n");
      printf("example: pvbrowser -font=arial:14 localhost:5050 -disable\n");
      printf("example: pvbrowser -geometry=0:0:640:480\n");
      printf("example: pvbrowser -global_strut=50:50 # set minimum size for embedded systems\n");
      exit(0);
    }
    if(strncmp(av[i],"-debug",6) == 0)
    {
      opt.arg_debug = 1; // print debugging info
      if(strncmp(av[i],"-debug=",7) == 0)
      {
        sscanf(av[i],"-debug=%d",&opt.arg_debug);
      }
    }
    if(strncmp(av[i],"-log",4) == 0)
    {
      opt.arg_log = 1; // print logging info
    }
    if(strncmp(av[i],"-fillbackground",15) == 0)
    {
      opt.arg_fillbackground = 1; // murnleitner special
    }
    if(strncmp(av[i],"-ini=",5) == 0)
    {
      if(strlen(av[i]) < MAXOPT)
      {
        const char *arg = av[i];
        opt.arg_localini = 1; // use inifile in local directory
        strcpy(opt.arg_ini,&arg[5]);
      }
    }
    if(strncmp(av[i],"-font=",6) == 0)
    {
      sscanf(av[i],"-font=%s",opt.arg_font); // use font from command line
    }
    if(strncmp(av[i],"-disable",8) == 0)
    {
      opt.arg_disable = 1; // disable some menus
    }
    if(strncmp(av[i],"-geometry=",10) == 0)
    {
      sscanf(av[i],"-geometry=%d:%d:%d:%d",&opt.arg_x,&opt.arg_y,&opt.arg_w,&opt.arg_h); // define geometry of window
    }
    if(i>0 && strncmp(av[i],"-",1) != 0)
    {
      strcpy(opt.arg_host,av[i]);
    }
    if(strncmp(av[i],"-delay=",7) == 0) // delay startup by milliseconds
    {
      int delay = 0;
      sscanf(av[i],"-delay=%d", &delay);
      if(delay < 0) delay = 0;
      if(opt.arg_debug) printf("delay startup by %d milliseconds\n", delay);
      tcp_sleep(delay);
    }
    if(strncmp(av[i],"-global_strut=",14) == 0) // set minimum size of some widgets on embedded systems
    {
      int width,height;
      sscanf(av[i],"-global_strut=%d:%d", &width, &height);
      QSize strut(width,height);
      QApplication::setGlobalStrut(strut);
    }
  }
}
Exemplo n.º 2
0
long
t_accept(long s, 
   struct sockaddr * addr,
   int * addrlen)
{
#ifdef SOCKDEBUG
   char logbuf[10];
#endif
   struct socket *   so;
   struct mbuf *  nam;

   so = LONG2SO(s);
   SOC_CHECK(so);
   DOMAIN_CHECK(so, *addrlen);

   so->so_error = 0;
   INET_TRACE (INETM_SOCKET,
      ("INET:accept:so %x so_qlen %d so_state %x\n", so, so->so_qlen, so->so_state));
   if ((so->so_options & SO_ACCEPTCONN) == 0)
   {
      so->so_error = EINVAL;
#ifdef SOCKDEBUG
      sprintf(logbuf, "t_accept[%d]: %d", __LINE__, so->so_error);
      glog_with_type(LOG_TYPE_DEBUG, logbuf, 1);
#endif
      return SOCKET_ERROR;
   }
   if ((so->so_state & SS_NBIO) && so->so_qlen == 0)
   {
      so->so_error = EWOULDBLOCK;
#ifdef SOCKDEBUG
      sprintf(logbuf, "t_accept[%d]: %d", __LINE__, so->so_error);
      glog_with_type(LOG_TYPE_DEBUG, logbuf, 1);
#endif
      return SOCKET_ERROR;
   }
   LOCK_NET_RESOURCE(NET_RESID);
   while (so->so_qlen == 0 && so->so_error == 0)
   {
      if (so->so_state & SS_CANTRCVMORE)
      {
         so->so_error = ECONNABORTED;
         UNLOCK_NET_RESOURCE(NET_RESID);
         return SOCKET_ERROR;
      }
      tcp_sleep ((char *)&so->so_timeo);
   }
   if (so->so_error)
   {
#ifdef SOCKDEBUG
      sprintf(logbuf, "t_accept[%d]: %d", __LINE__, so->so_error);
      glog_with_type(LOG_TYPE_DEBUG, logbuf, 1);
#endif
      UNLOCK_NET_RESOURCE(NET_RESID);
      return SOCKET_ERROR;
   }
   nam = m_getwithdata (MT_SONAME, sizeof (struct sockaddr));
   if (nam == NULL) 
   {
      UNLOCK_NET_RESOURCE(NET_RESID);
      so->so_error = ENOMEM;
#ifdef SOCKDEBUG
      sprintf(logbuf, "t_accept[%d]: %d", __LINE__, so->so_error);
      glog_with_type(LOG_TYPE_DEBUG, logbuf, 1);
#endif
      return SOCKET_ERROR;
   }
   { 
      struct socket *aso = so->so_q;
      if (soqremque (aso, 1) == 0)
         panic("accept");
      so = aso;
   }
   (void)soaccept (so, nam);
#ifdef TRACE_DEBUG
   { struct sockaddr_in *sin;
      sin = mtod(nam, struct sockaddr_in *);
      INET_TRACE (INETM_SOCKET, ("INET:accept:done so %lx port %d addr %lx\n",
       so, sin->sin_port, sin->sin_addr.s_addr));
   }
#endif   /* TRACE_INET */
   /* return the addressing info in the passed structure */
   if (addr != NULL)
      MEMCPY(addr, nam->m_data, *addrlen);
   m_freem (nam);
   UNLOCK_NET_RESOURCE(NET_RESID);
   SOC_RANGE(so);
   return SO2LONG(so);
}
Exemplo n.º 3
0
int
t_connect(long s, 
   struct sockaddr * addr,
   int   addrlen)
{
   struct socket *   so;
   struct mbuf *  nam;

   so = LONG2SO(s);
   SOC_CHECK(so);
   DOMAIN_CHECK(so, addrlen);

#ifdef NB_CONNECT
   /* need to test non blocking connect bits in case this is a 
      poll of a previous request */
   if (so->so_state & SS_NBIO)
   {
      if (so->so_state & SS_ISCONNECTING) /* still trying */
      {
         so->so_error = EINPROGRESS;
         return SOCKET_ERROR;
      }
      if (so->so_state & SS_ISCONNECTED)  /* connected OK */
      {
         so->so_error = 0;
         return 0;
      }
      if (so->so_state & SS_WASCONNECTING)
      {
         so->so_state &= ~SS_WASCONNECTING;
         if (so->so_error) /* connect error - maybe timeout */
            return SOCKET_ERROR;
      }
   }
#endif   /*  NB_CONNECT */

   so->so_error = 0;

   if ((nam = sockargs (addr, addrlen, MT_SONAME))
       == NULL)
   {
      so->so_error = ENOMEM;
      return SOCKET_ERROR;
   }

#ifdef TRACE_DEBUG
   { struct sockaddr_in *sin = (struct sockaddr_in *)uap->sap;
      INET_TRACE (INETM_SOCKET, ("INET: connect, port %d addr %lx\n",
       sin->sin_port, sin->sin_addr.s_addr));
   }
#endif   /* TRACE_DEBUG */

   LOCK_NET_RESOURCE(NET_RESID);
   if ((so->so_error = soconnect (so, nam)) != 0)
      goto bad;

#ifdef NB_CONNECT
   /* need to test non blocking connect bits after soconnect() call */
   if ((so->so_state & SS_NBIO)&& (so->so_state & SS_ISCONNECTING))
   {
      so->so_error = EINPROGRESS;
      goto bad;
   }
#endif   /*  NB_CONNECT */
   INET_TRACE (INETM_SOCKET, ("INET: connect, so %x so_state %x so_error %d\n",
    so, so->so_state, so->so_error));

   while ((so->so_state & SS_ISCONNECTING) && so->so_error == 0) 
   {
      tcp_sleep ((char *)&so->so_timeo);
   }
bad:
   if (so->so_error != EINPROGRESS)
      so->so_state &= ~(SS_ISCONNECTING|SS_WASCONNECTING);
   m_freem (nam);

   UNLOCK_NET_RESOURCE(NET_RESID);
   if (so->so_error)
   {
/*      printf("t_connect(): so_error = %d\n", so->so_error);*/
      return SOCKET_ERROR;

   }
      return 0;
}
Exemplo n.º 4
0
int
soclose(struct socket * so)
{
   int   error =  0;
   struct socket *   tmpso;
   unsigned long endtime;

   /* Check whether the closing socket is in the socket queue.  If it is
    * not, return a EINVAL error code to the caller.
    */
   for ((tmpso=(struct socket *)soq.q_head);tmpso != NULL;tmpso=tmpso->next)
   {
      if (so == tmpso)
         break;
   }
   if ( tmpso == NULL)
      return EINVAL;
   INET_TRACE (INETM_SOCKET|INETM_CLOSE,
    ("INET: soclose, so %lx  so_pcb %lx so_state %x so_q %lx\n",
    so, so->so_pcb, so->so_state, so->so_q));
   if (so->so_options & SO_ACCEPTCONN)
   {
      while (so->so_q0 != so)
         (void) soabort(so->so_q0);
      while (so->so_q != so)
         (void) soabort(so->so_q);
   }
   /* for datagram-oriented sockets, dispense with further tests */
   if (so->so_type != SOCK_STREAM)
   { 
      so->so_req = PRU_DETACH;
      error = (*so->so_proto->pr_usrreq)(so,
       (struct mbuf *)0, (struct mbuf *)0);
      goto discard;
   }

   if (so->so_pcb == 0)
      goto discard;
   if (so->so_state & SS_ISCONNECTED) 
   {
      if ((so->so_state & SS_ISDISCONNECTING) == 0) 
      {
         error = sodisconnect(so);
         if (error)
            goto drop;
      }
      if (so->so_options & SO_LINGER) 
      {
         if ((so->so_state & SS_ISDISCONNECTING) &&
             (so->so_state & SS_NBIO))
         {
            goto drop;
         }
         endtime = cticks + (unsigned long)so->so_linger * TPS;         
         while ((so->so_state & SS_ISCONNECTED) && (cticks < endtime))
         {
            tcp_sleep((char *)&so->so_timeo);
         }
      }
      else  /* Linger option not set */
      {
         /* If socket still has send data just return now, leaving the 
          * socket intact so the data can be sent. Socket should be cleaned
          * up later by timers.
          */
         if(so->so_snd.sb_cc)
         {
            so->so_state |= SS_NOFDREF;   /* mark as OK to close */
            return 0;
         }
      }
   }
drop:
   if (so->so_pcb) 
   {
      int   error2;
      so->so_req = PRU_DETACH;
      error2 = (*so->so_proto->pr_usrreq)(so,
       (struct mbuf *)0, (struct mbuf *)0);
      if (error == 0)
         error = error2;
   }
discard:
   if (so->so_state & SS_NOFDREF)
   {
      /* panic("soclose");  - non-fatal - degrade to dtrap() for now */
      dtrap();
   }
   so->so_state |= SS_NOFDREF;
   sofree(so);
   return (error);
}