Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit5ee3578

Browse files
chore: some code cleanup
1 parentc34b7fc commit5ee3578

File tree

10 files changed

+62
-58
lines changed

10 files changed

+62
-58
lines changed

‎components/esp32-javascript/modules/esp32-javascript/global.js‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,5 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
2121
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2222
SOFTWARE.
2323
*/
24+
// make `global` available for compatibility reasons. For new features use globalThis instead.
2425
globalThis.global=globalThis;

‎components/esp32-javascript/modules/esp32-javascript/global.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,5 @@ SOFTWARE.
2424

2525
/* eslint-disable no-var */
2626
declarevarglobal:any;
27-
(globalThisasany).global=globalThis;
27+
// make `global` available for compatibility reasons. For new features use globalThis instead.
28+
(globalThisasany).global=globalThis;

‎components/esp32-javascript/modules/esp32-js-eventloop/index.js‎

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -125,18 +125,16 @@ function el_select_next() {
125125
functionstart(){
126126
varnextfuncs=[main];
127127
for(;;){
128-
if(Array.isArray(nextfuncs)){
129-
nextfuncs.forEach(function(nf){
130-
if(typeofnf==="function"){
131-
try{
132-
nf();
133-
}
134-
catch(error){
135-
internalErrorHandler(error);
136-
}
128+
nextfuncs.forEach(function(nf){
129+
if(typeofnf==="function"){
130+
try{
131+
nf();
137132
}
138-
});
139-
}
133+
catch(error){
134+
internalErrorHandler(error);
135+
}
136+
}
137+
});
140138
nextfuncs=el_select_next();
141139
}
142140
}

‎components/esp32-javascript/modules/esp32-js-eventloop/index.ts‎

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -175,17 +175,15 @@ function el_select_next() {
175175
exportfunctionstart():void{
176176
letnextfuncs:(()=>void)[]=[main];
177177
for(;;){
178-
if(Array.isArray(nextfuncs)){
179-
nextfuncs.forEach(function(nf){
180-
if(typeofnf==="function"){
181-
try{
182-
nf();
183-
}catch(error){
184-
internalErrorHandler(error);
185-
}
178+
nextfuncs.forEach(function(nf){
179+
if(typeofnf==="function"){
180+
try{
181+
nf();
182+
}catch(error){
183+
internalErrorHandler(error);
186184
}
187-
});
188-
}
185+
}
186+
});
189187
nextfuncs=el_select_next();
190188
}
191189
}

‎components/socket-events/modules/socket-events/index.js‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,9 @@ var Socket = /** @class */ (function () {
158158
this.clearReadTimeoutTimer();
159159
if(this.readTimeout>0){
160160
this.readTimeoutHandle=setTimeout(function(){
161-
console.debug("Close socket because of read timeout.");
161+
if(console.isDebug){
162+
console.debug("Close socket because of read timeout.");
163+
}
162164
closeSocket(_this);
163165
},this.readTimeout);
164166
}

‎components/socket-events/modules/socket-events/index.ts‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,9 @@ class Socket implements Esp32JsSocket {
188188
this.clearReadTimeoutTimer();
189189
if(this.readTimeout>0){
190190
this.readTimeoutHandle=setTimeout(()=>{
191-
console.debug("Close socket because of read timeout.");
191+
if(console.isDebug){
192+
console.debug("Close socket because of read timeout.");
193+
}
192194
closeSocket(this);
193195
},this.readTimeout);
194196
}

‎components/socket-events/socket-events.c‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -238,9 +238,7 @@ void select_task_it()
238238
if (dataAvailable>0)
239239
{
240240
charmsg[dataAvailable];
241-
structsockaddr_inremaddr;
242-
socklen_taddrlen=sizeof(remaddr);
243-
if (recvfrom(selectServerSocket,msg,dataAvailable,0, (structsockaddr*)&remaddr,&addrlen)<0)
241+
if (recv(selectServerSocket,msg,dataAvailable,0)<0)
244242
{
245243
jslog(ERROR,"READ self-socket FAILED: %d",errno);
246244
}

‎components/socket-events/tcp.c‎

Lines changed: 31 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,37 @@ SOFTWARE.
3737
#include"esp32-js-log.h"
3838
#include"esp32-javascript.h"
3939

40-
#defineBUFSIZE 1024
4140
#defineLISTEN_BACKLOG 50
4241

42+
intsetNonBlocking(intsockfd)
43+
{
44+
intopt=1;
45+
intret=lwip_ioctl(sockfd,FIONBIO,&opt);
46+
47+
if (ret >=0)
48+
{
49+
structtimevaltv;
50+
tv.tv_sec=0;
51+
tv.tv_usec=1;
52+
53+
if (lwip_setsockopt(sockfd,
54+
SOL_SOCKET,
55+
SO_RCVTIMEO,
56+
&tv,
57+
sizeof(structtimeval))<0)
58+
{
59+
jslog(ERROR,"Cannot set timeout opt.");
60+
return-1;
61+
}
62+
}
63+
64+
returnret;
65+
}
66+
4367
intcreateNonBlockingSocket(intdomain,inttype,intprotocol,boolnonblocking)
4468
{
4569
intsockfd;
46-
intopt;
70+
4771
intret;
4872

4973
/* socket: create the socket */
@@ -56,8 +80,7 @@ int createNonBlockingSocket(int domain, int type, int protocol, bool nonblocking
5680

5781
if (nonblocking)
5882
{
59-
opt=1;
60-
ret=lwip_ioctl(sockfd,FIONBIO,&opt);
83+
intret=setNonBlocking(sockfd);
6184
if (ret<0)
6285
{
6386
jslog(ERROR,"Cannot set non-blocking opt.");
@@ -78,7 +101,7 @@ int connectNonBlocking(int sockfd, const char *hostname, int portno)
78101
server=gethostbyname(hostname);
79102
if (server==NULL)
80103
{
81-
jslog(ERROR,"ERROR, no such hostas%s",hostname);
104+
jslog(ERROR,"ERROR, no such host %s",hostname);
82105
return-1;
83106
}
84107

@@ -107,8 +130,7 @@ int acceptIncoming(int sockfd)
107130
intone=1;
108131
setsockopt(cfd,SOL_SOCKET,SO_REUSEADDR,&one,sizeof(one));
109132

110-
intopt=1;
111-
intret=lwip_ioctl(cfd,FIONBIO,&opt);
133+
intret=setNonBlocking(sockfd);
112134
if (ret<0)
113135
{
114136
jslog(ERROR,"ERROR while accepting and setting non blocking: %d",errno);
@@ -183,34 +205,16 @@ int writeSocket(int sockfd, const char *msg, int len, SSL *ssl)
183205

184206
intreadSocket(intsockfd,char*msg,intlen)
185207
{
186-
structsockaddr_inremaddr;
187-
socklen_taddrlen=sizeof(remaddr);
188-
189208
intresult=0;
190209

191-
intopt=1;
192-
intret=lwip_ioctl(sockfd,FIONBIO,&opt);
210+
intret=setNonBlocking(sockfd);
193211
if (ret<0)
194212
{
195213
jslog(ERROR,"Cannot set non-blocking opt.");
196214
return-1;
197215
}
198216

199-
structtimevaltv;
200-
tv.tv_sec=1;
201-
tv.tv_usec=0;
202-
203-
if (lwip_setsockopt(sockfd,
204-
SOL_SOCKET,
205-
SO_RCVTIMEO,
206-
&tv,
207-
sizeof(structtimeval))<0)
208-
{
209-
jslog(ERROR,"Cannot set timeout opt.");
210-
return-1;
211-
}
212-
213-
result=recvfrom(sockfd,msg,len,MSG_DONTWAIT, (structsockaddr*)&remaddr,&addrlen);
217+
result=recv(sockfd,msg,len,MSG_DONTWAIT);
214218
returnresult;
215219
}
216220

‎examples/repl.js‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
* After that you can type every JS expression, which then gets
1313
* evaluated in esp32-javascript and the result is printed.
1414
*
15-
* This is only considered as demo. If you want to use it in production
16-
* please change the ssl flag to true, otherwise credentials
15+
* This is only considered as demo. If you want to use it in production
16+
* please change the ssl flag to true, otherwise credentials
1717
* are visible for "persons in the middle".
1818
*/
1919
varconfigManager=require("esp32-javascript/config");
@@ -78,7 +78,7 @@ require("socket-events").sockListen(
7878
logOutput.push("ERROR|"+msg+"\n");
7979
},
8080
};
81-
_=eval(data);
81+
_=eval.call(globalThis,data);
8282
}finally{
8383
console=_console;
8484
}

‎sdkconfig.defaults‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -665,7 +665,7 @@ CONFIG_LWIP_DNS_SUPPORT_MDNS_QUERIES=y
665665
# CONFIG_LWIP_L2_TO_L3_COPY is not set
666666
CONFIG_LWIP_IRAM_OPTIMIZATION=y
667667
CONFIG_LWIP_TIMERS_ONDEMAND=y
668-
CONFIG_LWIP_MAX_SOCKETS=10
668+
CONFIG_LWIP_MAX_SOCKETS=12
669669
CONFIG_LWIP_USE_ONLY_LWIP_SELECT=y
670670
# CONFIG_LWIP_SO_LINGER is not set
671671
CONFIG_LWIP_SO_REUSE=y

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp