Added the hold and unhold methods to tcp socket

This commit is contained in:
Santiago 2015-02-09 03:00:18 -03:00
parent dec47d5372
commit 929d4aed5c
7 changed files with 115 additions and 1 deletions

View File

@ -394,5 +394,21 @@ extern sint8 espconn_igmp_join(ip_addr_t *host_ip, ip_addr_t *multicast_ip);
*******************************************************************************/ *******************************************************************************/
extern sint8 espconn_igmp_leave(ip_addr_t *host_ip, ip_addr_t *multicast_ip); extern sint8 espconn_igmp_leave(ip_addr_t *host_ip, ip_addr_t *multicast_ip);
/******************************************************************************
* FunctionName : espconn_recv_hold
* Description : hold tcp receive
* Parameters : espconn -- espconn to hold
* Returns : none
*******************************************************************************/
extern sint8 espconn_recv_hold(struct espconn *pespconn);
/******************************************************************************
* FunctionName : espconn_recv_unhold
* Description : unhold tcp receive
* Parameters : espconn -- espconn to unhold
* Returns : none
*******************************************************************************/
extern sint8 espconn_recv_unhold(struct espconn *pespconn);
#endif #endif

View File

@ -277,6 +277,8 @@ struct tcp_pcb {
/* KEEPALIVE counter */ /* KEEPALIVE counter */
u8_t keep_cnt_sent; u8_t keep_cnt_sent;
u8_t hold;
}; };
struct tcp_pcb_listen { struct tcp_pcb_listen {

View File

@ -718,3 +718,32 @@ espconn_gethostbyname(struct espconn *pespconn, const char *hostname, ip_addr_t
return dns_gethostbyname(hostname, addr, found, pespconn); return dns_gethostbyname(hostname, addr, found, pespconn);
} }
sint8 espconn_recv_hold(struct espconn *pespconn) {
espconn_msg *pnode = NULL;
if (pespconn == NULL) {
return ESPCONN_ARG;
}
pespconn->state = ESPCONN_WRITE;
if (!espconn_find_connection(pespconn, &pnode)) {
return ESPCONN_ARG;
}
espconn_tcp_hold(pnode);
return ESPCONN_OK;
}
sint8 espconn_recv_unhold(struct espconn *pespconn) {
espconn_msg *pnode = NULL;
if (pespconn == NULL) {
return ESPCONN_ARG;
}
pespconn->state = ESPCONN_WRITE;
if (!espconn_find_connection(pespconn, &pnode)) {
return ESPCONN_ARG;
}
espconn_tcp_unhold(pnode);
return ESPCONN_OK;
}

View File

@ -948,3 +948,19 @@ sint8 ICACHE_FLASH_ATTR espconn_tcp_delete(struct espconn *pdeletecon)
return ESPCONN_ARG; return ESPCONN_ARG;
} }
} }
void espconn_tcp_hold(void *arg) {
espconn_msg *ptcp_sent = arg;
struct tcp_pcb *pcb = NULL;
pcb = ptcp_sent->pcommon.pcb;
pcb->hold = 1;
}
void espconn_tcp_unhold(void *arg) {
espconn_msg *ptcp_sent = arg;
struct tcp_pcb *pcb = NULL;
pcb = ptcp_sent->pcommon.pcb;
pcb->hold = 0;
}

View File

@ -1259,6 +1259,7 @@ tcp_alloc(u8_t prio)
#endif /* LWIP_TCP_KEEPALIVE */ #endif /* LWIP_TCP_KEEPALIVE */
pcb->keep_cnt_sent = 0; //<2F><><EFBFBD>ķ<EFBFBD><C4B7>ʹ<EFBFBD><CDB4><EFBFBD> pcb->keep_cnt_sent = 0; //<2F><><EFBFBD>ķ<EFBFBD><C4B7>ʹ<EFBFBD><CDB4><EFBFBD>
pcb->hold = 0;
} }
return pcb; return pcb;
} }

View File

@ -1137,7 +1137,7 @@ tcp_receive(struct tcp_pcb *pcb)
/* If the incoming segment contains data, we must process it /* If the incoming segment contains data, we must process it
further. */ further. */
if (tcplen > 0) { if ((tcplen > 0) && (!pcb->hold)) {
/* This code basically does three things: /* This code basically does three things:
+) If the incoming segment contains data that is the next +) If the incoming segment contains data that is the next

View File

@ -1193,6 +1193,54 @@ static int net_socket_send( lua_State* L )
return net_send(L, mt); return net_send(L, mt);
} }
static int net_socket_hold( lua_State* L )
{
const char *mt = "net.socket";
struct espconn *pesp_conn = NULL;
lnet_userdata *nud;
size_t l;
nud = (lnet_userdata *)luaL_checkudata(L, 1, mt);
luaL_argcheck(L, nud, 1, "Server/Socket expected");
if(nud==NULL){
NODE_DBG("userdata is nil.\n");
return 0;
}
if(nud->pesp_conn == NULL){
NODE_DBG("nud->pesp_conn is NULL.\n");
return 0;
}
pesp_conn = nud->pesp_conn;
espconn_recv_hold(pesp_conn);
return 0;
}
static int net_socket_unhold( lua_State* L )
{
const char *mt = "net.socket";
struct espconn *pesp_conn = NULL;
lnet_userdata *nud;
size_t l;
nud = (lnet_userdata *)luaL_checkudata(L, 1, mt);
luaL_argcheck(L, nud, 1, "Server/Socket expected");
if(nud==NULL){
NODE_DBG("userdata is nil.\n");
return 0;
}
if(nud->pesp_conn == NULL){
NODE_DBG("nud->pesp_conn is NULL.\n");
return 0;
}
pesp_conn = nud->pesp_conn;
espconn_recv_unhold(pesp_conn);
return 0;
}
// Lua: socket:dns( string, function(ip) ) // Lua: socket:dns( string, function(ip) )
static int net_socket_dns( lua_State* L ) static int net_socket_dns( lua_State* L )
{ {
@ -1251,6 +1299,8 @@ static const LUA_REG_TYPE net_socket_map[] =
{ LSTRKEY( "close" ), LFUNCVAL ( net_socket_close ) }, { LSTRKEY( "close" ), LFUNCVAL ( net_socket_close ) },
{ LSTRKEY( "on" ), LFUNCVAL ( net_socket_on ) }, { LSTRKEY( "on" ), LFUNCVAL ( net_socket_on ) },
{ LSTRKEY( "send" ), LFUNCVAL ( net_socket_send ) }, { LSTRKEY( "send" ), LFUNCVAL ( net_socket_send ) },
{ LSTRKEY( "hold" ), LFUNCVAL ( net_socket_hold ) },
{ LSTRKEY( "unhold" ), LFUNCVAL ( net_socket_unhold ) },
{ LSTRKEY( "dns" ), LFUNCVAL ( net_socket_dns ) }, { LSTRKEY( "dns" ), LFUNCVAL ( net_socket_dns ) },
// { LSTRKEY( "delete" ), LFUNCVAL ( net_socket_delete ) }, // { LSTRKEY( "delete" ), LFUNCVAL ( net_socket_delete ) },
{ LSTRKEY( "__gc" ), LFUNCVAL ( net_socket_delete ) }, { LSTRKEY( "__gc" ), LFUNCVAL ( net_socket_delete ) },