Skip to content

Commit 6a2e89c

Browse files
author
zeroflag
committed
added read-timeout (sec) to individual netcons #23
1 parent ca6b6d1 commit 6a2e89c

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

arch/esp8266/ext.S

+15
Original file line numberDiff line numberDiff line change
@@ -229,12 +229,27 @@ defprimitive "ms",2,ms,REGULAR
229229
CCALL forth_delay_ms
230230
NEXT
231231

232+
// internal timeout
232233
defprimitive "netcon-set-recvtimeout",22,netcon_set_recvtimeout,REGULAR
233234
DPOP a2 // conn
234235
DPOP a3 // recv timeout ms
235236
CCALL forth_netcon_set_recvtimeout
236237
NEXT
237238

239+
// get user defined socket read timeout
240+
defprimitive "netcon-read-timeout@",20,netcon_get_readtimeout,REGULAR
241+
DPOP a2 // netcon
242+
CCALL forth_netcon_get_read_timeout
243+
DPUSH a2 // timeout_sec
244+
NEXT
245+
246+
// set user defined socket read timeout
247+
defprimitive "netcon-read-timeout!",20,netcon_set_readtimeout,REGULAR
248+
DPOP a2 // netcon
249+
DPOP a3 // timeout_sec
250+
CCALL forth_netcon_set_read_timeout
251+
NEXT
252+
238253
defprimitive "netcon-new",10,netcon_new,REGULAR
239254
DPOP a2 // conn type
240255
CCALL forth_netcon_new

arch/esp8266/rtos/user/forth_netconn.c

+10
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ struct forth_netconn {
88
struct netconn* conn;
99
struct netbuf* nbuf;
1010
int bufpos;
11+
int read_timeout_sec;
1112
};
1213

1314
struct forth_netconn* make_forth_netconn(struct netconn* conn) {
@@ -16,9 +17,18 @@ struct forth_netconn* make_forth_netconn(struct netconn* conn) {
1617
result->conn = conn;
1718
result->nbuf = NULL;
1819
result->bufpos = 0;
20+
result->read_timeout_sec = -1;
1921
return result;
2022
}
2123

24+
int forth_netcon_get_read_timeout(struct forth_netconn* conn) {
25+
return conn->read_timeout_sec;
26+
}
27+
28+
void forth_netcon_set_read_timeout(struct forth_netconn* conn, int seconds) {
29+
conn->read_timeout_sec = seconds;
30+
}
31+
2232
struct forth_netconn* forth_netcon_new(int type) {
2333
enum netconn_type con_type;
2434
//printf("New netcon type: %d\n", type);

0 commit comments

Comments
 (0)