introduce lws_issue_raw
authorAndy Green <andy@warmcat.com>
Sun, 6 Mar 2011 10:29:38 +0000 (10:29 +0000)
committerAndy Green <andy@warmcat.com>
Sun, 6 Mar 2011 10:29:38 +0000 (10:29 +0000)
Signed-off-by: Andy Green <andy@warmcat.com>
lib/parsers.c
lib/private-libwebsockets.h

index 3b72b58..37a4ae6 100644 (file)
@@ -1054,6 +1054,31 @@ libwebsocket_0405_frame_mask_generate(struct libwebsocket *wsi)
        return 0;
 }
 
+int lws_issue_raw(struct libwebsocket *wsi, unsigned char *buf, size_t len)
+{
+       int n;
+
+#ifdef LWS_OPENSSL_SUPPORT
+       if (wsi->ssl) {
+               n = SSL_write(wsi->ssl, buf, len);
+               if (n < 0) {
+                       fprintf(stderr,
+                                  "ERROR writing to socket\n");
+                       return -1;
+               }
+       } else {
+#endif
+               n = send(wsi->sock, buf, len, MSG_NOSIGNAL);
+               if (n < 0) {
+                       fprintf(stderr,
+                                  "ERROR writing to socket\n");
+                       return -1;
+               }
+#ifdef LWS_OPENSSL_SUPPORT
+       }
+#endif
+       return 0;
+}
 
 /**
  * libwebsocket_write() - Apply protocol then write data to client
@@ -1300,23 +1325,9 @@ int libwebsocket_write(struct libwebsocket *wsi, unsigned char *buf,
        }
 
 send_raw:
-#ifdef LWS_OPENSSL_SUPPORT
-       if (wsi->ssl) {
-               n = SSL_write(wsi->ssl, buf - pre, len + pre + post);
-               if (n < 0) {
-                       fprintf(stderr, "ERROR writing to socket\n");
-                       return -1;
-               }
-       } else {
-#endif
-               n = send(wsi->sock, buf - pre, len + pre + post, MSG_NOSIGNAL);
-               if (n < 0) {
-                       fprintf(stderr, "ERROR writing to socket\n");
-                       return -1;
-               }
-#ifdef LWS_OPENSSL_SUPPORT
-       }
-#endif
+
+       if (lws_issue_raw(wsi, buf - pre, len + pre + post))
+               return -1;
 
        debug("written %d bytes to client\n", (int)len);
 
index 94802ae..e560f05 100644 (file)
@@ -332,6 +332,9 @@ extern int
 libwebsockets_get_random(struct libwebsocket_context *context,
                                                            void *buf, int len);
 
+extern int
+lws_issue_raw(struct libwebsocket *wsi, unsigned char *buf, size_t len);
+
 #ifndef LWS_OPENSSL_SUPPORT
 
 unsigned char *