Lines Matching refs:sock
4426 var sock = {
4440 node.sock = sock;
4454 sock.stream = stream;
4456 return sock;
4462 return stream.node.sock;
4464 var sock = stream.node.sock;
4465 return sock.sock_ops.poll(sock);
4467 var sock = stream.node.sock;
4468 return sock.sock_ops.ioctl(sock, request, varargs);
4470 var sock = stream.node.sock;
4471 var msg = sock.sock_ops.recvmsg(sock, length);
4479 var sock = stream.node.sock;
4480 return sock.sock_ops.sendmsg(sock, buffer, offset, length);
4482 var sock = stream.node.sock;
4483 sock.sock_ops.close(sock);
4489 },websocket_sock_ops:{createPeer:function (sock, addr, port) {
4568 SOCKFS.websocket_sock_ops.addPeer(sock, peer);
4569 SOCKFS.websocket_sock_ops.handlePeerEvents(sock, peer);
4574 if (sock.type === 2 && typeof sock.sport !== 'undefined') {
4578 ((sock.sport & 0xff00) >> 8) , (sock.sport & 0xff)
4583 },getPeer:function (sock, addr, port) {
4584 return sock.peers[addr + ':' + port];
4585 },addPeer:function (sock, peer) {
4586 sock.peers[peer.addr + ':' + peer.port] = peer;
4587 },removePeer:function (sock, peer) {
4588 delete sock.peers[peer.addr + ':' + peer.port];
4589 },handlePeerEvents:function (sock, peer) {
4620 SOCKFS.websocket_sock_ops.removePeer(sock, peer);
4622 SOCKFS.websocket_sock_ops.addPeer(sock, peer);
4626 sock.recv_queue.push({ addr: peer.addr, port: peer.port, data: data });
4646 },poll:function (sock) {
4647 if (sock.type === 1 && sock.server) {
4650 return sock.pending.length ? (64 | 1) : 0;
4654 var dest = sock.type === 1 ? // we only care about the socket state for connection-based sockets
4655 SOCKFS.websocket_sock_ops.getPeer(sock, sock.daddr, sock.dport) :
4658 if (sock.recv_queue.length ||
4676 },ioctl:function (sock, request, arg) {
4680 if (sock.recv_queue.length) {
4681 bytes = sock.recv_queue[0].data.length;
4688 },close:function (sock) {
4690 if (sock.server) {
4692 sock.server.close();
4695 sock.server = null;
4698 var peers = Object.keys(sock.peers);
4700 var peer = sock.peers[peers[i]];
4705 SOCKFS.websocket_sock_ops.removePeer(sock, peer);
4708 },bind:function (sock, addr, port) {
4709 if (typeof sock.saddr !== 'undefined' || typeof sock.sport !== 'undefined') {
4712 sock.saddr = addr;
4713 sock.sport = port || _mkport();
4717 if (sock.type === 2) {
4719 if (sock.server) {
4720 sock.server.close();
4721 sock.server = null;
4726 sock.sock_ops.listen(sock, 0);
4732 },connect:function (sock, addr, port) {
4733 if (sock.server) {
4738 // if (!sock.addr && sock.type == 2) {
4742 if (typeof sock.daddr !== 'undefined' && typeof sock.dport !== 'undefined') {
4743 var dest = SOCKFS.websocket_sock_ops.getPeer(sock, sock.daddr, sock.dport);
4755 var peer = SOCKFS.websocket_sock_ops.createPeer(sock, addr, port);
4756 sock.daddr = peer.addr;
4757 sock.dport = peer.port;
4761 },listen:function (sock, backlog) {
4765 if (sock.server) {
4769 var host = sock.saddr;
4770 sock.server = new WebSocketServer({
4772 port: sock.sport
4776 sock.server.on('connection', function(ws) {
4777 if (sock.type === 1) {
4778 var newsock = SOCKFS.createSocket(sock.family, sock.type, sock.protocol);
4786 sock.pending.push(newsock);
4791 SOCKFS.websocket_sock_ops.createPeer(sock, ws);
4794 sock.server.on('closed', function() {
4795 sock.server = null;
4797 sock.server.on('error', function() {
4807 },getname:function (sock, peer) {
4810 if (sock.daddr === undefined || sock.dport === undefined) {
4813 addr = sock.daddr;
4814 port = sock.dport;
4818 addr = sock.saddr || 0;
4819 port = sock.sport || 0;
4822 },sendmsg:function (sock, buffer, offset, length, addr, port) {
4823 if (sock.type === 2) {
4827 addr = sock.daddr;
4828 port = sock.dport;
4836 addr = sock.daddr;
4837 port = sock.dport;
4841 var dest = SOCKFS.websocket_sock_ops.getPeer(sock, addr, port);
4844 if (sock.type === 1) {
4865 if (sock.type === 2) {
4869 dest = SOCKFS.websocket_sock_ops.createPeer(sock, addr, port);
4883 },recvmsg:function (sock, length) {
4885 if (sock.type === 1 && sock.server) {
4890 var queued = sock.recv_queue.shift();
4892 if (sock.type === 1) {
4893 var dest = SOCKFS.websocket_sock_ops.getPeer(sock, sock.daddr, sock.dport);
4926 if (sock.type === 1 && bytesRead < queuedLength) {
4929 sock.recv_queue.unshift(queued);
4934 var sock = SOCKFS.getSocket(fd);
4935 if (!sock) {