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
f9dd2815
Commit
f9dd2815
authored
Sep 24, 2025
by
Stefy Lanza (nextime / spora )
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
working noVNC
parent
72788b3f
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
19 additions
and
4 deletions
+19
-4
websocket_protocol.c
wssshd2/websocket_protocol.c
+19
-4
No files found.
wssshd2/websocket_protocol.c
View file @
f9dd2815
...
@@ -23,6 +23,7 @@
...
@@ -23,6 +23,7 @@
#include <unistd.h>
#include <unistd.h>
#include <errno.h>
#include <errno.h>
#include <string.h> // for strerror
#include <string.h> // for strerror
#include <fcntl.h>
#include <openssl/sha.h>
#include <openssl/sha.h>
#include <openssl/ssl.h>
#include <openssl/ssl.h>
#include "websocket_protocol.h"
#include "websocket_protocol.h"
...
@@ -588,10 +589,19 @@ bool ws_send_binary_frame(ws_connection_t *conn, const void *data, size_t len, b
...
@@ -588,10 +589,19 @@ bool ws_send_binary_frame(ws_connection_t *conn, const void *data, size_t len, b
memcpy
(
frame
+
header_len
,
data
,
len
);
memcpy
(
frame
+
header_len
,
data
,
len
);
}
}
// Send frame with partial write handling and retry logic
// Send frame - for WebSocket binary frames, we need to send atomically
// Temporarily set socket to blocking mode to ensure complete frame transmission
int
original_flags
=
-
1
;
if
(
!
conn
->
ssl
)
{
original_flags
=
fcntl
(
conn
->
sock_fd
,
F_GETFL
,
0
);
if
(
original_flags
!=
-
1
)
{
fcntl
(
conn
->
sock_fd
,
F_SETFL
,
original_flags
&
~
O_NONBLOCK
);
}
}
int
total_written
=
0
;
int
total_written
=
0
;
int
retry_count
=
0
;
int
retry_count
=
0
;
const
int
max_retries
=
5
;
const
int
max_retries
=
10
;
if
(
debug
)
printf
(
"[WS-BINARY] Sending frame of total length %zu
\n
"
,
frame_len
);
if
(
debug
)
printf
(
"[WS-BINARY] Sending frame of total length %zu
\n
"
,
frame_len
);
...
@@ -619,8 +629,8 @@ bool ws_send_binary_frame(ws_connection_t *conn, const void *data, size_t len, b
...
@@ -619,8 +629,8 @@ bool ws_send_binary_frame(ws_connection_t *conn, const void *data, size_t len, b
written
=
write
(
conn
->
sock_fd
,
frame
+
total_written
,
to_write
);
written
=
write
(
conn
->
sock_fd
,
frame
+
total_written
,
to_write
);
if
(
written
<
0
)
{
if
(
written
<
0
)
{
if
(
errno
==
EAGAIN
||
errno
==
EWOULDBLOCK
)
{
if
(
errno
==
EAGAIN
||
errno
==
EWOULDBLOCK
)
{
//
Non-blocking socket, try again
//
Should not happen in blocking mode, but handle anyway
if
(
debug
)
printf
(
"[WS-BINARY] Socket would block, retrying
\n
"
);
if
(
debug
)
printf
(
"[WS-BINARY] Socket would block
in blocking mode
, retrying
\n
"
);
retry_count
++
;
retry_count
++
;
usleep
(
1000
);
// Short delay before retry
usleep
(
1000
);
// Short delay before retry
continue
;
continue
;
...
@@ -643,6 +653,11 @@ bool ws_send_binary_frame(ws_connection_t *conn, const void *data, size_t len, b
...
@@ -643,6 +653,11 @@ bool ws_send_binary_frame(ws_connection_t *conn, const void *data, size_t len, b
if
(
debug
)
printf
(
"[WS-BINARY] Wrote %d bytes, total written: %d/%zu
\n
"
,
written
,
total_written
,
frame_len
);
if
(
debug
)
printf
(
"[WS-BINARY] Wrote %d bytes, total written: %d/%zu
\n
"
,
written
,
total_written
,
frame_len
);
}
}
// Restore original socket flags
if
(
!
conn
->
ssl
&&
original_flags
!=
-
1
)
{
fcntl
(
conn
->
sock_fd
,
F_SETFL
,
original_flags
);
}
if
(
total_written
!=
(
int
)
frame_len
)
{
if
(
total_written
!=
(
int
)
frame_len
)
{
if
(
debug
)
printf
(
"[WS-BINARY] Failed to write complete frame: %d/%zu
\n
"
,
total_written
,
frame_len
);
if
(
debug
)
printf
(
"[WS-BINARY] Failed to write complete frame: %d/%zu
\n
"
,
total_written
,
frame_len
);
free
(
frame
);
free
(
frame
);
...
...
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