interop notes - libwebsocket -06 close
authorPat McManus @Mozilla <mcmanus@ducksong.com>
Mon, 7 Mar 2011 06:06:36 +0000 (06:06 +0000)
committerAndy Green <andy.green@linaro.org>
Mon, 7 Mar 2011 06:06:36 +0000 (06:06 +0000)
... this afternoon I was just doing a little
interoperability testing around close... in my test-server I added

 libwebsocket_close_and_free_session(this, wsi, LWS_CLOSE_STATUS_NORMAL);

in order to generate a server driven close.. I hope that was the right
way to go about it. In any event, in generated an invalid websocket
frame - I think you want this patch, or something like it:

Signed-off-by: \"Pat McManus @Mozilla\" <mcmanus@ducksong.com>
lib/parsers.c

index e4f17a4..fd26cb7 100644 (file)
@@ -1215,9 +1215,11 @@ int libwebsocket_write(struct libwebsocket *wsi, unsigned char *buf,
                                 */
 
                                if (wsi->close_reason) {
-                                       buf[pre - 2] = wsi->close_reason >> 8;
-                                       buf[pre - 1] = wsi->close_reason;
-                                       pre += 2;
+                                       /* reason codes count as data bytes */
+                                       buf -= 2;
+                                       buf[0] = wsi->close_reason >> 8;
+                                       buf[1] = wsi->close_reason;
+                                       len += 2;
                                }
                                break;
                        }