Lines Matching refs:sock
4443 var sock = {
4457 node.sock = sock;
4471 sock.stream = stream;
4473 return sock;
4479 return stream.node.sock;
4481 var sock = stream.node.sock;
4482 return sock.sock_ops.poll(sock);
4484 var sock = stream.node.sock;
4485 return sock.sock_ops.ioctl(sock, request, varargs);
4487 var sock = stream.node.sock;
4488 var msg = sock.sock_ops.recvmsg(sock, length);
4496 var sock = stream.node.sock;
4497 return sock.sock_ops.sendmsg(sock, buffer, offset, length);
4499 var sock = stream.node.sock;
4500 sock.sock_ops.close(sock);
4506 },websocket_sock_ops:{createPeer:function (sock, addr, port) {
4585 SOCKFS.websocket_sock_ops.addPeer(sock, peer);
4586 SOCKFS.websocket_sock_ops.handlePeerEvents(sock, peer);
4591 if (sock.type === 2 && typeof sock.sport !== 'undefined') {
4595 ((sock.sport & 0xff00) >> 8) , (sock.sport & 0xff)
4600 },getPeer:function (sock, addr, port) {
4601 return sock.peers[addr + ':' + port];
4602 },addPeer:function (sock, peer) {
4603 sock.peers[peer.addr + ':' + peer.port] = peer;
4604 },removePeer:function (sock, peer) {
4605 delete sock.peers[peer.addr + ':' + peer.port];
4606 },handlePeerEvents:function (sock, peer) {
4637 SOCKFS.websocket_sock_ops.removePeer(sock, peer);
4639 SOCKFS.websocket_sock_ops.addPeer(sock, peer);
4643 sock.recv_queue.push({ addr: peer.addr, port: peer.port, data: data });
4663 },poll:function (sock) {
4664 if (sock.type === 1 && sock.server) {
4667 return sock.pending.length ? (64 | 1) : 0;
4671 var dest = sock.type === 1 ? // we only care about the socket state for connection-based sockets
4672 sock, sock.daddr, sock.dport) :
4675 if (sock.recv_queue.length ||
4693 },ioctl:function (sock, request, arg) {
4697 if (sock.recv_queue.length) {
4698 bytes = sock.recv_queue[0].data.length;
4705 },close:function (sock) {
4707 if (sock.server) {
4709 sock.server.close();
4712 sock.server = null;
4715 var peers = Object.keys(sock.peers);
4717 var peer = sock.peers[peers[i]];
4722 SOCKFS.websocket_sock_ops.removePeer(sock, peer);
4725 },bind:function (sock, addr, port) {
4726 if (typeof sock.saddr !== 'undefined' || typeof sock.sport !== 'undefined') {
4729 sock.saddr = addr;
4730 sock.sport = port || _mkport();
4734 if (sock.type === 2) {
4736 if (sock.server) {
4737 sock.server.close();
4738 sock.server = null;
4743 sock.sock_ops.listen(sock, 0);
4749 },connect:function (sock, addr, port) {
4750 if (sock.server) {
4755 // if (!sock.addr && sock.type == 2) {
4759 if (typeof sock.daddr !== 'undefined' && typeof sock.dport !== 'undefined') {
4760 var dest = SOCKFS.websocket_sock_ops.getPeer(sock, sock.daddr, sock.dport);
4772 var peer = SOCKFS.websocket_sock_ops.createPeer(sock, addr, port);
4773 sock.daddr = peer.addr;
4774 sock.dport = peer.port;
4778 },listen:function (sock, backlog) {
4782 if (sock.server) {
4786 var host = sock.saddr;
4787 sock.server = new WebSocketServer({
4789 port: sock.sport
4793 sock.server.on('connection', function(ws) {
4794 if (sock.type === 1) {
4795 var newsock = SOCKFS.createSocket(sock.family, sock.type, sock.protocol);
4803 sock.pending.push(newsock);
4808 SOCKFS.websocket_sock_ops.createPeer(sock, ws);
4811 sock.server.on('closed', function() {
4812 sock.server = null;
4814 sock.server.on('error', function() {
4824 },getname:function (sock, peer) {
4827 if (sock.daddr === undefined || sock.dport === undefined) {
4830 addr = sock.daddr;
4831 port = sock.dport;
4835 addr = sock.saddr || 0;
4836 port = sock.sport || 0;
4839 },sendmsg:function (sock, buffer, offset, length, addr, port) {
4840 if (sock.type === 2) {
4844 addr = sock.daddr;
4845 port = sock.dport;
4853 addr = sock.daddr;
4854 port = sock.dport;
4858 var dest = SOCKFS.websocket_sock_ops.getPeer(sock, addr, port);
4861 if (sock.type === 1) {
4882 if (sock.type === 2) {
4886 dest = SOCKFS.websocket_sock_ops.createPeer(sock, addr, port);
4900 },recvmsg:function (sock, length) {
4902 if (sock.type === 1 && sock.server) {
4907 var queued = sock.recv_queue.shift();
4909 if (sock.type === 1) {
4910 var dest = SOCKFS.websocket_sock_ops.getPeer(sock, sock.daddr, sock.dport);
4943 if (sock.type === 1 && bytesRead < queuedLength) {
4946 sock.recv_queue.unshift(queued);
4951 var sock = SOCKFS.getSocket(fd);
4952 if (!sock) {