src/server/safs/service.c

changeset 127
84e206063b64
parent 116
d7a186cf87f6
child 172
5580517faafc
equal deleted inserted replaced
126:631aaa01b2b5 127:84e206063b64
35 #include "../util/pblock.h" 35 #include "../util/pblock.h"
36 #include "../util/util.h" 36 #include "../util/util.h"
37 #include "../daemon/protocol.h" 37 #include "../daemon/protocol.h"
38 #include "../daemon/vfs.h" 38 #include "../daemon/vfs.h"
39 39
40 //include <sys/sendfile.h>
41 #include "../util/strbuf.h" 40 #include "../util/strbuf.h"
42 #include <ucx/string.h> 41 #include <ucx/string.h>
43 #include <ucx/utils.h> 42 #include <ucx/utils.h>
44 43
45 #include <errno.h> 44 #include <errno.h>
447 http_start_response(sn, rq); 446 http_start_response(sn, rq);
448 net_write(sn->csd, "Hello World!\n", 13); 447 net_write(sn->csd, "Hello World!\n", 13);
449 return REQ_PROCEED; 448 return REQ_PROCEED;
450 } 449 }
451 450
451 static int ws_msghandler(WebSocket *ws, WSMessage *msg) {
452 if(msg->type == 1) {
453 printf("Message(text): %.*s\n", (int)msg->length, msg->data);
454 websocket_send_text(ws->userdata, "hello", 5);
455 } else {
456 printf("Message: opcode: %d | length: %d\n", msg->type, (int)msg->length);
457 }
458 return 0;
459 }
460
461 int service_ws_hello(pblock *pb, Session *sn, Request *rq) {
462 WebSocket ws;
463 ZERO(&ws, sizeof(WebSocket));
464 ws.userdata = sn->csd;
465
466 ws.on_message = ws_msghandler;
467 return http_handle_websocket(sn, rq, &ws);
468 }
469
452 int service_index(pblock *pb, Session *sn, Request *rq) { 470 int service_index(pblock *pb, Session *sn, Request *rq) {
453 //printf("service_index\n"); 471 //printf("service_index\n");
454 472
455 char *path = pblock_findkeyval(pb_key_path, rq->vars); 473 char *path = pblock_findkeyval(pb_key_path, rq->vars);
456 char *uri = pblock_findkeyval(pb_key_uri, rq->reqpb); 474 char *uri = pblock_findkeyval(pb_key_uri, rq->reqpb);

mercurial