introdice tracking if frame is binary 33/2933/1
authorAndy Green <andy.green@linaro.org>
Fri, 18 Jan 2013 01:49:20 +0000 (09:49 +0800)
committerKevron Rees <kevron_m_rees@linux.intel.com>
Thu, 7 Mar 2013 21:01:26 +0000 (13:01 -0800)
Signed-off-by: Andy Green <andy.green@linaro.org>
lib/libwebsockets.h
lib/parsers.c
lib/private-libwebsockets.h
libwebsockets-api-doc.html

index 9055f9b..404d525 100644 (file)
@@ -828,6 +828,9 @@ lws_daemonize(const char *_lock_path);
 LWS_EXTERN int
 lws_send_pipe_choked(struct libwebsocket *wsi);
 
+LWS_EXTERN int
+lws_frame_is_binary(struct libwebsocket *wsi);
+
 LWS_EXTERN unsigned char *
 libwebsockets_SHA1(const unsigned char *d, size_t n, unsigned char *md);
 
index 5563df7..a1e4a48 100644 (file)
@@ -611,6 +611,20 @@ xor_mask_05(struct libwebsocket *wsi, unsigned char c)
        return c ^ wsi->frame_masking_nonce_04[(wsi->frame_mask_index++) & 3];
 }
 
+/**
+ * lws_frame_is_binary: true if the current frame was sent in binary mode
+ *
+ * @wsi: the connection we are inquiring about
+ *
+ * This is intended to be called from the LWS_CALLBACK_RECEIVE callback if
+ * it's interested to see if the frame it's dealing with was sent in binary
+ * mode.
+ */
+
+int lws_frame_is_binary(struct libwebsocket *wsi)
+{
+       return wsi->frame_is_binary;
+}
 
 
 int
@@ -1083,9 +1097,10 @@ spill:
                        wsi->rx_user_buffer_head = 0;
                        return 0;
 
-               case LWS_WS_OPCODE_07__CONTINUATION:
                case LWS_WS_OPCODE_07__TEXT_FRAME:
                case LWS_WS_OPCODE_07__BINARY_FRAME:
+                       wsi->frame_is_binary = wsi->opcode == LWS_WS_OPCODE_07__BINARY_FRAME;
+               case LWS_WS_OPCODE_07__CONTINUATION:
                        break;
 
                default:
index 8374bb6..8c52c81 100644 (file)
@@ -367,6 +367,7 @@ struct libwebsocket {
        unsigned char opcode;
        unsigned char final;
        unsigned char rsv;
+       int frame_is_binary:1;
 
        int pings_vs_pongs;
        unsigned char (*xor_mask)(struct libwebsocket *, unsigned char);
index bd734dc..73aefe8 100644 (file)
@@ -370,6 +370,22 @@ log level defaults to "err" and "warn" contexts enabled only and
 emission on stderr.
 </blockquote>
 <hr>
+<h2>lws_frame_is_binary - </h2>
+<i>int</i>
+<b>lws_frame_is_binary</b>
+(<i>struct libwebsocket *</i> <b>wsi</b>)
+<h3>Arguments</h3>
+<dl>
+<dt><b>wsi</b>
+<dd>the connection we are inquiring about
+</dl>
+<h3>Description</h3>
+<blockquote>
+This is intended to be called from the LWS_CALLBACK_RECEIVE callback if
+it's interested to see if the frame it's dealing with was sent in binary
+mode.
+</blockquote>
+<hr>
 <h2>libwebsockets_remaining_packet_payload - Bytes to come before "overall" rx packet is complete</h2>
 <i>size_t</i>
 <b>libwebsockets_remaining_packet_payload</b>