A loop to proceed periodic BFD packet transmission.
358173
def _send_loop(self):
        
        while self._enable_send:
            hub.sleep(self._xmit_period)

            # Send BFD packet. (RFC5880 Section 6.8.7.)

            if self._remote_discr == 0 and not self._active_role:
                continue

            if self._remote_min_rx_interval == 0:
                continue

            if self._remote_demand_mode and \
                    self._session_state == bfd.BFD_STATE_UP and \
                    self._remote_session_state == bfd.BFD_STATE_UP and \
                    not self._is_polling:
                continue

            self._send()
407639
def multiply_frequencies(signal, fs, frange, calibration_frequencies, attendB):
    """"""
    npts = len(signal)
    padto = 1 << (npts - 1).bit_length()

    X = np.fft.rfft(signal, n=padto)

    npts = padto
    f = np.arange((npts / 2) + 1) / (npts / fs)

    fidx_low = (np.abs(f - frange[0])).argmin()
    fidx_high = (np.abs(f - frange[1])).argmin()

    cal_func = interp1d(calibration_frequencies, attendB)
    roi = f[fidx_low:fidx_high]
    Hroi = cal_func(roi)
    H = np.zeros((len(X),))
    H[fidx_low:fidx_high] = Hroi

    H = smooth(H)
    # print 'H dB max', np.amax(H)

    H = 10 ** ((H).astype(float) / 20)
    # print 'H amp max', np.amax(H)

    # Xadjusted = X.copy()
    # Xadjusted[fidx_low:fidx_high] *= H
    # Xadjusted = smooth(Xadjusted)

    Xadjusted = X * H
    # print 'X max', np.amax(abs(X))
    # print 'Xadjusted max', np.amax(abs(Xadjusted))

    signal_calibrated = np.fft.irfft(Xadjusted)
    return signal_calibrated[:len(signal)]
116381
function randomzied (buffer) {
    // Randomly generated randomness.
    socket._sequence = buffer.readUInt32BE(0) % MAX_SEQ_NO;

    // The end point sends a packet on our behalf.
    socket._endPoint.shakeHands(socket);
  }
390328
def simple_periodic_send(bus):
    
    print("Starting to send a message every 200ms for 2s")
    msg = can.Message(arbitration_id=0x123, data=[1, 2, 3, 4, 5, 6], is_extended_id=False)
    task = bus.send_periodic(msg, 0.20)
    assert isinstance(task, can.CyclicSendTaskABC)
    time.sleep(2)
    task.stop()
    print("stopped cyclic send")
1074887
private void bfs(int v, int[] cc, int id) {
        cc[v] = id;
        Queue<Integer> queue = new LinkedList<>();
        queue.offer(v);
        while (!queue.isEmpty()) {
            int t = queue.poll();
            for (int i = 0; i < n; i++) {
                if (graph[t][i] != 0.0 && cc[i] == -1) {
                    queue.offer(i);
                    cc[i] = id;
                }
            }
        }
    }
1344433
def _receive(self, sock, count):
        

        buf = b''

        while len(buf) < count:
            chunk = sock.recv(count - len(buf))
            if not chunk:
                break
            buf += chunk

        return buf
1291200
def _async_recv(self):
        """"""

        logging.info("Receive loop started")
        recbuffer = b""

        while not self._stop_event.is_set():
            time.sleep(0.01)
            try:
                recbuffer = recbuffer + self._socket.recv(1024)
                data = recbuffer.split(b'\r\n')
                recbuffer = data.pop()
                if data:
                    for line in data:
                        self._process_data(line.decode(encoding='UTF-8', errors='ignore'))
            except BlockingIOError as e:
                pass
        logging.info("Receive loop stopped")
597191
def forward_packet(self, writer, packet, raw_packet):
        """"""
        peer = writer.get_extra_info('peername')
        log.debug(' %s:%s: forwarding data: %s', peer[0], peer[1], packet)
        if 'command' in packet:
            packet_id = serialize_packet_id(packet)
            command = packet['command']
            ack = yield from self.protocol.send_command_ack(
                packet_id, command)
            if ack:
                writer.write("20;00;OK;".encode() + CRLF)
            for _ in range(DEFAULT_SIGNAL_REPETITIONS-1):
                yield from self.protocol.send_command_ack(
                    packet_id, command)
        else:
            self.protocol.send_raw_packet(raw_packet)
357318
function forwarder(frontPort, backPort) {
  var frontSocket = zeromq.socket('sub'),
      backSocket = zeromq.socket('pub');

  frontSocket.identity = 'sub' + process.pid;
  backSocket.identity = 'pub' + process.pid;

  frontSocket.subscribe('');
  frontSocket.bind(frontPort, function (err) {
    console.log('bound', frontPort);
  });
    
  var totalMessages=0;
  frontSocket.on('message', function() {
    //pass to back
    //console.log('forwarder: recasting', arguments[0].toString());
    backSocket.send(Array.prototype.slice.call(arguments));
    totalMessages++;
  });

  backSocket.bind(backPort, function (err) {
    console.log('bound', backPort);
  });

  // lets count messages forwarded
  setInterval(function() {
    console.log('messages forwarded = ' + totalMessages);
    totalMessages=0;
  }, 1000);

}
811164
def _band8(ins):
    
    op1, op2 = tuple(ins.quad[2:])
    if _int_ops(op1, op2) is not None:
        op1, op2 = _int_ops(op1, op2)

        output = _8bit_oper(op1)
        if op2 == 0xFF:  # X & 0xFF = X
            output.append('push af')
            return output

        if op2 == 0:  # X and 0 = 0
            output.append('xor a')
            output.append('push af')
            return output

        op1, op2 = tuple(ins.quad[2:])

    output = _8bit_oper(op1, op2)
    output.append('and h')
    output.append('push af')

    return output
1015530
private ByteBuffer recv(int attempt)
          throws IOException, SocketException, SocketTimeoutException {
    int timeout = UDP_BASE_TIMEOUT_SECONDS * (int) Math.pow(2, attempt);
    logger.trace("Setting receive timeout to {}s for attempt {}...",
            timeout, attempt);
    this.socket.setSoTimeout(timeout * 1000);

    try {
      DatagramPacket p = new DatagramPacket(
              new byte[UDP_PACKET_LENGTH],
              UDP_PACKET_LENGTH);
      this.socket.receive(p);
      return ByteBuffer.wrap(p.getData(), 0, p.getLength());
    } catch (SocketTimeoutException ste) {
      throw ste;
    }
  }
220608
function rtcPipe(link, initiate)
  {
    // existing noop
    if(link.rtcPipe) return link.rtcPipe;

    // outgoing signal cache and sender
    var signals = [];
    function signal(sig){
      if(signals.indexOf(sig) == -1) signals.push(sig);
      if(!link.x) return;
      // send each signal as an individual lossy channel
      var json = {type:'webrtc',c:link.x.cid()};
      json.signal = sig;
      mesh.log.debug('sending signal to',link.hashname,json);
      link.x.send({json:json});
    }

    // new pipe
    var pipe = link.rtcPipe = new telehash.Pipe('webrtc');
    pipe.cloaked = true;
    pipe.id = link.hashname;
    pipe.path = {type:'webrtc'};
    
    // handle outgoing packets based on rtc state
    pipe.onSend = function(packet, link, cb){
      if(!packet) return cb('no packet');
      var safe = packet.toString('base64')
      if(link.rtc.connected)
      {
        mesh.log.debug('rtc send',safe.length);
        link.rtc.send(safe);
        return cb();
      }
      mesh.log.debug('rtc still signalling',signals.length);
      // cache most recent packet
      link.rtc.cached = safe;
      if(!link.up) return cb('not connected');
      // if there's signals yet, resend them as they could have been lost
      signals.forEach(signal);
    }

    // new webrtc connection
    link.rtc = new rtc.peer({initiate:initiate, _self:'self', _peer:link.hashname});
    link.rtc.DEBUG = true;
    link.rtc.onsignal = signal;
    link.rtc.onconnection = function() {
      mesh.log.debug('RTC CONNECTED');
      link.rtc.connected = true;
      signals = []; // empty any cached signals too
      if(link.rtc.cached) link.rtc.send(link.rtc.cached);
      link.rtc.cached = false;
    }
    link.rtc.onmessage = function(safe) {
      mesh.log.debug('rtc receive',safe.length);
      var packet = lob.decloak(new Buffer(safe,'base64'));
      if(!packet) return mesh.log.info('dropping invalid packet',safe);
      mesh.receive(packet,pipe);
    }
    
    return pipe;
  }
530429
private byte[] bufB(int bpv) {
    assert bpv == 1 || bpv == 2 : "Only bit vectors with/without NA are supported";
    final int off = CBSChunk.OFF;
    int clen  = off + CBSChunk.clen(_len, bpv);
    byte bs[] = new byte[clen];
    // Save the gap = number of unfilled bits and bpv value
    bs[0] = (byte) (((_len*bpv)&7)==0 ? 0 : (8-((_len*bpv)&7)));
    bs[1] = (byte) bpv;

    // Dense bitvector
    int  boff = 0;
    byte b    = 0;
    int  idx  = CBSChunk.OFF;
    int j = 0;
    for (int i=0; i<_len; i++) {
      byte val = 0;
      if(_id == null || (j < _id.length && _id[j] == i)) {
        assert bpv == 2 || !isNA2(j);
        val = (byte)(isNA2(j)?CBSChunk._NA:_ls[j]);
        ++j;
      }
      if( bpv==1 )
        b = CBSChunk.write1b(b, val, boff);
      else
        b = CBSChunk.write2b(b, val, boff);
      boff += bpv;
      if (boff>8-bpv) { assert boff == 8; bs[idx] = b; boff = 0; b = 0; idx++; }
    }
    assert j == _sparseLen;
    assert bs[0] == (byte) (boff == 0 ? 0 : 8-boff):"b[0] = " + bs[0] + ", boff = " + boff + ", bpv = " + bpv;
    // Flush last byte
    if (boff>0) bs[idx] = b;
    return bs;
  }
779678
public static IoBuffer encodeOutgoingData(Packet packet) {
        log.debug("encode outgoing: {}", packet);
        // get the payload data
        IoBuffer data = packet.getData();
        // get the frame length based on the byte count
        int frameLen = data.limit();
        // start with frame length + 2b (header info)
        IoBuffer buffer = IoBuffer.allocate(frameLen + 2, false);
        buffer.setAutoExpand(true);
        // set the proper flags / opcode for the data
        byte frameInfo = (byte) (1 << 7);
        switch (packet.getType()) {
            case TEXT:
                if (log.isTraceEnabled()) {
                    log.trace("Encoding text frame  \r\n{}", new String(packet.getData().array()));
                }
                frameInfo = (byte) (frameInfo | 1);
                break;
            case BINARY:
                log.trace("Encoding binary frame");
                frameInfo = (byte) (frameInfo | 2);
                break;
            case CLOSE:
                frameInfo = (byte) (frameInfo | 8);
                break;
            case CONTINUATION:
                frameInfo = (byte) (frameInfo | 0);
                break;
            case PING:
                log.trace("ping out");
                frameInfo = (byte) (frameInfo | 9);
                break;
            case PONG:
                log.trace("pong out");
                frameInfo = (byte) (frameInfo | 0xa);
                break;
            default:
                break;
        }
        buffer.put(frameInfo);
        // set the frame length
        log.trace("Frame length {} ", frameLen);
        if (frameLen <= 125) {
            buffer.put((byte) ((byte) frameLen & (byte) 0x7F));
        } else if (frameLen > 125 && frameLen <= 65535) {
            buffer.put((byte) ((byte) 126 & (byte) 0x7F));
            buffer.putShort((short) frameLen);
        } else {
            buffer.put((byte) ((byte) 127 & (byte) 0x7F));
            buffer.putLong((int) frameLen);
        }
        buffer.put(data);
        buffer.flip();
        if (log.isTraceEnabled()) {
            log.trace("Encoded: {}", buffer);
        }
        return buffer;
    }
1063955
def recv_data(self):
        
        data, addr = self.sock.recvfrom(self.packetsize)
        matrix = map(ord, data.strip())
        if len(matrix) == self.packetsize:
            self.matrix = matrix[:-4]
865456
function RFFT(bufferSize, sampleRate) {
  FourierTransform.call(this, bufferSize, sampleRate);

  this.trans = new Float32Array(bufferSize);

  this.reverseTable = new Uint32Array(bufferSize);

  // don't use a lookup table to do the permute, use this instead
  this.reverseBinPermute = function (dest, source) {
    var bufferSize  = this.bufferSize, 
        halfSize    = bufferSize >>> 1, 
        nm1         = bufferSize - 1, 
        i = 1, r = 0, h;

    dest[0] = source[0];

    do {
      r += halfSize;
      dest[i] = source[r];
      dest[r] = source[i];
      
      i++;

      h = halfSize << 1;
      while (h = h >> 1, !((r ^= h) & h));

      if (r >= i) { 
        dest[i]     = source[r]; 
        dest[r]     = source[i];

        dest[nm1-i] = source[nm1-r]; 
        dest[nm1-r] = source[nm1-i];
      }
      i++;
    } while (i < halfSize);
    dest[nm1] = source[nm1];
  };

  this.generateReverseTable = function () {
    var bufferSize  = this.bufferSize, 
        halfSize    = bufferSize >>> 1, 
        nm1         = bufferSize - 1, 
        i = 1, r = 0, h;

    this.reverseTable[0] = 0;

    do {
      r += halfSize;
      
      this.reverseTable[i] = r;
      this.reverseTable[r] = i;

      i++;

      h = halfSize << 1;
      while (h = h >> 1, !((r ^= h) & h));

      if (r >= i) { 
        this.reverseTable[i] = r;
        this.reverseTable[r] = i;

        this.reverseTable[nm1-i] = nm1-r;
        this.reverseTable[nm1-r] = nm1-i;
      }
      i++;
    } while (i < halfSize);

    this.reverseTable[nm1] = nm1;
  };

  this.generateReverseTable();
}
303520
def _receive_packet(self, timeout=3.0):
        

        while True:
            response_data = self._stream.read_packet(timeout=timeout)
            response = BGAPIPacket(is_event=(response_data[0] == 0x80), command_class=response_data[2], command=response_data[3], payload=response_data[4:])

            if response.is_event:
                if self.event_handler is not None:
                    self.event_handler(response)

                continue

            return response