Code Review
/
src
/
app-framework-binder.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
review
|
tree
raw
|
inline
| side by side
predeclare the structure
[src/app-framework-binder.git]
/
src
/
websock.c
diff --git
a/src/websock.c
b/src/websock.c
index
945ccd9
..
afb832e
100644
(file)
--- a/
src/websock.c
+++ b/
src/websock.c
@@
-146,15
+146,18
@@
static inline int websock_send(struct websock *ws, int last, int rsv1, int rsv2,
return websock_send_internal(ws, first, buffer, size);
}
return websock_send_internal(ws, first, buffer, size);
}
-int websock_close(struct websock *ws)
+int websock_close
_empty
(struct websock *ws)
{
{
- return websock_
send(ws, 1, 0, 0, 0, OPCODE_CLOSE
, NULL, 0);
+ return websock_
close(ws, WEBSOCKET_CODE_NOT_SET
, NULL, 0);
}
}
-int websock_close
_code
(struct websock *ws, uint16_t code, const void *data, size_t length)
+int websock_close(struct websock *ws, uint16_t code, const void *data, size_t length)
{
unsigned char buffer[125];
{
unsigned char buffer[125];
+ if (code == WEBSOCKET_CODE_NOT_SET && length == 0)
+ return websock_send(ws, 1, 0, 0, 0, OPCODE_CLOSE, NULL, 0);
+
/* checks the length */
if (length > 123) {
errno = EINVAL;
/* checks the length */
if (length > 123) {
errno = EINVAL;
@@
-203,6
+206,14
@@
int websock_binary(struct websock *ws, int last, const void *data, size_t length
return websock_send(ws, last, 0, 0, 0, OPCODE_BINARY, data, length);
}
return websock_send(ws, last, 0, 0, 0, OPCODE_BINARY, data, length);
}
+int websock_error(struct websock *ws, uint16_t code, const void *data, size_t size)
+{
+ int rc = websock_close(ws, code, data, size);
+ if (ws->itf->on_error != NULL)
+ ws->itf->on_error(ws->closure, code, data, size);
+ return rc;
+}
+
static int read_header(struct websock *ws)
{
if (ws->lenhead < ws->szhead) {
static int read_header(struct websock *ws)
{
if (ws->lenhead < ws->szhead) {
@@
-397,11
+408,11
@@
loop:
goto loop;
too_long_error:
goto loop;
too_long_error:
- websock_
close_code
(ws, WEBSOCKET_CODE_MESSAGE_TOO_LARGE, NULL, 0);
+ websock_
error
(ws, WEBSOCKET_CODE_MESSAGE_TOO_LARGE, NULL, 0);
return 0;
protocol_error:
return 0;
protocol_error:
- websock_
close_code
(ws, WEBSOCKET_CODE_PROTOCOL_ERROR, NULL, 0);
+ websock_
error
(ws, WEBSOCKET_CODE_PROTOCOL_ERROR, NULL, 0);
return 0;
}
return 0;
}