Edit

kc3-lang/libevent/include/event2/ws.h

Branch :

  • Show log

    Commit

  • Author : Dmitry Ilyin
    Date : 2023-08-31 22:38:41
    Hash : f39ad1c4
    Message : ws: replace evws_send with evws_send_text/evws_send_binary (ABI breakage) (#1500) Replace evws_send with evws_send_text, and introduce new API - evws_send_binary, that can be used to send binary frames. But note, that this commit breaks the ABI compatibility, but it should be OK, since there was only alpha release with evws_send, and nobody should rely on this, and I hope nobody does (we decided to go this way to avoid supporting deprecated API).

  • include/event2/ws.h
  • #ifndef EVENT2_WS_H_INCLUDED_
    #define EVENT2_WS_H_INCLUDED_
    
    #ifdef __cplusplus
    extern "C" {
    #endif
    
    struct evws_connection;
    
    #define WS_CR_NONE 0
    #define WS_CR_NORMAL 1000
    #define WS_CR_PROTO_ERR 1002
    #define WS_CR_DATA_TOO_BIG 1009
    
    #define WS_TEXT_FRAME 0x1
    #define WS_BINARY_FRAME 0x2
    
    typedef void (*ws_on_msg_cb)(
    	struct evws_connection *, int type, const unsigned char *, size_t, void *);
    typedef void (*ws_on_close_cb)(struct evws_connection *, void *);
    
    /** Opens new WebSocket session from HTTP request.
      @param req a request object
      @param cb the callback function that gets invoked on receiving message
      with len bytes length. In case of receiving text messages user is responsible
      to make a string with terminating \0 (with copying-out data) or use text data
      other way in which \0 is not required
      @param arg an additional context argument for the callback
      @return a pointer to a newly initialized WebSocket connection or NULL
    	on error
      @see evws_close()
     */
    EVENT2_EXPORT_SYMBOL
    struct evws_connection *evws_new_session(
    	struct evhttp_request *req, ws_on_msg_cb, void *arg, int options);
    
    /** Sends text data over WebSocket connection */
    EVENT2_EXPORT_SYMBOL
    void evws_send_text(struct evws_connection *evws, const char *packet_str);
    
    /** Sends binary data over WebSocket connection */
    EVENT2_EXPORT_SYMBOL
    void evws_send_binary(
    	struct evws_connection *evws, const char *packet_data, size_t packet_len);
    
    /** Closes a WebSocket connection with reason code */
    EVENT2_EXPORT_SYMBOL
    void evws_close(struct evws_connection *evws, uint16_t reason);
    
    /** Sets a callback for connection close. */
    EVENT2_EXPORT_SYMBOL
    void evws_connection_set_closecb(
    	struct evws_connection *evws, ws_on_close_cb, void *);
    
    /** Frees a WebSocket connection */
    EVENT2_EXPORT_SYMBOL
    void evws_connection_free(struct evws_connection *evws);
    
    /**
     * Return the bufferevent that an evws_connection is using.
     */
    EVENT2_EXPORT_SYMBOL
    struct bufferevent *evws_connection_get_bufferevent(
    	struct evws_connection *evws);
    
    #ifdef __cplusplus
    }
    #endif
    
    #endif