Skip to content

Commit d27c5a5

Browse files
committed
Set error code when websocket pack fails
1 parent 6f09d43 commit d27c5a5

File tree

2 files changed

+5
-0
lines changed

2 files changed

+5
-0
lines changed

ext-src/swoole_websocket_server.cc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -813,6 +813,8 @@ static PHP_METHOD(swoole_websocket_server, push) {
813813
#ifdef SW_HAVE_ZLIB
814814
Connection *conn = serv->get_connection_verify(fd);
815815
if (!conn) {
816+
swoole_set_last_error(SW_ERROR_SESSION_NOT_EXIST);
817+
php_swoole_fatal_error(E_WARNING, "session#%ld does not exists", fd);
816818
RETURN_FALSE;
817819
}
818820
allow_compress = conn->websocket_compression;
@@ -821,11 +823,13 @@ static PHP_METHOD(swoole_websocket_server, push) {
821823
swoole_http_buffer->clear();
822824
if (php_swoole_websocket_frame_is_object(zdata)) {
823825
if (php_swoole_websocket_frame_object_pack(swoole_http_buffer, zdata, 0, allow_compress) < 0) {
826+
swoole_set_last_error(SW_ERROR_WEBSOCKET_PACK_FAILED);
824827
RETURN_FALSE;
825828
}
826829
} else {
827830
if (php_swoole_websocket_frame_pack(
828831
swoole_http_buffer, zdata, opcode, flags & WebSocket::FLAGS_ALL, 0, allow_compress) < 0) {
832+
swoole_set_last_error(SW_ERROR_WEBSOCKET_PACK_FAILED);
829833
RETURN_FALSE;
830834
}
831835
}

include/swoole_error.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ enum swErrorCode {
128128
SW_ERROR_WEBSOCKET_BAD_OPCODE,
129129
SW_ERROR_WEBSOCKET_UNCONNECTED,
130130
SW_ERROR_WEBSOCKET_HANDSHAKE_FAILED,
131+
SW_ERROR_WEBSOCKET_PACK_FAILED,
131132

132133
/**
133134
* server global error

0 commit comments

Comments
 (0)