搜索
bottom↓
回复: 3

rt-thread 创建TCP失败,如何排查问题?

[复制链接]

出0入22汤圆

发表于 2017-1-7 16:30:53 | 显示全部楼层 |阅读模式
如题,以前使用1.2版本,在lm3s芯片上,可以很好的创建并使用tcp server
最近转到STM32,底层已经搞通,UDP也通了,但是在搞TCP的时候碰到了困难。
我使用example目录下的tcp server,加入工程,编译,通过

当运行的时候,到下面这个地方就出错了。
  1. if ((sock = socket(AF_INET, SOCK_STREAM, 0)) == -1)
  2.    {
  3.        /* 创建失败的错误处理 */
  4.        rt_kprintf("Socket error\n");

  5.        /* 释放已分配的接收缓冲 */
  6.        rt_free(recv_data);
  7.        return;
  8.    }
复制代码


检查了配置,已经使能了TCP功能。是不是其他还有哪个地方的开关没有打开,导致的这个故障的出现?
请有经验的大虾指导指导,谢谢!

rt-thread的版本号为RT-Thread v2.1.0 beta
主芯片为STM32F107

阿莫论坛20周年了!感谢大家的支持与爱护!!

一只鸟敢站在脆弱的枝条上歇脚,它依仗的不是枝条不会断,而是自己有翅膀,会飞。

出0入0汤圆

发表于 2017-1-7 16:48:03 | 显示全部楼层
本帖最后由 aozima 于 2017-1-7 16:51 编辑

改配置。加多NET_CONN和socket数量。
UDP也会占用掉这个数量。

可以把memp.c更新为下面的,来dump一下这些数量就明白了。
  1. /**
  2. * @file
  3. * Dynamic pool memory manager
  4. *
  5. * lwIP has dedicated pools for many structures (netconn, protocol control blocks,
  6. * packet buffers, ...). All these pools are managed here.
  7. */

  8. /*
  9. * Copyright (c) 2001-2004 Swedish Institute of Computer Science.
  10. * All rights reserved.
  11. *
  12. * Redistribution and use in source and binary forms, with or without modification,
  13. * are permitted provided that the following conditions are met:
  14. *
  15. * 1. Redistributions of source code must retain the above copyright notice,
  16. *    this list of conditions and the following disclaimer.
  17. * 2. Redistributions in binary form must reproduce the above copyright notice,
  18. *    this list of conditions and the following disclaimer in the documentation
  19. *    and/or other materials provided with the distribution.
  20. * 3. The name of the author may not be used to endorse or promote products
  21. *    derived from this software without specific prior written permission.
  22. *
  23. * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
  24. * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  25. * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
  26. * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  27. * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
  28. * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  29. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  30. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
  31. * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
  32. * OF SUCH DAMAGE.
  33. *
  34. * This file is part of the lwIP TCP/IP stack.
  35. *
  36. * Author: Adam Dunkels <adam@sics.se>
  37. *
  38. */

  39. #include "lwip/opt.h"

  40. #include "lwip/memp.h"
  41. #include "lwip/pbuf.h"
  42. #include "lwip/udp.h"
  43. #include "lwip/raw.h"
  44. #include "lwip/tcp_impl.h"
  45. #include "lwip/igmp.h"
  46. #include "lwip/api.h"
  47. #include "lwip/api_msg.h"
  48. #include "lwip/tcpip.h"
  49. #include "lwip/sys.h"
  50. #include "lwip/timers.h"
  51. #include "lwip/stats.h"
  52. #include "netif/etharp.h"
  53. #include "lwip/ip_frag.h"
  54. #include "lwip/snmp_structs.h"
  55. #include "lwip/snmp_msg.h"
  56. #include "lwip/dns.h"
  57. #include "netif/ppp_oe.h"

  58. #include <string.h>

  59. #if !MEMP_MEM_MALLOC /* don't build if not configured for use in lwipopts.h */

  60. struct memp {
  61.   struct memp *next;
  62. #if MEMP_OVERFLOW_CHECK
  63.   const char *file;
  64.   int line;
  65. #endif /* MEMP_OVERFLOW_CHECK */
  66. };

  67. #if MEMP_OVERFLOW_CHECK
  68. /* if MEMP_OVERFLOW_CHECK is turned on, we reserve some bytes at the beginning
  69. * and at the end of each element, initialize them as 0xcd and check
  70. * them later. */
  71. /* If MEMP_OVERFLOW_CHECK is >= 2, on every call to memp_malloc or memp_free,
  72. * every single element in each pool is checked!
  73. * This is VERY SLOW but also very helpful. */
  74. /* MEMP_SANITY_REGION_BEFORE and MEMP_SANITY_REGION_AFTER can be overridden in
  75. * lwipopts.h to change the amount reserved for checking. */
  76. #ifndef MEMP_SANITY_REGION_BEFORE
  77. #define MEMP_SANITY_REGION_BEFORE  16
  78. #endif /* MEMP_SANITY_REGION_BEFORE*/
  79. #if MEMP_SANITY_REGION_BEFORE > 0
  80. #define MEMP_SANITY_REGION_BEFORE_ALIGNED    LWIP_MEM_ALIGN_SIZE(MEMP_SANITY_REGION_BEFORE)
  81. #else
  82. #define MEMP_SANITY_REGION_BEFORE_ALIGNED    0
  83. #endif /* MEMP_SANITY_REGION_BEFORE*/
  84. #ifndef MEMP_SANITY_REGION_AFTER
  85. #define MEMP_SANITY_REGION_AFTER   16
  86. #endif /* MEMP_SANITY_REGION_AFTER*/
  87. #if MEMP_SANITY_REGION_AFTER > 0
  88. #define MEMP_SANITY_REGION_AFTER_ALIGNED     LWIP_MEM_ALIGN_SIZE(MEMP_SANITY_REGION_AFTER)
  89. #else
  90. #define MEMP_SANITY_REGION_AFTER_ALIGNED     0
  91. #endif /* MEMP_SANITY_REGION_AFTER*/

  92. /* MEMP_SIZE: save space for struct memp and for sanity check */
  93. #define MEMP_SIZE          (LWIP_MEM_ALIGN_SIZE(sizeof(struct memp)) + MEMP_SANITY_REGION_BEFORE_ALIGNED)
  94. #define MEMP_ALIGN_SIZE(x) (LWIP_MEM_ALIGN_SIZE(x) + MEMP_SANITY_REGION_AFTER_ALIGNED)

  95. #else /* MEMP_OVERFLOW_CHECK */

  96. /* No sanity checks
  97. * We don't need to preserve the struct memp while not allocated, so we
  98. * can save a little space and set MEMP_SIZE to 0.
  99. */
  100. #define MEMP_SIZE           0
  101. #define MEMP_ALIGN_SIZE(x) (LWIP_MEM_ALIGN_SIZE(x))

  102. #endif /* MEMP_OVERFLOW_CHECK */

  103. /** This array holds the first free element of each pool.
  104. *  Elements form a linked list. */
  105. static struct memp *memp_tab[MEMP_MAX];

  106. #else /* MEMP_MEM_MALLOC */

  107. #define MEMP_ALIGN_SIZE(x) (LWIP_MEM_ALIGN_SIZE(x))

  108. #endif /* MEMP_MEM_MALLOC */

  109. /** This array holds the element sizes of each pool. */
  110. #if !MEM_USE_POOLS && !MEMP_MEM_MALLOC
  111. static
  112. #endif
  113. const u16_t memp_sizes[MEMP_MAX] = {
  114. #define LWIP_MEMPOOL(name,num,size,desc)  LWIP_MEM_ALIGN_SIZE(size),
  115. #include "lwip/memp_std.h"
  116. };

  117. #if !MEMP_MEM_MALLOC /* don't build if not configured for use in lwipopts.h */

  118. /** This array holds the number of elements in each pool. */
  119. static const u16_t memp_num[MEMP_MAX] = {
  120. #define LWIP_MEMPOOL(name,num,size,desc)  (num),
  121. #include "lwip/memp_std.h"
  122. };

  123. /** This array holds a textual description of each pool. */
  124. #ifdef LWIP_DEBUG
  125. static const char *memp_desc[MEMP_MAX] = {
  126. #define LWIP_MEMPOOL(name,num,size,desc)  (desc),
  127. #include "lwip/memp_std.h"
  128. };
  129. #endif /* LWIP_DEBUG */

  130. #if MEMP_SEPARATE_POOLS

  131. /** This creates each memory pool. These are named memp_memory_XXX_base (where
  132. * XXX is the name of the pool defined in memp_std.h).
  133. * To relocate a pool, declare it as extern in cc.h. Example for GCC:
  134. *   extern u8_t __attribute__((section(".onchip_mem"))) memp_memory_UDP_PCB_base[];
  135. */
  136. #define LWIP_MEMPOOL(name,num,size,desc) u8_t memp_memory_ ## name ## _base \
  137.   [((num) * (MEMP_SIZE + MEMP_ALIGN_SIZE(size)))];
  138. #include "lwip/memp_std.h"

  139. /** This array holds the base of each memory pool. */
  140. static u8_t *const memp_bases[] = {
  141. #define LWIP_MEMPOOL(name,num,size,desc) memp_memory_ ## name ## _base,
  142. #include "lwip/memp_std.h"
  143. };

  144. #else /* MEMP_SEPARATE_POOLS */

  145. /** This is the actual memory used by the pools (all pools in one big block). */
  146. static u8_t memp_memory[MEM_ALIGNMENT - 1
  147. #define LWIP_MEMPOOL(name,num,size,desc) + ( (num) * (MEMP_SIZE + MEMP_ALIGN_SIZE(size) ) )
  148. #include "lwip/memp_std.h"
  149. ];

  150. #endif /* MEMP_SEPARATE_POOLS */

  151. #if MEMP_SANITY_CHECK
  152. /**
  153. * Check that memp-lists don't form a circle, using "Floyd's cycle-finding algorithm".
  154. */
  155. static int
  156. memp_sanity(void)
  157. {
  158.   s16_t i;
  159.   struct memp *t, *h;

  160.   for (i = 0; i < MEMP_MAX; i++) {
  161.     t = memp_tab[i];
  162.     if(t != NULL) {
  163.       for (h = t->next; (t != NULL) && (h != NULL); t = t->next,
  164.         h = (((h->next != NULL) && (h->next->next != NULL)) ? h->next->next : NULL)) {
  165.         if (t == h) {
  166.           return 0;
  167.         }
  168.       }
  169.     }
  170.   }
  171.   return 1;
  172. }
  173. #endif /* MEMP_SANITY_CHECK*/
  174. #if MEMP_OVERFLOW_CHECK
  175. #if defined(LWIP_DEBUG) && MEMP_STATS
  176. static const char * memp_overflow_names[] = {
  177. #define LWIP_MEMPOOL(name,num,size,desc) "/"desc,
  178. #include "lwip/memp_std.h"
  179.   };
  180. #endif

  181. /**
  182. * Check if a memp element was victim of an overflow
  183. * (e.g. the restricted area after it has been altered)
  184. *
  185. * @param p the memp element to check
  186. * @param memp_type the pool p comes from
  187. */
  188. static void
  189. memp_overflow_check_element_overflow(struct memp *p, u16_t memp_type)
  190. {
  191.   u16_t k;
  192.   u8_t *m;
  193. #if MEMP_SANITY_REGION_AFTER_ALIGNED > 0
  194.   m = (u8_t*)p + MEMP_SIZE + memp_sizes[memp_type];
  195.   for (k = 0; k < MEMP_SANITY_REGION_AFTER_ALIGNED; k++) {
  196.     if (m[k] != 0xcd) {
  197.       char errstr[128] = "detected memp overflow in pool ";
  198.       char digit[] = "0";
  199.       if(memp_type >= 10) {
  200.         digit[0] = '0' + (memp_type/10);
  201.         strcat(errstr, digit);
  202.       }
  203.       digit[0] = '0' + (memp_type%10);
  204.       strcat(errstr, digit);
  205. #if defined(LWIP_DEBUG) && MEMP_STATS
  206.       strcat(errstr, memp_overflow_names[memp_type]);
  207. #endif
  208.       LWIP_ASSERT(errstr, 0);
  209.     }
  210.   }
  211. #endif
  212. }

  213. /**
  214. * Check if a memp element was victim of an underflow
  215. * (e.g. the restricted area before it has been altered)
  216. *
  217. * @param p the memp element to check
  218. * @param memp_type the pool p comes from
  219. */
  220. static void
  221. memp_overflow_check_element_underflow(struct memp *p, u16_t memp_type)
  222. {
  223.   u16_t k;
  224.   u8_t *m;
  225. #if MEMP_SANITY_REGION_BEFORE_ALIGNED > 0
  226.   m = (u8_t*)p + MEMP_SIZE - MEMP_SANITY_REGION_BEFORE_ALIGNED;
  227.   for (k = 0; k < MEMP_SANITY_REGION_BEFORE_ALIGNED; k++) {
  228.     if (m[k] != 0xcd) {
  229.       char errstr[128] = "detected memp underflow in pool ";
  230.       char digit[] = "0";
  231.       if(memp_type >= 10) {
  232.         digit[0] = '0' + (memp_type/10);
  233.         strcat(errstr, digit);
  234.       }
  235.       digit[0] = '0' + (memp_type%10);
  236.       strcat(errstr, digit);
  237. #if defined(LWIP_DEBUG) && MEMP_STATS
  238.       strcat(errstr, memp_overflow_names[memp_type]);
  239. #endif
  240.       LWIP_ASSERT(errstr, 0);
  241.     }
  242.   }
  243. #endif
  244. }

  245. /**
  246. * Do an overflow check for all elements in every pool.
  247. *
  248. * @see memp_overflow_check_element for a description of the check
  249. */
  250. static void
  251. memp_overflow_check_all(void)
  252. {
  253.   u16_t i, j;
  254.   struct memp *p;

  255.   p = (struct memp *)LWIP_MEM_ALIGN(memp_memory);
  256.   for (i = 0; i < MEMP_MAX; ++i) {
  257.     p = p;
  258.     for (j = 0; j < memp_num[i]; ++j) {
  259.       memp_overflow_check_element_overflow(p, i);
  260.       p = (struct memp*)((u8_t*)p + MEMP_SIZE + memp_sizes[i] + MEMP_SANITY_REGION_AFTER_ALIGNED);
  261.     }
  262.   }
  263.   p = (struct memp *)LWIP_MEM_ALIGN(memp_memory);
  264.   for (i = 0; i < MEMP_MAX; ++i) {
  265.     p = p;
  266.     for (j = 0; j < memp_num[i]; ++j) {
  267.       memp_overflow_check_element_underflow(p, i);
  268.       p = (struct memp*)((u8_t*)p + MEMP_SIZE + memp_sizes[i] + MEMP_SANITY_REGION_AFTER_ALIGNED);
  269.     }
  270.   }
  271. }

  272. /**
  273. * Initialize the restricted areas of all memp elements in every pool.
  274. */
  275. static void
  276. memp_overflow_init(void)
  277. {
  278.   u16_t i, j;
  279.   struct memp *p;
  280.   u8_t *m;

  281.   p = (struct memp *)LWIP_MEM_ALIGN(memp_memory);
  282.   for (i = 0; i < MEMP_MAX; ++i) {
  283.     p = p;
  284.     for (j = 0; j < memp_num[i]; ++j) {
  285. #if MEMP_SANITY_REGION_BEFORE_ALIGNED > 0
  286.       m = (u8_t*)p + MEMP_SIZE - MEMP_SANITY_REGION_BEFORE_ALIGNED;
  287.       memset(m, 0xcd, MEMP_SANITY_REGION_BEFORE_ALIGNED);
  288. #endif
  289. #if MEMP_SANITY_REGION_AFTER_ALIGNED > 0
  290.       m = (u8_t*)p + MEMP_SIZE + memp_sizes[i];
  291.       memset(m, 0xcd, MEMP_SANITY_REGION_AFTER_ALIGNED);
  292. #endif
  293.       p = (struct memp*)((u8_t*)p + MEMP_SIZE + memp_sizes[i] + MEMP_SANITY_REGION_AFTER_ALIGNED);
  294.     }
  295.   }
  296. }
  297. #endif /* MEMP_OVERFLOW_CHECK */


  298. static void memp_dump(void)
  299. {
  300.         rt_kprintf("memp_init\n");
  301.        
  302.         rt_kprintf("memp_memory size:%d\n", sizeof(memp_memory));
  303.        
  304.         rt_kprintf("name              size  num total\n");
  305.         rt_kprintf("%-16.16s: %-5d %-3d %-5d\n", "RAW_PCB",
  306.         sizeof(struct raw_pcb), MEMP_NUM_RAW_PCB,
  307.         sizeof(struct raw_pcb) * MEMP_NUM_RAW_PCB);

  308. #if LWIP_UDP
  309.         rt_kprintf("%-16.16s: %-5d %-3d %-5d\n", "UDP_PCB",
  310.         sizeof(struct udp_pcb), MEMP_NUM_UDP_PCB,
  311.         sizeof(struct udp_pcb) * MEMP_NUM_UDP_PCB);
  312. #else
  313.         rt_kprintf("LWIP_UDP disable\n");
  314. #endif /* LWIP_UDP */

  315. #if LWIP_TCP
  316.         rt_kprintf("%-16.16s: %-5d %-3d %-5d\n", "TCP_PCB",
  317.         sizeof(struct tcp_pcb), MEMP_NUM_TCP_PCB,
  318.         sizeof(struct tcp_pcb) * MEMP_NUM_TCP_PCB);

  319.         rt_kprintf("%-16.16s: %-5d %-3d %-5d\n", "TCP_PCB_LISTEN",
  320.         sizeof(struct tcp_pcb_listen), MEMP_NUM_TCP_PCB_LISTEN,
  321.         sizeof(struct tcp_pcb_listen) * MEMP_NUM_TCP_PCB_LISTEN);

  322.         rt_kprintf("%-16.16s: %-5d %-3d %-5d\n", "TCP_SEG",
  323.         sizeof(struct tcp_seg), MEMP_NUM_TCP_SEG,
  324.         sizeof(struct tcp_seg) * MEMP_NUM_TCP_SEG);
  325. #else
  326.         rt_kprintf("LWIP_TCP disable\n");
  327. #endif /* LWIP_TCP */

  328. //重新组装
  329. #if IP_REASSEMBLY
  330.         rt_kprintf("%-16.16s: %-5d %-3d %-5d\n", "REASSDATA",
  331.         sizeof(struct ip_reassdata), MEMP_NUM_REASSDATA,
  332.         sizeof(struct ip_reassdata) * MEMP_NUM_REASSDATA);
  333. #else
  334.         rt_kprintf("IP_REASSEMBLY disable\n");
  335. #endif /* IP_REASSEMBLY */

  336. //分片
  337. #if IP_FRAG && !IP_FRAG_USES_STATIC_BUF && !LWIP_NETIF_TX_SINGLE_PBUF
  338.         rt_kprintf("%-16.16s: %-5d %-3d %-5d\n", "FRAG_PBUF",
  339.         sizeof(struct pbuf_custom_ref), MEMP_NUM_FRAG_PBUF,
  340.         sizeof(struct pbuf_custom_ref) * MEMP_NUM_FRAG_PBUF);
  341. #else
  342.         rt_kprintf("IP_FRAG disable\n");
  343. #endif /* IP_FRAG && !IP_FRAG_USES_STATIC_BUF && !LWIP_NETIF_TX_SINGLE_PBUF */

  344. #if LWIP_NETCONN
  345.         rt_kprintf("%-16.16s: %-5d %-3d %-5d\n", "NETBUF",
  346.         sizeof(struct netbuf), MEMP_NUM_NETBUF,
  347.         sizeof(struct netbuf) * MEMP_NUM_NETBUF);

  348.         rt_kprintf("%-16.16s: %-5d %-3d %-5d\n", "NETCONN",
  349.         sizeof(struct netconn), MEMP_NUM_NETCONN,
  350.         sizeof(struct netconn) * MEMP_NUM_NETCONN);
  351. #else
  352.         rt_kprintf("LWIP_NETCONN disable\n");
  353. #endif /* LWIP_NETCONN */

  354.         rt_kprintf("%-16.16s: %-5d %-3d %-5d\n", "TCPIP_MSG_API",
  355.         sizeof(struct tcpip_msg), MEMP_NUM_TCPIP_MSG_API,
  356.         sizeof(struct tcpip_msg) * MEMP_NUM_TCPIP_MSG_API);

  357.         rt_kprintf("%-16.16s: %-5d %-3d %-5d\n", "TCPIP_MSG_INPKT",
  358.         sizeof(struct tcpip_msg), MEMP_NUM_TCPIP_MSG_INPKT,
  359.         sizeof(struct tcpip_msg) * MEMP_NUM_TCPIP_MSG_INPKT);

  360. #if LWIP_ARP && ARP_QUEUEING
  361.         rt_kprintf("%-16.16s: %-5d %-3d %-5d\n", "ARP_QUEUE",
  362.         sizeof(struct etharp_q_entry), MEMP_NUM_ARP_QUEUE,
  363.         sizeof(struct etharp_q_entry) * MEMP_NUM_ARP_QUEUE);
  364. #else
  365.         rt_kprintf("LWIP_ARP disable\n");
  366. #endif /* LWIP_ARP && ARP_QUEUEING */

  367. #if LWIP_IGMP
  368.         rt_kprintf("%-16.16s: %-5d %-3d %-5d\n", "IGMP_GROUP",
  369.         sizeof(struct igmp_group), MEMP_NUM_IGMP_GROUP,
  370.         sizeof(struct igmp_group) * MEMP_NUM_IGMP_GROUP);
  371. #else
  372.         rt_kprintf("LWIP_IGMP disable\n");
  373. #endif /* LWIP_IGMP */

  374.         rt_kprintf("%-16.16s: %-5d %-3d %-5d\n", "SYS_TIMEOUT",
  375.         sizeof(struct sys_timeo), MEMP_NUM_SYS_TIMEOUT,
  376.         sizeof(struct sys_timeo) * MEMP_NUM_SYS_TIMEOUT);

  377. #if LWIP_SNMP
  378.         rt_kprintf("%-16.16s: %-5d %-3d %-5d\n", "SNMP_ROOTNODE",
  379.         sizeof(struct mib_list_rootnode), MEMP_NUM_SNMP_ROOTNODE,
  380.         sizeof(struct mib_list_rootnode) * MEMP_NUM_SNMP_ROOTNODE);
  381.        
  382.         rt_kprintf("%-16.16s: %-5d %-3d %-5d\n", "SNMP_NODE",
  383.         sizeof(struct mib_list_node), MEMP_NUM_SNMP_NODE,
  384.         sizeof(struct mib_list_node) * MEMP_NUM_SNMP_NODE);
  385.        
  386.         rt_kprintf("%-16.16s: %-5d %-3d %-5d\n", "SNMP_VARBIND",
  387.         sizeof(struct snmp_varbind), MEMP_NUM_SNMP_VARBIND,
  388.         sizeof(struct snmp_varbind) * MEMP_NUM_SNMP_VARBIND);
  389.        
  390.         rt_kprintf("%-16.16s: %-5d %-3d %-5d\n", "SNMP_VALUE",
  391.         SNMP_MAX_VALUE_SIZE, MEMP_NUM_SNMP_VALUE,
  392.         SNMP_MAX_VALUE_SIZE * MEMP_NUM_SNMP_VALUE);
  393. #else
  394.         rt_kprintf("LWIP_SNMP disable\n");
  395. #endif /* LWIP_SNMP */

  396. #if LWIP_DNS && LWIP_SOCKET
  397.         rt_kprintf("%-16.16s: %-5d %-3d %-5d\n", "NETDB",
  398.         NETDB_ELEM_SIZE, MEMP_NUM_NETDB,
  399.         NETDB_ELEM_SIZE * MEMP_NUM_NETDB);
  400. #else
  401.         rt_kprintf("LWIP_DNS LWIP_SOCKET disable\n");
  402. #endif /* LWIP_DNS LWIP_SOCKET */

  403. #if LWIP_DNS && DNS_LOCAL_HOSTLIST && DNS_LOCAL_HOSTLIST_IS_DYNAMIC
  404.         rt_kprintf("%-16.16s: %-5d %-3d %-5d\n", "LOCALHOSTLIST",
  405.         LOCALHOSTLIST_ELEM_SIZE, MEMP_NUM_LOCALHOSTLIST,
  406.         LOCALHOSTLIST_ELEM_SIZE * MEMP_NUM_LOCALHOSTLIST);
  407. #else
  408.         rt_kprintf("DNS_LOCAL_HOSTLIST disable\n");
  409. #endif /* DNS_LOCAL_HOSTLIST */

  410. #if PPPOE_SUPPORT
  411.         rt_kprintf("%-16.16s: %-5d %-3d %-5d\n", "PPPOE_IF",
  412.         sizeof(struct pppoe_softc), MEMP_NUM_PPPOE_INTERFACES,
  413.         sizeof(struct pppoe_softc) * MEMP_NUM_PPPOE_INTERFACES);
  414. #else
  415.         rt_kprintf("PPPOE_SUPPORT disable\n");
  416. #endif /* PPPOE_SUPPORT */

  417.         rt_kprintf("%-16.16s: %-5d %-3d %-5d\n", "PBUF_POOL",
  418.         PBUF_POOL_BUFSIZE, PBUF_POOL_SIZE,
  419.         PBUF_POOL_BUFSIZE * PBUF_POOL_SIZE);
  420. }

  421. /**
  422. * Initialize this module.
  423. *
  424. * Carves out memp_memory into linked lists for each pool-type.
  425. */
  426. void
  427. memp_init(void)
  428. {
  429.   struct memp *memp;
  430.   u16_t i, j;

  431.   memp_dump();

  432.   for (i = 0; i < MEMP_MAX; ++i) {
  433.     MEMP_STATS_AVAIL(used, i, 0);
  434.     MEMP_STATS_AVAIL(max, i, 0);
  435.     MEMP_STATS_AVAIL(err, i, 0);
  436.     MEMP_STATS_AVAIL(avail, i, memp_num[i]);
  437.   }

  438. #if !MEMP_SEPARATE_POOLS
  439.   memp = (struct memp *)LWIP_MEM_ALIGN(memp_memory);
  440. #endif /* !MEMP_SEPARATE_POOLS */
  441.   /* for every pool: */
  442.   for (i = 0; i < MEMP_MAX; ++i) {
  443.     memp_tab[i] = NULL;
  444. #if MEMP_SEPARATE_POOLS
  445.     memp = (struct memp*)memp_bases[i];
  446. #endif /* MEMP_SEPARATE_POOLS */
  447.     /* create a linked list of memp elements */
  448.     for (j = 0; j < memp_num[i]; ++j) {
  449.       memp->next = memp_tab[i];
  450.       memp_tab[i] = memp;
  451.       memp = (struct memp *)(void *)((u8_t *)memp + MEMP_SIZE + memp_sizes[i]
  452. #if MEMP_OVERFLOW_CHECK
  453.         + MEMP_SANITY_REGION_AFTER_ALIGNED
  454. #endif
  455.       );
  456.     }
  457.   }
  458. #if MEMP_OVERFLOW_CHECK
  459.   memp_overflow_init();
  460.   /* check everything a first time to see if it worked */
  461.   memp_overflow_check_all();
  462. #endif /* MEMP_OVERFLOW_CHECK */
  463. }

  464. /**
  465. * Get an element from a specific pool.
  466. *
  467. * @param type the pool to get an element from
  468. *
  469. * the debug version has two more parameters:
  470. * @param file file name calling this function
  471. * @param line number of line where this function is called
  472. *
  473. * @return a pointer to the allocated memory or a NULL pointer on error
  474. */
  475. void *
  476. #if !MEMP_OVERFLOW_CHECK
  477. memp_malloc(memp_t type)
  478. #else
  479. memp_malloc_fn(memp_t type, const char* file, const int line)
  480. #endif
  481. {
  482.   struct memp *memp;
  483.   SYS_ARCH_DECL_PROTECT(old_level);

  484.   LWIP_ERROR("memp_malloc: type < MEMP_MAX", (type < MEMP_MAX), return NULL;);

  485.   SYS_ARCH_PROTECT(old_level);
  486. #if MEMP_OVERFLOW_CHECK >= 2
  487.   memp_overflow_check_all();
  488. #endif /* MEMP_OVERFLOW_CHECK >= 2 */

  489.   memp = memp_tab[type];

  490.   if (memp != NULL) {
  491.     memp_tab[type] = memp->next;
  492. #if MEMP_OVERFLOW_CHECK
  493.     memp->next = NULL;
  494.     memp->file = file;
  495.     memp->line = line;
  496. #endif /* MEMP_OVERFLOW_CHECK */
  497.     MEMP_STATS_INC_USED(used, type);
  498.     LWIP_ASSERT("memp_malloc: memp properly aligned",
  499.                 ((mem_ptr_t)memp % MEM_ALIGNMENT) == 0);
  500.     memp = (struct memp*)(void *)((u8_t*)memp + MEMP_SIZE);
  501.   } else {
  502.     LWIP_DEBUGF(MEMP_DEBUG | LWIP_DBG_LEVEL_SERIOUS, ("memp_malloc: out of memory in pool %s\n", memp_desc[type]));
  503.     MEMP_STATS_INC(err, type);
  504.   }

  505.   SYS_ARCH_UNPROTECT(old_level);

  506.   return memp;
  507. }

  508. /**
  509. * Put an element back into its pool.
  510. *
  511. * @param type the pool where to put mem
  512. * @param mem the memp element to free
  513. */
  514. void
  515. memp_free(memp_t type, void *mem)
  516. {
  517.   struct memp *memp;
  518.   SYS_ARCH_DECL_PROTECT(old_level);

  519.   if (mem == NULL) {
  520.     return;
  521.   }
  522.   LWIP_ASSERT("memp_free: mem properly aligned",
  523.                 ((mem_ptr_t)mem % MEM_ALIGNMENT) == 0);

  524.   memp = (struct memp *)(void *)((u8_t*)mem - MEMP_SIZE);

  525.   SYS_ARCH_PROTECT(old_level);
  526. #if MEMP_OVERFLOW_CHECK
  527. #if MEMP_OVERFLOW_CHECK >= 2
  528.   memp_overflow_check_all();
  529. #else
  530.   memp_overflow_check_element_overflow(memp, type);
  531.   memp_overflow_check_element_underflow(memp, type);
  532. #endif /* MEMP_OVERFLOW_CHECK >= 2 */
  533. #endif /* MEMP_OVERFLOW_CHECK */

  534.   MEMP_STATS_DEC(used, type);

  535.   memp->next = memp_tab[type];
  536.   memp_tab[type] = memp;

  537. #if MEMP_SANITY_CHECK
  538.   LWIP_ASSERT("memp sanity", memp_sanity());
  539. #endif /* MEMP_SANITY_CHECK */

  540.   SYS_ARCH_UNPROTECT(old_level);
  541. }

  542. #endif /* MEMP_MEM_MALLOC */
复制代码


出0入22汤圆

 楼主| 发表于 2017-1-7 17:26:45 来自手机 | 显示全部楼层
aozima 发表于 2017-1-7 16:48
改配置。加多NET_CONN和socket数量。
UDP也会占用掉这个数量。


如果是那啥数量的问题,我尝试过不启用udp服务器,同样会在初始化tcp的时候出错呢

出190入0汤圆

发表于 2017-1-7 21:27:59 来自手机 | 显示全部楼层
都喜欢直接贴代码?
回帖提示: 反政府言论将被立即封锁ID 在按“提交”前,请自问一下:我这样表达会给举报吗,会给自己惹麻烦吗? 另外:尽量不要使用Mark、顶等没有意义的回复。不得大量使用大字体和彩色字。【本论坛不允许直接上传手机拍摄图片,浪费大家下载带宽和论坛服务器空间,请压缩后(图片小于1兆)才上传。压缩方法可以在微信里面发给自己(不要勾选“原图),然后下载,就能得到压缩后的图片】。另外,手机版只能上传图片,要上传附件需要切换到电脑版(不需要使用电脑,手机上切换到电脑版就行,页面底部)。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

手机版|Archiver|amobbs.com 阿莫电子技术论坛 ( 粤ICP备2022115958号, 版权所有:东莞阿莫电子贸易商行 创办于2004年 (公安交互式论坛备案:44190002001997 ) )

GMT+8, 2024-3-29 17:17

© Since 2004 www.amobbs.com, 原www.ourdev.cn, 原www.ouravr.com

快速回复 返回顶部 返回列表