- websock_send(ws, OPCODE_CLOSE, buffer, 2);
+ if (length != 0)
+ memcpy(&buffer[2], data, length);
+
+ /* Send server-side closing handshake */
+ return websock_send(ws, 1, 0, 0, 0, OPCODE_CLOSE, buffer, 2 + length);
+}
+
+int websock_ping(struct websock *ws, const void *data, size_t length)
+{
+ /* checks the length */
+ if (length > 125) {
+ errno = EINVAL;
+ return -1;
+ }
+
+ return websock_send(ws, 1, 0, 0, 0, OPCODE_PING, data, length);