static ssize_t aws_writev(struct afb_ws *ws, const struct iovec *iov, int iovcnt);
static ssize_t aws_readv(struct afb_ws *ws, const struct iovec *iov, int iovcnt);
-static void aws_disconnect(struct afb_ws *ws);
static void aws_on_close(struct afb_ws *ws, uint16_t code, size_t size);
static void aws_on_text(struct afb_ws *ws, int last, size_t size);
static void aws_on_binary(struct afb_ws *ws, int last, size_t size);
static struct websock_itf aws_itf = {
.writev = (void*)aws_writev,
.readv = (void*)aws_readv,
- .disconnect = (void*)aws_disconnect,
.on_ping = NULL,
.on_pong = NULL,
void afb_ws_close(struct afb_ws *ws, uint16_t code)
{
- websock_close_code(ws->ws, code);
+ websock_close_code(ws->ws, code, NULL, 0);
}
void afb_ws_text(struct afb_ws *ws, const char *text, size_t length)
{
- websock_text(ws->ws, text, length);
+ websock_text(ws->ws, 1, text, length);
}
void afb_ws_binary(struct afb_ws *ws, const void *data, size_t length)
{
- websock_binary(ws->ws, data, length);
+ websock_binary(ws->ws, 1, data, length);
}
static ssize_t aws_writev(struct afb_ws *ws, const struct iovec *iov, int iovcnt)
do {
rc = readv(ws->fd, iov, iovcnt);
} while(rc == -1 && errno == EINTR);
+ if (rc == 0) {
+ errno = EPIPE;
+ rc = -1;
+ }
return rc;
}
static void aws_on_readable(struct afb_ws *ws)
{
- websock_dispatch(ws->ws);
+ if (websock_dispatch(ws->ws) < 0 && errno == EPIPE)
+ afb_ws_disconnect(ws);
}
static void aws_on_hangup(struct afb_ws *ws)
afb_ws_disconnect(ws);
}
-static void aws_disconnect(struct afb_ws *ws)
-{
- afb_ws_disconnect(ws);
-}
-
static inline struct buf aws_pick_buffer(struct afb_ws *ws)
{
struct buf result = ws->buffer;
{
if (ws->type != none) {
websock_drop(ws->ws);
- websock_close_code(ws->ws, WEBSOCKET_CODE_PROTOCOL_ERROR);
+ websock_close_code(ws->ws, WEBSOCKET_CODE_PROTOCOL_ERROR, NULL, 0);
} else if (ws->itf->on_text == NULL) {
websock_drop(ws->ws);
- websock_close_code(ws->ws, WEBSOCKET_CODE_CANT_ACCEPT);
+ websock_close_code(ws->ws, WEBSOCKET_CODE_CANT_ACCEPT, NULL, 0);
} else {
ws->type = text;
aws_on_continue(ws, last, size);
{
if (ws->type != none) {
websock_drop(ws->ws);
- websock_close_code(ws->ws, WEBSOCKET_CODE_PROTOCOL_ERROR);
+ websock_close_code(ws->ws, WEBSOCKET_CODE_PROTOCOL_ERROR, NULL, 0);
} else if (ws->itf->on_binary == NULL) {
websock_drop(ws->ws);
- websock_close_code(ws->ws, WEBSOCKET_CODE_CANT_ACCEPT);
+ websock_close_code(ws->ws, WEBSOCKET_CODE_CANT_ACCEPT, NULL, 0);
} else {
ws->type = text;
aws_on_continue(ws, last, size);
if (ws->type == none) {
websock_drop(ws->ws);
- websock_close_code(ws->ws, WEBSOCKET_CODE_PROTOCOL_ERROR);
+ websock_close_code(ws->ws, WEBSOCKET_CODE_PROTOCOL_ERROR, NULL, 0);
} else {
if (!aws_read(ws, size)) {
aws_on_close(ws, WEBSOCKET_CODE_ABNORMAL, 0);