Page 1 of 2
how to close secure websocket properly
Posted: Mon Mar 08, 2021 3:27 pm
by RebootExpert
I try to use the function close() to close a secure websocket and it will stop my app from working. but it runs fine with non secure websocket
Code: Select all
printf("closing wss_fd = %d\r\n", wss_fd);
close(wss_fd);
printf("wss_fd = %d closed\r\n", wss_fd);
the second print statement never execute.
Re: how to close secure websocket properly
Posted: Mon Mar 08, 2021 7:34 pm
by pbreed
That should work...
What NNDK version are you running on what platform?
Re: how to close secure websocket properly
Posted: Tue Mar 09, 2021 1:20 pm
by pbreed
I'd like to try to reproduce your issue....
Platform?
NNDK version?
Re: how to close secure websocket properly
Posted: Tue Mar 09, 2021 4:07 pm
by RebootExpert
It's 2.9.3 and mod54415. The weird thing is that sometimes it prints out and sometimes it doesn't.
Re: how to close secure websocket properly
Posted: Tue Mar 09, 2021 5:17 pm
by pbreed
Ok for close sometimes and not others, I might suspect some stack issues....
I'll see if we can recreate...
I've got a few things ahead of this on my plate, I'll see if the engineer working on TLS can take a look...
Re: how to close secure websocket properly
Posted: Wed Mar 10, 2021 11:26 am
by RebootExpert
I think close the ssl fd that associated with the secure websocket first solve the issue. Is there a function to get the ssl fd from a websocket fd? Like the function SSL_GetRawSocket(int sslSocketFd) return the tcp fd from a ssl fd. Right now I create a task monitor the state of all the ssl fd that associated with a websocket, but I don't want to have a task just for that.
I need something simple like this.
Code: Select all
if( websocket is closed remotely)
{
fd = GetFdFromWS(ws_fd);
if(IsSSLfd(fd))
close(fd);
close(ws_fd);
}
Re: how to close secure websocket properly
Posted: Thu Mar 11, 2021 3:40 pm
by pbreed
WE fixed some SSL/TLS close issues in rev 2.9.5.
Could you see if the problem exists under 2.9.5?
Re: how to close secure websocket properly
Posted: Tue Mar 16, 2021 9:33 am
by RebootExpert
When I rebuild all system files in 2.9.5, it gives me errors.
C:\nburn\gcc-m68k\msys\1.0\bin\sh.exe: *** Couldn't reserve space for cygwin's heap, Win32 error 0
make: *** [C:\nburn/make/librules.mak:48: extraio.o] Error 1
buffers.o userparam.o ftp.o arp.o md5c.o udpsocket.o tzsetchar.o aes.o system.o
0 [main] us 0 init_cheap: VirtualAlloc pointer is null, Win32 error 487
AllocationBase 0x0, BaseAddress 0x71110000, RegionSize 0x2E0000, State 0x10000
make: *** [C:\nburn/make/librules.mak:59: ftp.od] Error 1
update
follow the post by anguel in this
thread, I rebase the msys-1.0.dll to 0x30000000 solve the problem
Re: how to close secure websocket properly
Posted: Tue Mar 16, 2021 11:18 am
by RebootExpert
regard to the secure websocket closure, issue still present in the app build by 2.9.5
Re: how to close secure websocket properly
Posted: Tue Mar 16, 2021 11:46 am
by Jon
Hi RebootExpert,
It sounds like you had a working solution above, but wanted the SSL FD to close first. In this case, you can call:
int sslFd = 0;
WebSocket* ws = GetWebSocketRecord( webSocketFd );
if( ws != nullptr )
{
sslFd = ws->m_fd_tcp;
}
In this case, the TCP is actually the SSL fd, as it's assigned the return value of SSL_Connect(). You can then close this fd, and should be good to go.
Kind Regards,
Jon