Lines Matching refs:sock
4429 var sock = {
4443 node.sock = sock;
4457 sock.stream = stream;
4459 return sock;
4465 return stream.node.sock;
4467 var sock = stream.node.sock;
4468 return sock.sock_ops.poll(sock);
4470 var sock = stream.node.sock;
4471 return sock.sock_ops.ioctl(sock, request, varargs);
4473 var sock = stream.node.sock;
4474 var msg = sock.sock_ops.recvmsg(sock, length);
4482 var sock = stream.node.sock;
4483 return sock.sock_ops.sendmsg(sock, buffer, offset, length);
4485 var sock = stream.node.sock;
4486 sock.sock_ops.close(sock);
4492 },websocket_sock_ops:{createPeer:function (sock, addr, port) {
4571 SOCKFS.websocket_sock_ops.addPeer(sock, peer);
4572 SOCKFS.websocket_sock_ops.handlePeerEvents(sock, peer);
4577 if (sock.type === 2 && typeof sock.sport !== 'undefined') {
4581 ((sock.sport & 0xff00) >> 8) , (sock.sport & 0xff)
4586 },getPeer:function (sock, addr, port) {
4587 return sock.peers[addr + ':' + port];
4588 },addPeer:function (sock, peer) {
4589 sock.peers[peer.addr + ':' + peer.port] = peer;
4590 },removePeer:function (sock, peer) {
4591 delete sock.peers[peer.addr + ':' + peer.port];
4592 },handlePeerEvents:function (sock, peer) {
4623 SOCKFS.websocket_sock_ops.removePeer(sock, peer);
4625 SOCKFS.websocket_sock_ops.addPeer(sock, peer);
4629 sock.recv_queue.push({ addr: peer.addr, port: peer.port, data: data });
4649 },poll:function (sock) {
4650 if (sock.type === 1 && sock.server) {
4653 return sock.pending.length ? (64 | 1) : 0;
4657 var dest = sock.type === 1 ? // we only care about the socket state for connection-based sockets
4658 SOCKFS.websocket_sock_ops.getPeer(sock, sock.daddr, sock.dport) :
4661 if (sock.recv_queue.length ||
4679 },ioctl:function (sock, request, arg) {
4683 if (sock.recv_queue.length) {
4684 bytes = sock.recv_queue[0].data.length;
4691 },close:function (sock) {
4693 if (sock.server) {
4695 sock.server.close();
4698 sock.server = null;
4701 var peers = Object.keys(sock.peers);
4703 var peer = sock.peers[peers[i]];
4708 SOCKFS.websocket_sock_ops.removePeer(sock, peer);
4711 },bind:function (sock, addr, port) {
4712 if (typeof sock.saddr !== 'undefined' || typeof sock.sport !== 'undefined') {
4715 sock.saddr = addr;
4716 sock.sport = port || _mkport();
4720 if (sock.type === 2) {
4722 if (sock.server) {
4723 sock.server.close();
4724 sock.server = null;
4729 sock.sock_ops.listen(sock, 0);
4735 },connect:function (sock, addr, port) {
4736 if (sock.server) {
4741 // if (!sock.addr && sock.type == 2) {
4745 if (typeof sock.daddr !== 'undefined' && typeof sock.dport !== 'undefined') {
4746 var dest = SOCKFS.websocket_sock_ops.getPeer(sock, sock.daddr, sock.dport);
4758 var peer = SOCKFS.websocket_sock_ops.createPeer(sock, addr, port);
4759 sock.daddr = peer.addr;
4760 sock.dport = peer.port;
4764 },listen:function (sock, backlog) {
4768 if (sock.server) {
4772 var host = sock.saddr;
4773 sock.server = new WebSocketServer({
4775 port: sock.sport
4779 sock.server.on('connection', function(ws) {
4780 if (sock.type === 1) {
4781 var newsock = SOCKFS.createSocket(sock.family, sock.type, sock.protocol);
4789 sock.pending.push(newsock);
4794 SOCKFS.websocket_sock_ops.createPeer(sock, ws);
4797 sock.server.on('closed', function() {
4798 sock.server = null;
4800 sock.server.on('error', function() {
4810 },getname:function (sock, peer) {
4813 if (sock.daddr === undefined || sock.dport === undefined) {
4816 addr = sock.daddr;
4817 port = sock.dport;
4821 addr = sock.saddr || 0;
4822 port = sock.sport || 0;
4825 },sendmsg:function (sock, buffer, offset, length, addr, port) {
4826 if (sock.type === 2) {
4830 addr = sock.daddr;
4831 port = sock.dport;
4839 addr = sock.daddr;
4840 port = sock.dport;
4844 var dest = SOCKFS.websocket_sock_ops.getPeer(sock, addr, port);
4847 if (sock.type === 1) {
4868 if (sock.type === 2) {
4872 dest = SOCKFS.websocket_sock_ops.createPeer(sock, addr, port);
4886 },recvmsg:function (sock, length) {
4888 if (sock.type === 1 && sock.server) {
4893 var queued = sock.recv_queue.shift();
4895 if (sock.type === 1) {
4896 var dest = SOCKFS.websocket_sock_ops.getPeer(sock, sock.daddr, sock.dport);
4929 if (sock.type === 1 && bytesRead < queuedLength) {
4932 sock.recv_queue.unshift(queued);
4937 var sock = SOCKFS.getSocket(fd);
4938 if (!sock) {