lwip-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[lwip-users] TCP Echo (sockets) only accepting connection once


From: bbawkon
Subject: [lwip-users] TCP Echo (sockets) only accepting connection once
Date: Sun, 15 Oct 2017 21:38:28 -0700 (MST)

Hello everyone,

I've got lwip basically working (UDP Send, ping, DHCP, etc) under FreeRTOS
on my hardware, but I'm having a heck of a time getting a simple TCP Echo
server to work as expected.

I've separated the listener thread from the worker threads so that more than
one client can connect, but no matter what I do, only the very first
connection is successful.  No other client can connect after the first one
does, and not even the first client can disconnect and then re-connect.

I'm guessing that I'm missing something very simple, but I sure as heck
can't see the forest through the trees here.

If anyone sees anything obvious, please say so.
Thanks,
Ben


--lwipopts.h--
#ifndef __LWIPOPTS_H__
#define __LWIPOPTS_H__

#include "FreeRTOS.h"

#define malloc pvPortMalloc
#define free vPortFree



/*
   -----------------------------------------------
   ---------- TM4C129 lwIP port options ----------
   -----------------------------------------------
*/
#define PHY_PHYS_ADDR                   0
#define EMAC_PHY_CONFIG (EMAC_PHY_TYPE_INTERNAL | EMAC_PHY_INT_MDIX_EN |     
\
                         EMAC_PHY_AN_100B_T_FULL_DUPLEX)
#define NUM_RX_DESCRIPTORS              8           // default is 4
#define NUM_TX_DESCRIPTORS              24          // default is 8



/*
   ----------------------------------
   ---------- PTPD options ----------
   ----------------------------------
*/
#define LWIP_PTPD                       0



/*
   -----------------------------------------------
   ---------- Platform specific locking ----------
   -----------------------------------------------
*/
#define SYS_LIGHTWEIGHT_PROT            1           // default is 0
#define NO_SYS                          0
#define NO_SYS_NO_TIMERS                0

#if !NO_SYS
#define LWIP_COMPAT_MUTEX               1
#define RTOS_FREERTOS                   1
#endif /* !NO_SYS */

#define MEMCPY(dst,src,len)             memcpy(dst,src,len)
#define SMEMCPY(dst,src,len)            memcpy(dst,src,len)



/*
   ------------------------------------
   ---------- Memory options ----------
   ------------------------------------
*/
#define MEM_LIBC_MALLOC                 0
#define MEMP_MEM_MALLOC                 0
#define MEM_ALIGNMENT                   4           // default is 1
#define MEM_SIZE                        (32 * 1024) // default is 1600, was
16K
#define MEMP_SEPARATE_POOLS             0
#define MEMP_OVERFLOW_CHECK             0
#define MEMP_SANITY_CHECK               0
#define MEM_USE_POOLS                   0
#define MEM_USE_POOLS_TRY_BIGGER_POOL   0
#define MEMP_USE_CUSTOM_POOLS           MEM_USE_POOLS
#define LWIP_ALLOW_MEM_FREE_FROM_OTHER_CONTEXT 0



/*
   ------------------------------------------------
   ---------- Internal Memory Pool Sizes ----------
   ------------------------------------------------
*/
#define MEMP_NUM_PBUF                   16
#define MEMP_NUM_RAW_PCB                4
#define MEMP_NUM_UDP_PCB                4
#define MEMP_NUM_TCP_PCB                5
#define MEMP_NUM_TCP_PCB_LISTEN         8
#define MEMP_NUM_TCP_SEG                16
#define MEMP_NUM_REASSDATA              5
#define MEMP_NUM_FRAG_PBUF              15
#define MEMP_NUM_ARP_QUEUE              30
#define MEMP_NUM_IGMP_GROUP             8
#define MEMP_NUM_SYS_TIMEOUT            10    // (LWIP_TCP + IP_REASSEMBLY +
LWIP_ARP + (2*LWIP_DHCP) + LWIP_AUTOIP + LWIP_IGMP + LWIP_DNS + PPP_SUPPORT)
#define MEMP_NUM_NETBUF                 4
#define MEMP_NUM_NETCONN                12
#define MEMP_NUM_TCPIP_MSG_API          8
#define MEMP_NUM_TCPIP_MSG_INPKT        8
#define MEMP_NUM_SNMP_NODE              50
#define MEMP_NUM_SNMP_ROOTNODE          30
#define MEMP_NUM_SNMP_VARBIND           2
#define MEMP_NUM_SNMP_VALUE             3
#define MEMP_NUM_NETDB                  1
#define MEMP_NUM_LOCALHOSTLIST          1
#define MEMP_NUM_PPPOE_INTERFACES       1
#define PBUF_POOL_SIZE                  16



/*
   ---------------------------------
   ---------- ARP options ----------
   ---------------------------------
*/
#define LWIP_ARP                        1

#if LWIP_ARP
#define ARP_TABLE_SIZE                  10
#define ARP_QUEUEING                    1           // default is 0
#define ETHARP_TRUST_IP_MAC             1           // default is 0
#define ETHARP_SUPPORT_VLAN             0
#define LWIP_ETHERNET                   (LWIP_ARP || PPPOE_SUPPORT)
#define ETH_PAD_SIZE                    0
#define ETHARP_SUPPORT_STATIC_ENTRIES   0
#endif



/*
   --------------------------------
   ---------- IP options ----------
   --------------------------------
*/
#define IP_FORWARD                      0
#define IP_OPTIONS_ALLOWED              1
#define IP_REASSEMBLY                   1           // default is 1
#define IP_FRAG                         1           // default is 1
#define IP_REASS_MAXAGE                 3
#define IP_REASS_MAX_PBUFS              10
#define IP_FRAG_USES_STATIC_BUF         1           // default is 0

#if IP_FRAG_USES_STATIC_BUF && !defined(IP_FRAG_MAX_MTU)
#define IP_FRAG_MAX_MTU                 1500
#endif

#define IP_DEFAULT_TTL                  255
#define IP_SOF_BROADCAST                0
#define IP_SOF_BROADCAST_RECV           0
#define IP_FORWARD_ALLOW_TX_ON_RX_NETIF 0
#define LWIP_RANDOMIZE_INITIAL_LOCAL_PORTS 0



/*
   ----------------------------------
   ---------- ICMP options ----------
   ----------------------------------
*/
#define LWIP_ICMP                       1

#if LWIP_ICMP
#define ICMP_TTL                       (IP_DEFAULT_TTL)
#define LWIP_BROADCAST_PING             0
#define LWIP_MULTICAST_PING             0
#endif



/*
   ---------------------------------
   ---------- RAW options ----------
   ---------------------------------
*/
#define LWIP_RAW                        1
#define RAW_TTL                        (IP_DEFAULT_TTL)



/*
   ----------------------------------
   ---------- DHCP options ----------
   ----------------------------------
*/
#define LWIP_DHCP                       1           // default is 0
#define DHCP_DOES_ARP_CHECK             ((LWIP_DHCP) && (LWIP_ARP))



/*
   ------------------------------------
   ---------- AUTOIP options ----------
   ------------------------------------
*/
#define LWIP_AUTOIP                     1           // default is 0
#define LWIP_DHCP_AUTOIP_COOP           ((LWIP_DHCP) && (LWIP_AUTOIP))  //
default is 0
#define LWIP_DHCP_AUTOIP_COOP_TRIES     5           // default is 9



/*
   ----------------------------------
   ---------- SNMP options ----------
   ----------------------------------
*/
#define LWIP_SNMP                       0

#if LWIP_SNMP
#define SNMP_CONCURRENT_REQUESTS        1
#define SNMP_TRAP_DESTINATIONS          1
#define SNMP_PRIVATE_MIB                0
#define SNMP_SAFE_REQUESTS              1
#define SNMP_MAX_OCTET_STRING_LEN       127
#define SNMP_MAX_TREE_DEPTH             15
#define SNMP_MAX_VALUE_SIZE            
LWIP_MAX((SNMP_MAX_OCTET_STRING_LEN)+1, sizeof(s32_t)*(SNMP_MAX_TREE_DEPTH))
#endif



/*
   ----------------------------------
   ---------- IGMP options ----------
   ----------------------------------
*/
#define LWIP_IGMP                       0



/*
   ----------------------------------
   ---------- DNS options -----------
   ----------------------------------
*/
#define LWIP_DNS                        0

#if LWIP_DNS
#define DNS_TABLE_SIZE                  4
#define DNS_MAX_NAME_LENGTH             256
#define DNS_MAX_SERVERS                 2
#define DNS_DOES_NAME_CHECK             1
#define DNS_MSG_SIZE                    512
#define DNS_LOCAL_HOSTLIST              0
#define DNS_LOCAL_HOSTLIST_IS_DYNAMIC   0
#endif


/*
   ---------------------------------
   ---------- UDP options ----------
   ---------------------------------
*/
#define LWIP_UDP                        1
#define LWIP_UDPLITE                    0
#define UDP_TTL                         (IP_DEFAULT_TTL)
#define LWIP_NETBUF_RECVINFO            0



/*
   ---------------------------------
   ---------- TCP options ----------
   ---------------------------------
*/
#define LWIP_TCP                        1

#if LWIP_TCP
#define TCP_TTL                         (IP_DEFAULT_TTL)
#define TCP_WND                         (4 * TCP_MSS)   // default is (4 *
TCP_MSS)
#define TCP_MAXRTX                      12
#define TCP_SYNMAXRTX                   6
#define TCP_QUEUE_OOSEQ                 (LWIP_TCP)
#define TCP_MSS                         1460            // default is 536
#define TCP_CALCULATE_EFF_SEND_MSS      1
#define TCP_SND_BUF                     (2 * TCP_MSS)   // default is (2 *
TCP_MSS)
#define TCP_SND_QUEUELEN                ((4 * (TCP_SND_BUF) + (TCP_MSS -
1))/(TCP_MSS))
#define TCP_SNDLOWAT                    ((TCP_SND_BUF)/2)
#define TCP_SNDQUEUELOWAT               ((TCP_SND_QUEUELEN)/2)
#define TCP_OOSEQ_MAX_BYTES             0
#define TCP_OOSEQ_MAX_PBUFS             0
#define TCP_LISTEN_BACKLOG              0
#if TCP_LISTEN_BACKLOG
#error "TCP_LISTEN_BACKLOG must be set to 0. Bug in lwIP v1.4.1.
http://comments.gmane.org/gmane.network.lwip.general/7286";
#endif
#define TCP_DEFAULT_LISTEN_BACKLOG      0xff
#define TCP_OVERSIZE                    TCP_MSS
#define LWIP_TCP_TIMESTAMPS             0
#define TCP_WND_UPDATE_THRESHOLD        (TCP_WND / 4)

#endif /* LWIP_TCP */



/*
   ---------------------------------
   ---------- API options ----------
   ---------------------------------
*/
#define LWIP_EVENT_API                  0
#define LWIP_CALLBACK_API               1

#if (LWIP_EVENT_API) && (LWIP_CALLBACK_API)
#error "Only one of EVENT_API or CALLBACK_API can be defined. See opt.h"
#endif


/*
   ----------------------------------
   ---------- Pbuf options ----------
   ----------------------------------
*/
#define PBUF_LINK_HLEN                  16
#define PBUF_POOL_BUFSIZE              
LWIP_MEM_ALIGN_SIZE(TCP_MSS+40+PBUF_LINK_HLEN)



/*
   ------------------------------------------------
   ---------- Network Interfaces options ----------
   ------------------------------------------------
*/
#define LWIP_NETIF_HOSTNAME             0
#define LWIP_NETIF_API                  1
#define LWIP_NETIF_STATUS_CALLBACK      0
#define LWIP_NETIF_LINK_CALLBACK        0
#define LWIP_NETIF_REMOVE_CALLBACK      0
#define LWIP_NETIF_HWADDRHINT           0
#define LWIP_NETIF_LOOPBACK             0
#define LWIP_LOOPBACK_MAX_PBUFS         0
#define LWIP_NETIF_LOOPBACK_MULTITHREADING    (!NO_SYS)
#define LWIP_NETIF_TX_SINGLE_PBUF             0



/*
   ------------------------------------
   ---------- LOOPIF options ----------
   ------------------------------------
*/
#define LWIP_HAVE_LOOPIF                0
//#define LWIP_LOOPIF_MULTITHREADING      1



/*
   ------------------------------------
   ---------- SLIPIF options ----------
   ------------------------------------
*/
#define LWIP_HAVE_SLIPIF                0



/*
   ------------------------------------
   ---------- Thread options ----------
   ------------------------------------
*/
#define TCPIP_THREAD_NAME              "tcpip_thread"
#define TCPIP_THREAD_STACKSIZE          2048
#define TCPIP_THREAD_PRIO               3
#define TCPIP_MBOX_SIZE                 32
// #define SLIPIF_THREAD_NAME             "slipif_loop"
// #define SLIPIF_THREAD_STACKSIZE         0
// #define SLIPIF_THREAD_PRIO              3
// #define PPP_THREAD_NAME                "pppInputThread"
// #define PPP_THREAD_STACKSIZE            0
// #define PPP_THREAD_PRIO                 3
#define DEFAULT_THREAD_NAME            "lwIP"
#define DEFAULT_THREAD_STACKSIZE        2048
#define DEFAULT_THREAD_PRIO             3
#define DEFAULT_RAW_RECVMBOX_SIZE       4
#define DEFAULT_UDP_RECVMBOX_SIZE       4
#define DEFAULT_TCP_RECVMBOX_SIZE       40
#define DEFAULT_ACCEPTMBOX_SIZE         4



/*
   ----------------------------------------------
   ---------- Sequential layer options ----------
   ----------------------------------------------
*/
#define LWIP_NETCONN                    1
#define LWIP_TCPIP_TIMEOUT              1



/*
   ------------------------------------
   ---------- Socket options ----------
   ------------------------------------
*/
#define LWIP_SOCKET                     1

#if LWIP_SOCKET
#define LWIP_COMPAT_SOCKETS             0
#define LWIP_POSIX_SOCKETS_IO_NAMES     1
#define LWIP_TCP_KEEPALIVE              0
#define LWIP_SO_SNDTIMEO                0
#define LWIP_SO_RCVTIMEO                0
#define LWIP_SO_RCVBUF                  0
#define RECV_BUFSIZE_DEFAULT            INT_MAX
#define SO_REUSE                        1
#define SO_REUSE_RXTOALL                0
#endif



/*
   ----------------------------------------
   ---------- Statistics options ----------
   ----------------------------------------
*/
#define LWIP_STATS                      1

#if LWIP_STATS
#define LWIP_STATS_DISPLAY              0
#define LINK_STATS                      1
#define ETHARP_STATS                    (LWIP_ARP)
#define IP_STATS                        1
#define IPFRAG_STATS                    (IP_REASSEMBLY || IP_FRAG)
#define ICMP_STATS                      1
#define IGMP_STATS                      (LWIP_IGMP)
#define UDP_STATS                       (LWIP_UDP)
#define TCP_STATS                       (LWIP_TCP)
#define MEM_STATS                       ((MEM_LIBC_MALLOC == 0) &&
(MEM_USE_POOLS == 0))
#define MEMP_STATS                      (MEMP_MEM_MALLOC == 0)
#define PBUF_STATS                      1
#define SYS_STATS                       (NO_SYS == 0)
#define LWIP_STATS_LARGE                1
#endif /* LWIP_STATS */



/*
   ---------------------------------
   ---------- PPP options ----------
   ---------------------------------
*/
#define PPP_SUPPORT                     0
#define PPPOE_SUPPORT                   0
#define PPPOS_SUPPORT                   PPP_SUPPORT

#if PPP_SUPPORT

#define NUM_PPP                         1
#define PAP_SUPPORT                     0
#define CHAP_SUPPORT                    0
#define MSCHAP_SUPPORT                  0
#define CBCP_SUPPORT                    0
#define CCP_SUPPORT                     0
#define VJ_SUPPORT                      0
#define MD5_SUPPORT                     0

/*
 * Timeouts
 */
#define FSM_DEFTIMEOUT                  6       /* Timeout time in seconds
*/
#define FSM_DEFMAXTERMREQS              2       /* Maximum Terminate-Request
transmissions */
#define FSM_DEFMAXCONFREQS              10      /* Maximum Configure-Request
transmissions */
#define FSM_DEFMAXNAKLOOPS              5       /* Maximum number of nak
loops */
#define UPAP_DEFTIMEOUT                 6       /* Timeout (seconds) for
retransmitting req */
#define UPAP_DEFREQTIME                 30      /* Time to wait for auth-req
from peer */
#define CHAP_DEFTIMEOUT                 6       /* Timeout time in seconds
*/
#define CHAP_DEFTRANSMITS               10      /* max # times to send
challenge */
#define LCP_ECHOINTERVAL                0
#define LCP_MAXECHOFAILS                3
#define PPP_MAXIDLEFLAG                 100

/*
 * Packet sizes
 *
 * Note - lcp shouldn't be allowed to negotiate stuff outside these
 *    limits.  See lcp.h in the pppd directory.
 * (XXX - these constants should simply be shared by lcp.c instead
 *    of living in lcp.h)
 */
#define PPP_MTU                         1500    /* Default MTU (size of Info
field) */
/* #define PPP_MAXMTU  65535 - (PPP_HDRLEN + PPP_FCSLEN) */
#define PPP_MAXMTU                      1500    /* Largest MTU we allow */
#define PPP_MINMTU                      64
#define PPP_MRU                         1500    /* default MRU = max length
of info field */
#define PPP_MAXMRU                      1500    /* Largest MRU we allow */
#define PPP_DEFMRU                      296     /* Try for this */
#define PPP_MINMRU                      128     /* No MRUs below this */
#define MAXNAMELEN                      256     /* max length of hostname or
name for auth */
#define MAXSECRETLEN                    256     /* max length of password or
secret */
    
#endif /* PPP_SUPPORT */



/*
   --------------------------------------
   ---------- Checksum options ----------
   --------------------------------------
*/
#define CHECKSUM_GEN_IP                 1
#define CHECKSUM_GEN_UDP                1
#define CHECKSUM_GEN_TCP                1
#define CHECKSUM_GEN_ICMP               0  
#define CHECKSUM_CHECK_IP               1
#define CHECKSUM_CHECK_UDP              1
#define CHECKSUM_CHECK_TCP              1
#define LWIP_CHECKSUM_ON_COPY           0 



/*
   ---------------------------------------
   ---------- Debugging options ----------
   ---------------------------------------
*/
/* Define default values for unconfigured parameters. */
// 1 == To suppress some errors for now (no debug output)
#define LWIP_NOASSERT                   1
#define LWIP_DEBUG                      0

#define LWIP_DBG_MIN_LEVEL              LWIP_DBG_LEVEL_ALL
//#define LWIP_DBG_MIN_LEVEL              LWIP_DBG_LEVEL_WARNING
//#define LWIP_DBG_MIN_LEVEL              LWIP_DBG_LEVEL_SERIOUS
//#define LWIP_DBG_MIN_LEVEL              LWIP_DBG_LEVEL_SEVERE

//#define LWIP_DBG_TYPES_ON               LWIP_DBG_ON
#define LWIP_DBG_TYPES_ON              
(LWIP_DBG_ON|LWIP_DBG_TRACE|LWIP_DBG_STATE|LWIP_DBG_FRESH)

#if LWIP_DEBUG
#define ETHARP_DEBUG                    LWIP_DBG_OFF    // ETHARP_DEBUG:
Enable debugging in etharp.c.
#define NETIF_DEBUG                     LWIP_DBG_OFF    // NETIF_DEBUG:
Enable debugging in netif.c.
#define PBUF_DEBUG                      LWIP_DBG_OFF    // PBUF_DEBUG:
Enable debugging in pbuf.c.
#define API_LIB_DEBUG                   LWIP_DBG_OFF    // API_LIB_DEBUG:
Enable debugging in api_lib.c.
#define API_MSG_DEBUG                   LWIP_DBG_OFF    // API_MSG_DEBUG:
Enable debugging in api_msg.c.
#define SOCKETS_DEBUG                   LWIP_DBG_OFF    // SOCKETS_DEBUG:
Enable debugging in sockets.c.
#define ICMP_DEBUG                      LWIP_DBG_OFF    // ICMP_DEBUG:
Enable debugging in icmp.c.
#define IGMP_DEBUG                      LWIP_DBG_OFF    // IGMP_DEBUG:
Enable debugging in igmp.c.
#define INET_DEBUG                      LWIP_DBG_OFF    // INET_DEBUG:
Enable debugging in inet.c.
#define IP_DEBUG                        LWIP_DBG_OFF
#define IP_REASS_DEBUG                  LWIP_DBG_OFF    // IP_REASS_DEBUG:
Enable debugging in ip_frag.c for both frag & reass.
#define RAW_DEBUG                       LWIP_DBG_OFF    // RAW_DEBUG: Enable
debugging in raw.c.
#define MEM_DEBUG                       LWIP_DBG_OFF    // MEM_DEBUG: Enable
debugging in mem.c.
#define MEMP_DEBUG                      LWIP_DBG_OFF    // MEMP_DEBUG:
Enable debugging in memp.c.
#define SYS_DEBUG                       LWIP_DBG_OFF    // SYS_DEBUG: Enable
debugging in sys.c.
#define TIMERS_DEBUG                    LWIP_DBG_OFF    // TIMERS_DEBUG:
Enable debugging in timers.c.

#define TCP_DEBUG                       LWIP_DBG_OFF
#define TCP_INPUT_DEBUG                 LWIP_DBG_OFF    // TCP_INPUT_DEBUG:
Enable debugging in tcp_in.c for incoming debug.
#define TCP_FR_DEBUG                    LWIP_DBG_OFF    // TCP_FR_DEBUG:
Enable debugging in tcp_in.c for fast retransmit.
#define TCP_RTO_DEBUG                   LWIP_DBG_OFF
#define TCP_CWND_DEBUG                  LWIP_DBG_OFF
#define TCP_WND_DEBUG                   LWIP_DBG_OFF    // TCP_WND_DEBUG:
Enable debugging in tcp_in.c for window updating.
#define TCP_OUTPUT_DEBUG                LWIP_DBG_OFF    // TCP_OUTPUT_DEBUG:
Enable debugging in tcp_out.c output functions.
#define TCP_RST_DEBUG                   LWIP_DBG_OFF
#define TCP_QLEN_DEBUG                  LWIP_DBG_OFF

#define UDP_DEBUG                       LWIP_DBG_OFF
#define TCPIP_DEBUG                     LWIP_DBG_OFF    // TCPIP_DEBUG:
Enable debugging in tcpip.c.
#define PPP_DEBUG                       LWIP_DBG_OFF
#define SLIP_DEBUG                      LWIP_DBG_OFF    // SLIP_DEBUG:
Enable debugging in slipif.c.
#define DHCP_DEBUG                      LWIP_DBG_OFF    // DHCP_DEBUG:
Enable debugging in dhcp.c.
#define AUTOIP_DEBUG                    LWIP_DBG_OFF    // AUTOIP_DEBUG:
Enable debugging in autoip.c.
#define SNMP_MSG_DEBUG                  LWIP_DBG_OFF
#define SNMP_MIB_DEBUG                  LWIP_DBG_OFF
#define DNS_DEBUG                       LWIP_DBG_OFF
#endif

#define LWIP_TIMEVAL_PRIVATE    0

#endif /* __LWIPOPTS_H__ */


--TelnetControl.c--
#include <stdio.h>
#include <stdint.h>
#include <stdbool.h>
#include <string.h>

#include "inc/hw_memmap.h"
#include "inc/hw_types.h"
#include "driverlib/gpio.h"
#include "driverlib/rom.h"

#include "config/lwiplib.h"
#include "config/lwipopts.h"

#include "TelnetControl.h"
#include "priorities.h"
#include "FreeRTOS.h"
#include "task.h"
#include "queue.h"
#include "semphr.h"


#if LWIP_NETCONN

#include "lwip/sys.h"
#include "lwip/api.h"
#include "lwip/sockets.h"
#include "lwip/inet.h"

#define ListenPort      7734
#define STACKSIZE_TELNET_CONTROL_TASK       1024



void TelnetControl_Connection_thread(void *p)
{
                int sd = (int)p;
                int RECV_BUF_SIZE = 512;
                char recv_buf[RECV_BUF_SIZE];
                int n, nwrote;

                while (1) {
                        /* read a max of RECV_BUF_SIZE bytes from socket */
                        if ((n = lwip_read(sd, recv_buf, RECV_BUF_SIZE)) < 0) {
                                break;
                        }

                        /* break if the recved message = "quit" */
                        if (!strncmp(recv_buf, "quit", 4))
                                break;

                        /* break if client closed connection */
                        if (n <= 0)
                                break;

                        /* handle request */
                        if ((nwrote = lwip_write(sd, recv_buf, n)) < 0) {
                                break;
                        }
                }

                /* close connection */
                lwip_close(sd);
                vTaskDelete(NULL);

}



/*-----------------------------------------------------------------------------------*/
static void
TelnetControl_Listener_thread(void *arg)
{
                int sock, new_sd;
                struct sockaddr_in address, remote;
                int size;
                int     optval;
                int optlen = sizeof(optval);

                if ((sock = lwip_socket(AF_INET, SOCK_STREAM, IPPROTO_TCP)) < 0)
                        return;

                address.sin_family = AF_INET;
                address.sin_port = htons(ListenPort);
                address.sin_addr.s_addr = INADDR_ANY;

                if (lwip_bind(sock, (struct sockaddr *)&address, sizeof 
(address)) < 0)
                        return;

                lwip_listen(sock, 20);

                if (lwip_setsockopt(sock, SOL_SOCKET, SO_KEEPALIVE, &optval, 
optlen) < 0)
                        return;

                size = sizeof(remote);

                while (1) {
                        if ((new_sd = lwip_accept(sock, (struct sockaddr 
*)&remote, (socklen_t
*)&size)) > 0) {
                                sys_thread_new("TelnetControl_Connection",
TelnetControl_Connection_thread,
                                        (void*)new_sd,
                                        STACKSIZE_TELNET_CONTROL_TASK,
                                        tskIDLE_PRIORITY + 
PRIORITY_TELNET_CONTROL_TASK);
                                size=sizeof(remote);
                        }
                }
        }

/*-----------------------------------------------------------------------------------*/

uint32_t
TelnetControl_init(void) {

     sys_thread_new("TelnetControl_Listener_thread",
TelnetControl_Listener_thread, NULL, 
     STACKSIZE_TELNET_CONTROL_TASK, tskIDLE_PRIORITY +
PRIORITY_TELNET_CONTROL_TASK);

    // Success.
    return(0);
}


#endif /* LWIP_NETCONN */


--FreeRTOSConfig.h--
#ifndef FREERTOS_CONFIG_H
#define FREERTOS_CONFIG_H



#define configUSE_TIMERS                    1
#define configTIMER_TASK_PRIORITY           4
#define configTIMER_QUEUE_LENGTH            4
#define configTIMER_TASK_STACK_DEPTH        configMINIMAL_STACK_SIZE

#define configUSE_PREEMPTION                1
#define configUSE_IDLE_HOOK                 0
#define configMAX_PRIORITIES                ( 16 )
#define configUSE_TICK_HOOK                 0
#define configCPU_CLOCK_HZ                  ( ( unsigned long ) 120000000 )
#define configTICK_RATE_HZ                  ( ( portTickType ) 1000 )
#define configMINIMAL_STACK_SIZE            ( ( unsigned short ) 200 )
#define configTOTAL_HEAP_SIZE               ( ( size_t ) ( 20240 ) )
#define configMAX_TASK_NAME_LEN             ( 12 )
#define configIDLE_SHOULD_YIELD                     0
#define configQUEUE_REGISTRY_SIZE                   10
#define configUSE_TRACE_FACILITY            1
#define configUSE_16_BIT_TICKS              0
#define configUSE_MUTEXES                   1
#define configUSE_CO_ROUTINES               0
#define configMAX_CO_ROUTINE_PRIORITIES     ( 2 )
#define configUSE_COUNTING_SEMAPHORES       1
#define configUSE_ALTERNATIVE_API                   0
#define configUSE_RECURSIVE_MUTEXES                 1
/* Hook function related definitions. */
#define configUSE_MALLOC_FAILED_HOOK        0
#define configCHECK_FOR_STACK_OVERFLOW      2

/* Run time stats gathering definitions. */
void vConfigureTimerForRunTimeStats( void );
uint32_t ulGetRunTimeCounterValue( void );
#define configGENERATE_RUN_TIME_STATS               1
#define configUSE_STATS_FORMATTING_FUNCTIONS        1
#define portCONFIGURE_TIMER_FOR_RUN_TIME_STATS()   
vConfigureTimerForRunTimeStats()
#define portGET_RUN_TIME_COUNTER_VALUE()           
ulGetRunTimeCounterValue()

/* Set the following definitions to 1 to include the API function, or zero
to exclude the API function. */

#define INCLUDE_vTaskPrioritySet            1
#define INCLUDE_uxTaskPriorityGet           1
#define INCLUDE_vTaskDelete                 1
#define INCLUDE_vTaskCleanUpResources       1
#define INCLUDE_vTaskSuspend                1
#define INCLUDE_vTaskDelayUntil             1
#define INCLUDE_vTaskDelay                  1
#define INCLUDE_uxTaskGetStackHighWaterMark 1

#define INCLUDE_xTimerGetTimerTaskHandle        0
#define INCLUDE_xTaskGetIdleTaskHandle          0
#define INCLUDE_xQueueGetMutexHolder            1

#define configKERNEL_INTERRUPT_PRIORITY         ( 7 << 5 )    /* Priority 7,
or 0xE0 as only the top three bits are implemented.  This is the lowest
priority. */
#define configMAX_SYSCALL_INTERRUPT_PRIORITY     ( 5 << 5 )  /* Priority 5,
or 0xA0 as only the top three bits are implemented. */

#endif /* FREERTOS_CONFIG_H */



--
Sent from: http://lwip.100.n7.nabble.com/lwip-users-f3.html



reply via email to

[Prev in Thread] Current Thread [Next in Thread]