HTTPc_WebSockFmtCloseMsg()

Format a Close Frame.

Files

http-c.h/http-c.c

Prototype

          CPU_INT16U  HTTPc_WebSockFmtCloseMsg (HTTPc_WEBSOCK_CLOSE_CODE    close_code,
                                                CPU_CHAR                   *p_reason,
                                                CPU_CHAR                   *p_buf,
                                                CPU_INT16U                  buf_len,
                                                HTTPc_ERR                  *p_err)


Arguments

close_code

Close code to format in the Close message.

p_reason

Pointer to a string to be concatenated to the Close code in the Close message.

p_buf

Pointer to the buffer to set the formatted Close Message.

buf_len

Length of the buffer.

p_err

Pointer to variable that will receive the return error code from this function:

HTTPc_ERR_NONE
HTTPc_ERR_NULL_PTR
HTTPc_ERR_WEBSOCK_INVALID_CLOSE_CODE
HTTPc_ERR_WEBSOCK_INVALID_CTRL_FRAME_LEN

Returned Values

Return the length of the formatted message in the buffer.

Required Configuration

None.

Notes / Warnings

  • This function MUST be called after the µC/HTTP-client Suite Initialization has been completed.
  • Close Frame have a specific format. According to the RFC 6455 section :"If there is a body, the first two bytes of the body MUST be a 2-byte unsigned integer (in network byte order) representing a status code with value /code/ defined in Section 7.4. Following the 2-byte integer,the body MAY contain UTF-8-encoded data with value /reason/, the interpretation of which is not defined by this specification."

  • Close Codes available:

HTTPc_WEBSOCK_CLOSE_CODE_PROTOCOL_ERR
HTTPc_WEBSOCK_CLOSE_CODE_DATA_TYPE_NOT_ALLOWED
HTTPc_WEBSOCK_CLOSE_CODE_DATA_TYPE_ERR
HTTPc_WEBSOCK_CLOSE_CODE_UNEXPECTED_CONDITION 
HTTPc_WEBSOCK_CLOSE_CODE_INVALID_EXT
HTTPc_WEBSOCK_CLOSE_CODE_MSG_TOO_BIG
HTTPc_WEBSOCK_CLOSE_CODE_POLICY_VIOLATION
HTTPc_WEBSOCK_CLOSE_CODE_GOING_AWAY
HTTPc_WEBSOCK_CLOSE_CODE_NORMAL

  • Close Reason: 

    • Except for its length, the reason string has no restriction and it is user-definable. This should be used for debug purpose.

    • This field can be empty.