Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
wsssh
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
nexlab
wsssh
Commits
c9755708
Commit
c9755708
authored
Sep 22, 2025
by
Stefy Lanza (nextime / spora )
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add timeout to polling requests to prevent hanging
parent
22069c66
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
25 additions
and
15 deletions
+25
-15
assets.o
wssshd2/assets.o
+0
-0
terminal_page.h
wssshd2/html_pages/terminal_page.h
+5
-3
image_data.h
wssshd2/image_data.h
+1
-1
terminal.html
wssshd2/templates/terminal.html
+19
-3
web.c
wssshd2/web.c
+0
-8
web.o
wssshd2/web.o
+0
-0
wssshd
wssshd2/wssshd
+0
-0
No files found.
wssshd2/assets.o
View file @
c9755708
No preview for this file type
wssshd2/html_pages/terminal_page.h
View file @
c9755708
...
...
@@ -143,6 +143,7 @@ static const char *terminal_page_html =
"let connected = false;
\n
"
"let requestId = null;
\n
"
"let pollInterval = null;
\n
"
"let polling = false;
\n
"
"
\n
"
"console.log('Terminal page loaded, adding event listeners');
\n
"
"document.getElementById('connectBtn').addEventListener('click', connect);
\n
"
...
...
@@ -450,7 +451,8 @@ static const char *terminal_page_html =
"}
\n
"
"
\n
"
"function pollData() {
\n
"
" if (!requestId) return;
\n
"
" if (!requestId || polling) return;
\n
"
" polling = true;
\n
"
" fetch('/terminal/%s/xterm/data?request_id=' + encodeURIComponent(requestId))
\n
"
" .then(response => {
\n
"
" if (response.status !== 200) {
\n
"
...
...
@@ -484,9 +486,9 @@ static const char *terminal_page_html =
" term.write(data);
\n
"
" }
\n
"
" }
\n
"
" // Schedule next poll
immediately for long polling
\n
"
" // Schedule next poll
\n
"
" if (pollInterval) {
\n
"
" pollInterval = setTimeout(pollData,
5
0);
\n
"
" pollInterval = setTimeout(pollData,
100
0);
\n
"
" }
\n
"
" }
\n
"
" })
\n
"
...
...
wssshd2/image_data.h
View file @
c9755708
...
...
@@ -8,7 +8,7 @@ unsigned char image_jpg[] = {
0x70
,
0x9c
,
0xba
,
0x51
,
0x3c
,
0x00
,
0x00
,
0x00
,
0x06
,
0x62
,
0x4b
,
0x47
,
0x44
,
0x00
,
0xff
,
0x00
,
0xff
,
0x00
,
0xff
,
0xa0
,
0xbd
,
0xa7
,
0x93
,
0x00
,
0x00
,
0x00
,
0x07
,
0x74
,
0x49
,
0x4d
,
0x45
,
0x07
,
0xe9
,
0x09
,
0x16
,
0x10
,
0x
06
,
0x26
,
0x1d
,
0x8c
,
0x0b
,
0xd3
,
0x00
,
0x00
,
0x05
,
0xd4
,
0x7a
,
0x54
,
0x
13
,
0x35
,
0xae
,
0x87
,
0xac
,
0x19
,
0x00
,
0x00
,
0x05
,
0xd4
,
0x7a
,
0x54
,
0x58
,
0x74
,
0x52
,
0x61
,
0x77
,
0x20
,
0x70
,
0x72
,
0x6f
,
0x66
,
0x69
,
0x6c
,
0x65
,
0x20
,
0x74
,
0x79
,
0x70
,
0x65
,
0x20
,
0x61
,
0x70
,
0x70
,
0x31
,
0x00
,
0x00
,
0x48
,
0x89
,
0x85
,
0x96
,
0x59
,
0x92
,
0xdc
,
0x38
,
0x10
,
0x43
,
0xff
,
...
...
wssshd2/templates/terminal.html
View file @
c9755708
...
...
@@ -429,7 +429,23 @@ function disconnect() {
function
pollData
()
{
if
(
!
requestId
||
polling
)
return
;
polling
=
true
;
fetch
(
'/terminal/%s/xterm/data?request_id='
+
encodeURIComponent
(
requestId
))
const
controller
=
new
AbortController
();
const
timeoutId
=
setTimeout
(()
=>
controller
.
abort
(),
10000
);
// 10 second timeout
fetch
(
'/terminal/%s/xterm/data?request_id='
+
encodeURIComponent
(
requestId
),
{
signal
:
controller
.
signal
})
.
then
(
response
=>
{
clearTimeout
(
timeoutId
);
if
(
response
.
status
!==
200
)
{
console
.
log
(
'Poll response status:'
,
response
.
status
);
}
const
contentType
=
response
.
headers
.
get
(
'content-type'
);
if
(
contentType
&&
contentType
.
includes
(
'json'
))
{
return
response
.
json
();
}
else
{
return
response
.
arrayBuffer
();
}
})
.
then
(
response
=>
{
if
(
response
.
status
!==
200
)
{
console
.
log
(
'Poll response status:'
,
response
.
status
);
...
...
@@ -462,9 +478,9 @@ function pollData() {
term
.
write
(
data
);
}
}
// Schedule next poll
immediately for long polling
// Schedule next poll
if
(
pollInterval
)
{
pollInterval
=
setTimeout
(
pollData
,
5
0
);
pollInterval
=
setTimeout
(
pollData
,
100
0
);
}
}
})
...
...
wssshd2/web.c
View file @
c9755708
...
...
@@ -1332,14 +1332,6 @@ static void handle_request(int client_fd, const http_request_t *req) {
session_ended
=
true
;
}
else
{
output
=
terminal_get_output
(
active_terminals
[
i
],
&
output_len
);
// Long polling: if no data, wait up to 5 seconds for data
if
(
output_len
==
0
)
{
for
(
int
wait
=
0
;
wait
<
5
;
wait
++
)
{
sleep
(
1
);
output
=
terminal_get_output
(
active_terminals
[
i
],
&
output_len
);
if
(
output_len
>
0
)
break
;
}
}
}
break
;
}
...
...
wssshd2/web.o
View file @
c9755708
No preview for this file type
wssshd2/wssshd
View file @
c9755708
No preview for this file type
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