Exemplo n.º 1
0
/*---------------------------------------------------------------------------*/
void
tcp_unlisten(uint16_t port)
{
  static unsigned char i;
  struct listenport *l;

  l = s.listenports;
  for(i = 0; i < UIP_LISTENPORTS; ++i) {
    if(l->port == port &&
       l->p == PROCESS_CURRENT()) {
      l->port = 0;
      uip_unlisten(port);
      break;
    }
    ++l;
  }
}
Exemplo n.º 2
0
/*---------------------------------------------------------------------------*/
void
tcp_unlisten(uint16_t port,uint8_t conn_id)
{
  static unsigned char i;
  struct listenport *l;

  l = s.listenports;
  for(i = 0; i < UIP_LISTENPORTS; ++i) {
    if(l->port == port &&
       l->conn_id == conn_id) {
      l->port = 0;
      uip_unlisten(port);
      break;
    }
    ++l;
  }
}
Exemplo n.º 3
0
static int sockClose(UosFile* file)
{
  P_ASSERT("sockWrite", file->fs->cf == &netFSConf);
  NetSock* sock = (NetSock*)file->fsPriv;

  posMutexLock(sock->mutex);

  if (sock->state == NET_SOCK_BUSY) {

    sock->state = NET_SOCK_CLOSE;

    dataToSend = 1;
    posSemaSignal(uipGiant);

    while (sock->state == NET_SOCK_CLOSE) {

      posMutexUnlock(sock->mutex);
      posFlagGet(sock->uipChange, POSFLAG_MODE_GETMASK);
      posMutexLock(sock->mutex);
    }
  }

  if (sock->state == NET_SOCK_LISTENING) {

    posMutexLock(uipMutex);
    uip_unlisten(sock->port);
    posMutexUnlock(uipMutex);

    sock->port = 0;
    sock->state = NET_SOCK_CLOSE_OK;
  }

  P_ASSERT("CloseState", (sock->state == NET_SOCK_PEER_CLOSED ||
                          sock->state == NET_SOCK_PEER_ABORTED || 
                          sock->state == NET_SOCK_CLOSE_OK));

  netSockFree(file);
  return 0;
}
Exemplo n.º 4
0
/*---------------------------------------------------------------------------*/
static void
eventhandler(process_event_t ev, process_data_t data)
{
#if UIP_TCP
    static unsigned char i;
    register struct listenport *l;
#endif /*UIP_TCP*/
    struct process *p;

    switch(ev) {
    case PROCESS_EVENT_EXITED:
        /* This is the event we get if a process has exited. We go through
           the TCP/IP tables to see if this process had any open
           connections or listening TCP ports. If so, we'll close those
           connections. */

        p = (struct process *)data;
#if UIP_TCP
        l = s.listenports;
        for(i = 0; i < UIP_LISTENPORTS; ++i) {
            if(l->p == p) {
                uip_unlisten(l->port);
                l->port = 0;
                l->p = PROCESS_NONE;
            }
            ++l;
        }

        {
            struct uip_conn *cptr;

            for(cptr = &uip_conns[0]; cptr < &uip_conns[UIP_CONNS]; ++cptr) {
                if(cptr->appstate.p == p) {
                    cptr->appstate.p = PROCESS_NONE;
                    cptr->tcpstateflags = UIP_CLOSED;
                }
            }
        }
#endif /* UIP_TCP */
#if UIP_UDP
        {
            struct uip_udp_conn *cptr;

            for(cptr = &uip_udp_conns[0];
                    cptr < &uip_udp_conns[UIP_UDP_CONNS]; ++cptr) {
                if(cptr->appstate.p == p) {
                    cptr->lport = 0;
                }
            }
        }
#endif /* UIP_UDP */
        break;

    case PROCESS_EVENT_TIMER:
        /* We get this event if one of our timers have expired. */
    {
        /* Check the clock so see if we should call the periodic uIP
           processing. */
        if(data == &periodic &&
                etimer_expired(&periodic)) {
#if UIP_TCP
            for(i = 0; i < UIP_CONNS; ++i) {
                if(uip_conn_active(i)) {
                    /* Only restart the timer if there are active
                       connections. */
                    etimer_restart(&periodic);
                    uip_periodic(i);
#if UIP_CONF_IPV6
                    tcpip_ipv6_output();
#else
                    if(uip_len > 0) {
                        PRINTF("tcpip_output from periodic len %d\n", uip_len);
                        tcpip_output();
                        PRINTF("tcpip_output after periodic len %d\n", uip_len);
                    }
#endif /* UIP_CONF_IPV6 */
                }
            }
#endif /* UIP_TCP */
#if UIP_CONF_IP_FORWARD
            uip_fw_periodic();
#endif /* UIP_CONF_IP_FORWARD */
        }

#if UIP_CONF_IPV6
#if UIP_CONF_IPV6_REASSEMBLY
        /*
         * check the timer for reassembly
         */
        if(data == &uip_reass_timer &&
                etimer_expired(&uip_reass_timer)) {
            uip_reass_over();
            tcpip_ipv6_output();
        }
#endif /* UIP_CONF_IPV6_REASSEMBLY */
        /*
         * check the different timers for neighbor discovery and
         * stateless autoconfiguration
         */
        /*if(data == &uip_ds6_timer_periodic &&
           etimer_expired(&uip_ds6_timer_periodic)) {
          uip_ds6_periodic();
          tcpip_ipv6_output();
        }*/
#if !UIP_CONF_ROUTER
        if(data == &uip_ds6_timer_rs &&
                etimer_expired(&uip_ds6_timer_rs)) {
            uip_ds6_send_rs();
            tcpip_ipv6_output();
        }
#endif /* !UIP_CONF_ROUTER */
        if(data == &uip_ds6_timer_periodic &&
                etimer_expired(&uip_ds6_timer_periodic)) {
            uip_ds6_periodic();
            tcpip_ipv6_output();
        }
#endif /* UIP_CONF_IPV6 */
    }
    break;

#if UIP_TCP
    case TCP_POLL:
        if(data != NULL) {
            uip_poll_conn(data);
#if UIP_CONF_IPV6
            tcpip_ipv6_output();
#else /* UIP_CONF_IPV6 */
            if(uip_len > 0) {
                PRINTF("tcpip_output from tcp poll len %d\n", uip_len);
                tcpip_output();
            }
#endif /* UIP_CONF_IPV6 */
            /* Start the periodic polling, if it isn't already active. */
            start_periodic_tcp_timer();
        }
        break;
#endif /* UIP_TCP */
#if UIP_UDP
    case UDP_POLL:
        if(data != NULL) {
            uip_udp_periodic_conn(data);
#if UIP_CONF_IPV6
            tcpip_ipv6_output();
#else
            if(uip_len > 0) {
                tcpip_output();
            }
#endif /* UIP_UDP */
        }
        break;
#endif /* UIP_UDP */

    case PACKET_INPUT:
        packet_input();
        break;
    };
}
Exemplo n.º 5
0
int psock_close(FAR struct socket *psock)
{
  int err;

  /* Verify that the sockfd corresponds to valid, allocated socket */

  if (!psock || psock->s_crefs <= 0)
    {
      err = EBADF;
      goto errout;
    }

  /* We perform the uIP close operation only if this is the last count on the socket.
   * (actually, I think the socket crefs only takes the values 0 and 1 right now).
   */

  if (psock->s_crefs <= 1)
    {
      /* Perform uIP side of the close depending on the protocol type */

      switch (psock->s_type)
        {
#ifdef CONFIG_NET_TCP
          case SOCK_STREAM:
            {
              struct uip_conn *conn = psock->s_conn;

              /* Is this the last reference to the connection structure (there
               * could be more if the socket was dup'ed.
               */

              if (conn->crefs <= 1)
                {
                  /* Yes... free the connection structure */

                  uip_unlisten(conn);          /* No longer accepting connections */
                  netclose_disconnect(psock);  /* Break any current connections */
                  conn->crefs = 0;             /* No more references on the connection */
                  uip_tcpfree(conn);           /* Free uIP resources */
                }
              else
                {
                  /* No.. Just decrement the reference count */

                  conn->crefs--;
                }
            }
            break;
#endif

#ifdef CONFIG_NET_UDP
          case SOCK_DGRAM:
            {
              struct uip_udp_conn *conn = psock->s_conn;

              /* Is this the last reference to the connection structure (there
               * could be more if the socket was dup'ed.
               */

              if (conn->crefs <= 1)
                {
                  /* Yes... free the connection structure */

                  conn->crefs = 0;             /* No more references on the connection */
                  uip_udpfree(psock->s_conn);  /* Free uIP resources */
                }
              else
                {
                  /* No.. Just decrement the reference count */

                  conn->crefs--;
                }
            }
            break;
#endif

          default:
            err = EBADF;
            goto errout;
        }
    }

  /* Then release our reference on the socket structure containing the connection */

  sock_release(psock);
  return OK;

errout:
  errno = err;
  return ERROR;
}
Exemplo n.º 6
0
void srv_unlisten(uint16_t port)
{
	uip_unlisten(HTONS(port));
}
Exemplo n.º 7
0
/* -------------------------------------------------------------------------- */
void xtcpd_unlisten(int linknum, int port_number){
  unregister_listener(tcp_listeners, linknum, port_number, NUM_TCP_LISTENERS);
  uip_unlisten(HTONS(port_number));
}