58 struct tcp_pcb *pcb, *inactive;
64 for (pcb = tcp_tw_pcbs; pcb !=
NULL; pcb = pcb->next) {
65 if ((
u32_t) (tcp_ticks - pcb->tmr) >= inactivity) {
66 inactivity = tcp_ticks - pcb->tmr;
70 if (inactive !=
NULL) {
77 for (pcb = tcp_active_pcbs; pcb !=
NULL; pcb = pcb->next) {
78 if (pcb->state == FIN_WAIT_1 || pcb->state == FIN_WAIT_2){
79 if ((
u32_t) (tcp_ticks - pcb->tmr) >= inactivity) {
80 inactivity = tcp_ticks - pcb->tmr;
86 if (inactive !=
NULL) {
87 tcp_pcb_remove(&tcp_active_pcbs, inactive);
94 for (pcb = tcp_active_pcbs; pcb !=
NULL; pcb = pcb->next) {
95 if (pcb->state == LAST_ACK) {
96 if ((
u32_t) (tcp_ticks - pcb->tmr) >= inactivity) {
97 inactivity = tcp_ticks - pcb->tmr;
103 if (inactive !=
NULL) {
104 tcp_pcb_remove(&tcp_active_pcbs, inactive);
117 struct tcp_pcb *cpcb =
NULL;
119 uint8 num_tcp_fin = 0;
120 for(i = 2; i < 4; i ++){
122 if (cpcb->state == TIME_WAIT){
128 if (cpcb->state == FIN_WAIT_1 || cpcb->state == FIN_WAIT_2 || cpcb->state == LAST_ACK){
138 }
else if (cpcb ==
NULL){
152 struct tcp_pcb *cpcb =
NULL;
154 struct tcp_pcb *inactive =
NULL;
155 struct tcp_pcb *prev =
NULL;
158 for (i = 1; i < 4; i++) {
162 if (cpcb->local_port == port) {
169 cpcb = inactive->next;
191 struct tcp_pcb *find_pcb =
NULL;
192 if (pcurrent_msg ->preverse ==
NULL){
193 if (local_ip == 0|| local_port == 0)
return pcurrent_msg->
pcommon.
pcb;
195 for (find_pcb = tcp_active_pcbs; find_pcb !=
NULL; find_pcb = find_pcb->next){
196 if ((find_pcb->remote_port == remote_port) && (find_pcb->remote_ip.addr == remote_ip) &&
197 (find_pcb->local_port == local_port) && (find_pcb->local_ip.addr == local_ip))
201 for (find_pcb = tcp_tw_pcbs; find_pcb !=
NULL; find_pcb = find_pcb->next){
202 if ((find_pcb->remote_port == remote_port) && (find_pcb->remote_ip.addr == remote_ip) &&
203 (find_pcb->local_port == local_port) && (find_pcb->local_ip.addr == local_ip))
207 if (remote_ip == 0|| remote_port == 0)
return pcurrent_msg->
pcommon.
pcb;
209 for (find_pcb = tcp_active_pcbs; find_pcb !=
NULL; find_pcb = find_pcb->next){
210 if ((find_pcb->remote_port == remote_port) && (find_pcb->remote_ip.addr == remote_ip))
214 for (find_pcb = tcp_tw_pcbs; find_pcb !=
NULL; find_pcb = find_pcb->next){
215 if ((find_pcb->remote_port == remote_port) && (find_pcb->remote_ip.addr == remote_ip))
236 if (precon_cb !=
NULL) {
240 if (espconn !=
NULL){
261 while (perr_buf !=
NULL){
262 perr_back = perr_buf;
263 perr_buf = perr_back->
pnext;
294 if (pdiscon_cb !=
NULL) {
299 struct tcp_pcb *pcb =
NULL;
300 if (espconn !=
NULL){
321 struct tcp_pcb *cpcb =
NULL;
322 struct tcp_pcb *prev =
NULL;
324 espconn_printf(
"espconn_tcp_disconnect_successful %d, %d\n", pcb->state, pcb->local_port);
326 while (cpcb !=
NULL) {
328 if (cpcb->local_port == pcb->local_port) {
333 struct tcp_pcb *backup_pcb =
NULL;
337 LWIP_ASSERT(
"espconn_tcp_delete: middle cpcb != tcp_tw_pcbs",cpcb != tcp_tw_pcbs);
338 prev->next = cpcb->next;
341 LWIP_ASSERT(
"espconn_tcp_delete: first cpcb == tcp_tw_pcbs",tcp_tw_pcbs == cpcb);
342 tcp_tw_pcbs = cpcb->next;
362 while (pdis_buf !=
NULL) {
363 pdis_back = pdis_buf;
364 pdis_buf = pdis_back->
pnext;
394 switch (events->sig) {
397 if (pespconn ==
NULL) {
437 struct tcp_pcb *pcb =
NULL;
440 u8_t data_to_send =
false;
442 espconn_printf(
"espconn_tcp_sent ptcp_sent %p psent %p length %d\n", ptcp_sent, psent, length);
445 if (ptcp_sent ==
NULL || psent ==
NULL || length == 0) {
451 if (tcp_sndbuf(pcb) < length) {
452 len = tcp_sndbuf(pcb);
455 LWIP_ASSERT(
"length did not fit into uint16!", (len == length));
458 if (len > (2*pcb->mss)) {
464 espconn_printf(
"espconn_tcp_sent writing %d bytes %p\n", len, pcb);
466 err = tcp_write(pcb, psent, len, 1);
468 err = tcp_write(pcb, psent, len, 0);
473 }
while (err ==
ERR_MEM && len > 1);
479 err = tcp_output(pcb);
500 if (pdiscon !=
NULL){
530 err = tcp_close(pcb);
532 {tcp_abort(pcb); err =
ERR_OK;}
554 if (pespconn ==
NULL) {
560 os_printf(
"RecvHold, By pespconn,find conn_msg fail\n");
579 if (pespconn ==
NULL) {
585 os_printf(
"RecvHold, By pespconn,find conn_msg fail\n");
632 pdata = (
char *)
os_zalloc(p ->tot_len + 1);
644 if (pcb->state == ESTABLISHED)
676 while (tcp_sndbuf(pcb) != 0){
764 struct tcp_pcb *pcb =
NULL;
767 if (perr_cb !=
NULL) {
770 espconn_printf(
"espconn_client_err %d %d %d\n", pcb->state, pcb->nrtx, err);
777 switch (pcb->state) {
830 espconn_printf(
"espconn_client_connect pcon %p tpcb %p\n", pcon, tpcb);
844 tcp_arg(tpcb, (
void *) pcon);
852 tcp_nagle_disable(tpcb);
856 if (pcon->pespconn->proto.tcp->connect_callback !=
NULL) {
857 pcon->pespconn->proto.tcp->connect_callback(pcon->pespconn);
880 struct tcp_pcb *pcb =
NULL;
886 if (pclient ==
NULL){
908 tcp_arg(pcb, (
void *)pclient);
910 pclient->preverse =
NULL;
911 pclient->pespconn = espconn;
913 pclient->pcommon.pcb = pcb;
914 tcp_bind(pcb,
IP_ADDR_ANY, pclient->pespconn->proto.tcp->local_port);
916 pclient->pcommon.err = tcp_bind(pcb,
IP_ADDR_ANY, pclient->pespconn->proto.tcp->local_port);
917 if (pclient->pcommon.err !=
ERR_OK){
927 pclient->pcommon.err = tcp_connect(pcb, &ipaddr,
929 if (pclient->pcommon.err ==
ERR_RTE){
937 return pclient->pcommon.err;
960 err = tcp_close(pcb);
962 {tcp_abort(pcb); err =
ERR_OK;}
969 tcp_poll(pcb,
NULL, 0);
1004 u32_t data_cntr = 0;
1013 if (data_cntr != 0) {
1022 if (pcb->state == ESTABLISHED)
1085 tcp_abandon(pcb, 0);
1086 tcp_poll(pcb,
NULL, 0);
1092 if (pcb->state == ESTABLISHED) {
1101 while (ptime_msg !=
NULL) {
1113 ptime_msg = ptime_msg->
pnext;
1135 struct tcp_pcb *pcb =
NULL;
1136 if (pserr_cb !=
NULL) {
1146 switch (pcb->state) {
1206 if (!espconn || !espconn->
proto.
tcp) {
1210 tcp_arg(pcb, paccept);
1220 tcp_arg(pcb, paccept);
1222 if (paccept ==
NULL)
1258 tcp_nagle_disable(pcb);
1283 struct tcp_pcb *pcb =
NULL;
1288 if (pserver ==
NULL){
1300 struct tcp_pcb *lpcb =
NULL;
1305 pcb = tcp_listen(pcb);
1315 tcp_arg(pcb, (
void *)espconn);
1340 struct tcp_pcb *pcb =
NULL;
1342 if (pdeletecon ==
NULL)
1352 while (pdelete_msg !=
NULL){
1353 if (pdelete_msg->
pespconn == pdeletecon){
1357 os_printf(
"espconn_tcp_delete %d, %d\n",pcb->state, pcb->local_port);
1359 err = tcp_close(pcb);
1364 pdelete_msg = pdelete_msg->
pnext;
static err_t ICACHE_FLASH_ATTR espconn_server_poll(void *arg, struct tcp_pcb *pcb)
static void espconn_client_close(void *arg, struct tcp_pcb *pcb, u8 type)
sint8 ICACHE_FLASH_ATTR espconn_tcp_client(struct espconn *espconn)
#define ip4_addr3_16(ipaddr)
#define espconn_copy_disabled(espconn)
void memp_free(memp_t type, void *mem) ICACHE_FLASH_ATTR
err_t ICACHE_FLASH_ATTR espconn_tcp_write(void *arg)
err_t ICACHE_FLASH_ATTR espconn_tcp_sent(void *arg, uint8 *psent, uint16 length)
sint8 ICACHE_FLASH_ATTR espconn_tcp_server(struct espconn *espconn)
sint8 espconn_tcp_get_max_con_allow(struct espconn *espconn)
void ICACHE_FLASH_ATTR espconn_pbuf_delete(espconn_buf **phead, espconn_buf *pdelete)
static void ICACHE_FLASH_ATTR espconn_Task(os_event_t *events)
#define espconn_TaskQueueLen
struct _espconn_msg * pnext
uint32 system_get_free_heap_size(void)
void espconn_list_delete(espconn_msg **phead, espconn_msg *pdelete)
sint8 espconn_get_connection_info(struct espconn *pespconn, remot_info **pcon_info, uint8 typeflags)
espconn_msg * pserver_list
static err_t espconn_client_recv(void *arg, struct tcp_pcb *pcb, struct pbuf *p, err_t err)
static err_t espconn_server_recv(void *arg, struct tcp_pcb *pcb, struct pbuf *p, err_t err)
const ip_addr_t ip_addr_any ICACHE_RODATA_ATTR
#define ICACHE_FLASH_ATTR
static void ICACHE_FLASH_ATTR espconn_tcp_finish(void *arg)
static err_t ICACHE_FLASH_ATTR espconn_client_connect(void *arg, struct tcp_pcb *tpcb, err_t err)
os_event_t espconn_TaskQueue[espconn_TaskQueueLen]
static void ICACHE_FLASH_ATTR espconn_tcp_reconnect(void *arg)
void ICACHE_FLASH_ATTR espconn_kill_pcb(u16_t port)
sint8 espconn_tcp_set_buf_count(struct espconn *espconn, uint8 num)
static err_t ICACHE_FLASH_ATTR espconn_tcp_accept(void *arg, struct tcp_pcb *pcb, err_t err)
espconn_connect_callback connect_callback
void espconn_list_creat(espconn_msg **phead, espconn_msg *pinsert)
struct espconn_packet packet_info
struct tcp_pcb **const tcp_pcb_lists[]
static void ICACHE_FLASH_ATTR espconn_tcp_disconnect_successful(void *arg)
static void ICACHE_FLASH_ATTR esponn_server_err(void *arg, err_t err)
bool espconn_find_connection(struct espconn *pespconn, espconn_msg **pnode)
#define espconn_keepalive_enable(pcb)
void ICACHE_FLASH_ATTR espconn_kill_oldest_pcb(void)
static void ICACHE_FLASH_ATTR espconn_kill_oldest(void)
#define ip4_addr4_16(ipaddr)
espconn_connect_callback write_finish_fn
void espconn_copy_partial(struct espconn *pesp_dest, struct espconn *pesp_source)
static void ICACHE_FLASH_ATTR espconn_client_err(void *arg, err_t err)
static void espconn_server_close(void *arg, struct tcp_pcb *pcb, u8 type)
#define espconn_printf(fmt, args...)
u8_t pbuf_free(struct pbuf *p) ICACHE_FLASH_ATTR
sint8 ICACHE_FLASH_ATTR espconn_recv_unhold(struct espconn *pespconn)
#define espconn_reuse_disabled(espconn)
espconn_reconnect_callback reconnect_callback
#define ip4_addr1_16(ipaddr)
#define LWIP_ASSERT(message, assertion)
espconn_connect_callback disconnect_callback
u16_t pbuf_copy_partial(struct pbuf *p, void *dataptr, u16_t len, u16_t offset) ICACHE_FLASH_ATTR
void ICACHE_FLASH_ATTR espconn_init(void)
struct espconn_packet pktinfo[2]
#define ESPCONN_INPROGRESS
espconn_recv_callback recv_callback
#define ip4_addr2_16(ipaddr)
uint16 recv_holded_buf_Len
struct _espconn_buf * pnext
static err_t ICACHE_FLASH_ATTR espconn_client_sent(void *arg, struct tcp_pcb *pcb, u16_t len)
struct espconn * pespconn
static err_t ICACHE_FLASH_ATTR espconn_server_sent(void *arg, struct tcp_pcb *pcb, u16_t len)
void ICACHE_FLASH_ATTR espconn_tcp_disconnect(espconn_msg *pdiscon, u8 type)
#define LWIP_UNUSED_ARG(x)
#define espconn_keepalive_disabled(espconn)
espconn_msg * plink_active
espconn_sent_callback sent_callback
struct tcp_pcb *ICACHE_FLASH_ATTR espconn_find_current_pcb(espconn_msg *pcurrent_msg)
sint8 ICACHE_FLASH_ATTR espconn_tcp_delete(struct espconn *pdeletecon)
sint8 ICACHE_FLASH_ATTR espconn_recv_hold(struct espconn *pespconn)
#define IP4_ADDR(ipaddr, a, b, c, d)