# mco_lews_is_websocket_close_frame
RT

### Prototype

        int mco_lews_is_websocket_close_frame(const char *buf, mco_size_t buf_size);

### Arguments

`buf`
Pointer to the raw incoming data buffer.
`buf_size`
Size (in bytes) of the buffer pointed to by `buf`.

### Description

> This function is used to detect client-initiated WebSocket shutdown requests.

> The function checks whether the provided buffer contains a valid WebSocket close control frame as defined in RFC 6455.

> It validates the following aspects of the frame:

> - Frame must be final (`FIN = 1`).
> - No reserved bits set (`RSV1–RSV3 = 0`).
> - Opcode must be `0x8` (close).
> - Payload length must be ≤ 125 bytes and not equal to 1 byte.
> - Frame must be complete (buffer size sufficient for header, mask, and payload).
> - If a close status code is present (payload ≥ 2 bytes), it must be a valid WebSocket close code (e.g., 1000, 1001, 1002, etc.).

### Return Value

`1`
The buffer contains a fully valid WebSocket close frame.
`0`
The buffer does not contain a valid close frame (e.g., wrong opcode, invalid structure, unsupported close code, or insufficient data).

### Files

Header file:
mcoewslite.h
Source file:
mcoewslite.c
Library:
mcoewslite.a