Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
ruanhaishen
Nodemcu Firmware
Commits
a9398b1d
Commit
a9398b1d
authored
Feb 09, 2015
by
zeroday
Browse files
Merge pull request #196 from Point-less/master
Added the hold and unhold methods to tcp socket
parents
0fe694b1
929d4aed
Changes
8
Hide whitespace changes
Inline
Side-by-side
app/include/lwip/app/espconn.h
View file @
a9398b1d
...
...
@@ -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
);
/******************************************************************************
* 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
app/include/lwip/tcp.h
View file @
a9398b1d
...
...
@@ -277,6 +277,8 @@ struct tcp_pcb {
/* KEEPALIVE counter */
u8_t
keep_cnt_sent
;
u8_t
hold
;
};
struct
tcp_pcb_listen
{
...
...
app/lwip/app/espconn.c
View file @
a9398b1d
...
...
@@ -718,3 +718,32 @@ espconn_gethostbyname(struct espconn *pespconn, const char *hostname, ip_addr_t
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
;
}
app/lwip/app/espconn_tcp.c
View file @
a9398b1d
...
...
@@ -948,3 +948,19 @@ sint8 ICACHE_FLASH_ATTR espconn_tcp_delete(struct espconn *pdeletecon)
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
;
}
app/lwip/core/tcp.c
View file @
a9398b1d
...
...
@@ -1259,6 +1259,7 @@ tcp_alloc(u8_t prio)
#endif
/* LWIP_TCP_KEEPALIVE */
pcb
->
keep_cnt_sent
=
0
;
//���ķ��ʹ���
pcb
->
hold
=
0
;
}
return
pcb
;
}
...
...
app/lwip/core/tcp_in.c
View file @
a9398b1d
...
...
@@ -1137,7 +1137,7 @@ tcp_receive(struct tcp_pcb *pcb)
/* If the incoming segment contains data, we must process it
further. */
if
(
tcplen
>
0
)
{
if
(
(
tcplen
>
0
)
&&
(
!
pcb
->
hold
))
{
/* This code basically does three things:
+) If the incoming segment contains data that is the next
...
...
app/modules/mqtt.c
View file @
a9398b1d
...
...
@@ -725,8 +725,15 @@ static int mqtt_socket_connect( lua_State* L )
if
(
mud
==
NULL
)
return
0
;
if
(
mud
->
pesp_conn
)
c_free
(
mud
->
pesp_conn
);
if
(
mud
->
pesp_conn
){
//TODO: should I free tcp struct directly or ask user to call close()???
mud
->
pesp_conn
->
reverse
=
NULL
;
if
(
mud
->
pesp_conn
->
proto
.
tcp
)
c_free
(
mud
->
pesp_conn
->
proto
.
tcp
);
mud
->
pesp_conn
->
proto
.
tcp
=
NULL
;
c_free
(
mud
->
pesp_conn
);
mud
->
pesp_conn
=
NULL
;
}
struct
espconn
*
pesp_conn
=
NULL
;
pesp_conn
=
mud
->
pesp_conn
=
(
struct
espconn
*
)
c_zalloc
(
sizeof
(
struct
espconn
));
if
(
!
pesp_conn
)
...
...
app/modules/net.c
View file @
a9398b1d
...
...
@@ -665,6 +665,10 @@ static int net_start( lua_State* L, const char* mt )
return
0
;
}
if
(
nud
->
pesp_conn
==
NULL
){
NODE_DBG
(
"nud->pesp_conn is NULL.
\n
"
);
return
0
;
}
pesp_conn
=
nud
->
pesp_conn
;
port
=
luaL_checkinteger
(
L
,
stack
);
stack
++
;
...
...
@@ -1074,6 +1078,10 @@ static int net_dns( lua_State* L, const char* mt )
return
0
;
}
if
(
nud
->
pesp_conn
==
NULL
){
NODE_DBG
(
"nud->pesp_conn is NULL.
\n
"
);
return
0
;
}
pesp_conn
=
nud
->
pesp_conn
;
if
(
!
isserver
||
pesp_conn
->
type
==
ESPCONN_UDP
){
// self_ref is only needed by socket userdata, or udp server
...
...
@@ -1185,6 +1193,54 @@ static int net_socket_send( lua_State* L )
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) )
static
int
net_socket_dns
(
lua_State
*
L
)
{
...
...
@@ -1243,6 +1299,8 @@ static const LUA_REG_TYPE net_socket_map[] =
{
LSTRKEY
(
"close"
),
LFUNCVAL
(
net_socket_close
)
},
{
LSTRKEY
(
"on"
),
LFUNCVAL
(
net_socket_on
)
},
{
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( "delete" ), LFUNCVAL ( net_socket_delete ) },
{
LSTRKEY
(
"__gc"
),
LFUNCVAL
(
net_socket_delete
)
},
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment