Skip to content

Commit 190990c

Browse files
committed
Improve on error
1 parent e9be638 commit 190990c

File tree

2 files changed

+16
-23
lines changed

2 files changed

+16
-23
lines changed

itest/test_ws.py

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,14 @@
11
#!/usr/bin/env python
22
import asyncio
3-
import pickle
4-
import time
5-
import msgpack
6-
import ssl
7-
import struct
83
from lib import run_test
94
from lib import default_test_setup
105
from lib.testbase import TestBase
116
from lib.client import get_client
12-
from thingsdb.exceptions import AssertionError
13-
from thingsdb.exceptions import ValueError
14-
from thingsdb.exceptions import TypeError
15-
from thingsdb.exceptions import NumArgumentsError
16-
from thingsdb.exceptions import BadDataError
17-
from thingsdb.exceptions import LookupError
18-
from thingsdb.exceptions import OverflowError
19-
from thingsdb.exceptions import ZeroDivisionError
20-
from thingsdb.exceptions import OperationError
7+
from thingsdb.client import Client
8+
9+
# The following code can be used to lower or increase the max package size
10+
# from thingsdb.client import protocol
11+
# protocol.WEBSOCKET_MAX_SIZE = 2**8
2112

2213

2314
class TestWS(TestBase):
@@ -39,7 +30,7 @@ async def run(self):
3930
await client.wait_closed()
4031
await asyncio.sleep(1) # sleep is required for nice close
4132

42-
async def test_simple_ws(self, client):
33+
async def test_simple_ws(self, client: Client):
4334
self.assertTrue(client.is_websocket())
4435
info = client.connection_info()
4536
self.assertIsInstance(info, str)

src/ti/ws.c

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,11 @@ static int ws__callback_established(struct lws * wsi, ti_ws_t * pss)
5151
return -1;
5252
}
5353

54-
static inline void ws__write_done(ti_ws_t * pss)
54+
static inline void ws__done(ti_ws_t * pss, ti_write_t * req, ex_enum status)
5555
{
5656
(void) queue_shift(pss->queue);
5757
pss->f = 0; /* reset to frame 0 */
58+
req->cb_(req, status);
5859
}
5960

6061
static int ws__callback_server_writable(struct lws * wsi, ti_ws_t * pss)
@@ -99,16 +100,12 @@ static int ws__callback_server_writable(struct lws * wsi, ti_ws_t * pss)
99100
if (m < (int) len)
100101
{
101102
log_error("ERROR %d; writing to WebSocket", m);
102-
ws__write_done(pss); /* reset to frame 0 and shift from queue */
103-
req->cb_(req, EX_WRITE_UV);
103+
ws__done(pss, req, EX_WRITE_UV);
104104
return -1;
105105
}
106106

107107
if (is_end)
108-
{
109-
ws__write_done(pss); /* reset to frame 0 and shift from queue */
110-
req->cb_(req, 0);
111-
}
108+
ws__done(pss, req, 0);
112109
else
113110
pss->f++; /* next frame */
114111

@@ -179,6 +176,11 @@ struct per_vhost_data__minimal {
179176
const struct lws_protocols *protocol;
180177
};
181178

179+
static void ws__drop_req(ti_write_t * req)
180+
{
181+
req->cb_(req, EX_WRITE_UV);
182+
}
183+
182184
/* Callback function for WebSocket server messages */
183185
int ws__callback(
184186
struct lws * wsi,
@@ -202,8 +204,8 @@ int ws__callback(
202204
case LWS_CALLBACK_CLOSED:
203205
if (pss->stream)
204206
{
207+
queue_destroy(pss->queue, (queue_destroy_cb) ws__drop_req);
205208
ti_stream_close(pss->stream);
206-
queue_destroy(pss->queue, free);
207209
}
208210
break;
209211
default:

0 commit comments

Comments
 (0)