src/server/safs/service.c

changeset 127
84e206063b64
parent 116
d7a186cf87f6
child 172
5580517faafc
--- a/src/server/safs/service.c	Sun Oct 30 11:44:04 2016 +0100
+++ b/src/server/safs/service.c	Mon Dec 26 14:00:10 2016 +0100
@@ -37,7 +37,6 @@
 #include "../daemon/protocol.h"
 #include "../daemon/vfs.h"
 
-//include <sys/sendfile.h>
 #include "../util/strbuf.h"
 #include <ucx/string.h>
 #include <ucx/utils.h>
@@ -449,6 +448,25 @@
     return REQ_PROCEED;
 }
 
+static int ws_msghandler(WebSocket *ws, WSMessage *msg) {
+    if(msg->type == 1) {
+        printf("Message(text): %.*s\n", (int)msg->length, msg->data);
+        websocket_send_text(ws->userdata, "hello", 5);
+    } else {
+        printf("Message: opcode: %d | length: %d\n", msg->type, (int)msg->length);
+    }
+    return 0;
+}
+
+int service_ws_hello(pblock *pb, Session *sn, Request *rq) {
+    WebSocket ws;
+    ZERO(&ws, sizeof(WebSocket));
+    ws.userdata = sn->csd;
+    
+    ws.on_message = ws_msghandler;
+    return http_handle_websocket(sn, rq, &ws);
+}
+
 int service_index(pblock *pb, Session *sn, Request *rq) {
     //printf("service_index\n");
 

mercurial