Lines Matching refs:sock
4440 var sock = {
4454 node.sock = sock;
4468 sock.stream = stream;
4470 return sock;
4476 return stream.node.sock;
4478 var sock = stream.node.sock;
4479 return sock.sock_ops.poll(sock);
4481 var sock = stream.node.sock;
4482 return sock.sock_ops.ioctl(sock, request, varargs);
4484 var sock = stream.node.sock;
4485 var msg = sock.sock_ops.recvmsg(sock, length);
4493 var sock = stream.node.sock;
4494 return sock.sock_ops.sendmsg(sock, buffer, offset, length);
4496 var sock = stream.node.sock;
4497 sock.sock_ops.close(sock);
4503 },websocket_sock_ops:{createPeer:function (sock, addr, port) {
4582 SOCKFS.websocket_sock_ops.addPeer(sock, peer);
4583 SOCKFS.websocket_sock_ops.handlePeerEvents(sock, peer);
4588 if (sock.type === 2 && typeof sock.sport !== 'undefined') {
4592 ((sock.sport & 0xff00) >> 8) , (sock.sport & 0xff)
4597 },getPeer:function (sock, addr, port) {
4598 return sock.peers[addr + ':' + port];
4599 },addPeer:function (sock, peer) {
4600 sock.peers[peer.addr + ':' + peer.port] = peer;
4601 },removePeer:function (sock, peer) {
4602 delete sock.peers[peer.addr + ':' + peer.port];
4603 },handlePeerEvents:function (sock, peer) {
4634 SOCKFS.websocket_sock_ops.removePeer(sock, peer);
4636 SOCKFS.websocket_sock_ops.addPeer(sock, peer);
4640 sock.recv_queue.push({ addr: peer.addr, port: peer.port, data: data });
4660 },poll:function (sock) {
4661 if (sock.type === 1 && sock.server) {
4664 return sock.pending.length ? (64 | 1) : 0;
4668 var dest = sock.type === 1 ? // we only care about the socket state for connection-based sockets
4669 SOCKFS.websocket_sock_ops.getPeer(sock, socksock.dport) :
4672 if (sock.recv_queue.length ||
4690 },ioctl:function (sock, request, arg) {
4694 if (sock.recv_queue.length) {
4695 bytes = sock.recv_queue[0].data.length;
4702 },close:function (sock) {
4704 if (sock.server) {
4706 sock.server.close();
4709 sock.server = null;
4712 var peers = Object.keys(sock.peers);
4714 var peer = sock.peers[peers[i]];
4719 SOCKFS.websocket_sock_ops.removePeer(sock, peer);
4722 },bind:function (sock, addr, port) {
4723 if (typeof sock.saddr !== 'undefined' || typeof sock.sport !== 'undefined') {
4726 sock.saddr = addr;
4727 sock.sport = port || _mkport();
4731 if (sock.type === 2) {
4733 if (sock.server) {
4734 sock.server.close();
4735 sock.server = null;
4740 sock.sock_ops.listen(sock, 0);
4746 },connect:function (sock, addr, port) {
4747 if (sock.server) {
4752 // if (!sock.addr && sock.type == 2) {
4756 if (typeof sock.daddr !== 'undefined' && typeof sock.dport !== 'undefined') {
4757 var dest = SOCKFS.websocket_sock_ops.getPeer(sock, sock.daddr, sock.dport);
4769 var peer = SOCKFS.websocket_sock_ops.createPeer(sock, addr, port);
4770 sock.daddr = peer.addr;
4771 sock.dport = peer.port;
4775 },listen:function (sock, backlog) {
4779 if (sock.server) {
4783 var host = sock.saddr;
4784 sock.server = new WebSocketServer({
4786 port: sock.sport
4790 sock.server.on('connection', function(ws) {
4791 if (sock.type === 1) {
4792 var newsock = SOCKFS.createSocket(sock.family, sock.type, sock.protocol);
4800 sock.pending.push(newsock);
4805 SOCKFS.websocket_sock_ops.createPeer(sock, ws);
4808 sock.server.on('closed', function() {
4809 sock.server = null;
4811 sock.server.on('error', function() {
4821 },getname:function (sock, peer) {
4824 if (sock.daddr === undefined || sock.dport === undefined) {
4827 addr = sock.daddr;
4828 port = sock.dport;
4832 addr = sock.saddr || 0;
4833 port = sock.sport || 0;
4836 },sendmsg:function (sock, buffer, offset, length, addr, port) {
4837 if (sock.type === 2) {
4841 addr = sock.daddr;
4842 port = sock.dport;
4850 addr = sock.daddr;
4851 port = sock.dport;
4855 var dest = SOCKFS.websocket_sock_ops.getPeer(sock, addr, port);
4858 if (sock.type === 1) {
4879 if (sock.type === 2) {
4883 dest = SOCKFS.websocket_sock_ops.createPeer(sock, addr, port);
4897 },recvmsg:function (sock, length) {
4899 if (sock.type === 1 && sock.server) {
4904 var queued = sock.recv_queue.shift();
4906 if (sock.type === 1) {
4907 var dest = SOCKFS.websocket_sock_ops.getPeer(sock, sock.daddr, sock.dport);
4940 if (sock.type === 1 && bytesRead < queuedLength) {
4943 sock.recv_queue.unshift(queued);
4948 var sock = SOCKFS.getSocket(fd);
4949 if (!sock) {