If data is empty, current buffer is sent. Otherwise data must be like:
        data = [('metricname', (timestamp, value)),
              ('metricname', (timestamp, value)),
              ...]
517597
def send_data(self, data=None):
        
        save_in_error = False
        if not data:
            if self.__data_lock.acquire():
                data = self.__data
                self.__data = []
                save_in_error = True
                self.__data_lock.release()
            else:
                return False
        s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        payload = pickle.dumps(data, protocol=2)
        header = struct.pack("!L", len(payload))
        message = header + payload
        s.settimeout(1)
        s.connect((self.host, self.port))
        try:
            s.send(message)
        except:
            # log.exception('Error when sending data to carbon')
            if save_in_error:
                self.__data.extend(data)
            return False
        else:
            # log.debug('Sent data to {host}:{port}: {0} metrics, {1} bytes'.format(len(data),
            #   len(message), host = self.host, port=self.port))
            return True
        finally:
            s.close()
183055
def __flush_buffer(self):
        
        self.__flush_data(self._buffer.getvalue())
        self._buffer.close()
        self._buffer = StringIO()
682618
def data_received(self, data):
        
        self.logger.debug('Received data: %s', repr(data))

        try:
            request = self._parse_headers(data)
            self._handle_request(request)
        except InvalidRequestError as e:
            self._write_response(e.get_http_response())

        if not self.keepalive:
            if self._timeout_handle:
                self._timeout_handle.cancel()
            self.transport.close()

        if self._timeout and self._timeout_handle:
            self.logger.debug('Delaying timeout event')
            self._timeout_handle.cancel()
            self._timout_handle = self._loop.call_later(
                self._timeout, self._handle_timeout)
1071389
def _push_from_buffer(self):
        
        if len(self.buffer) > 0:
            if time.time() - self.last_sent_time > 5:
                try:
                    message = self.buffer.pop(0)
                    self.s.send(message.encode('utf-8'))
                    if self.verbose:
                        print(message)
                finally:
                    self.last_sent_time = time.time()
480514
def check_buffer(coords, length, buffer):
    
    s = min(coords[0], buffer)
    e = min(length - coords[1], buffer)
    return [s, e]
266095
function prepareData(items, with_timestamps, with_ns) {
    var data = {
        request: 'sender data',
        data: items
    };

    if (with_timestamps) {
        var ts = Date.now() / 1000;
        data.clock = ts | 0;

        if (with_ns) {
            data.ns = (ts % 1) * 1000 * 1000000 | 0;
        }
    }

    var payload = new Buffer(JSON.stringify(data), 'utf8'),
        header  = new Buffer(5 + 4); // ZBXD\1 + packed payload.length

    header.write('ZBXD\x01');
    header.writeInt32LE(payload.length, 5);
    return Buffer.concat([header, new Buffer('\x00\x00\x00\x00'), payload]);
}
218794
def sendto(self, data, addr=None):
        
        if not isinstance(data, (bytes, bytearray, memoryview)):
            raise TypeError("data: expecting a bytes-like instance, got {!r}"
                                .format(type(data).__name__))
        self._check_status()
        if not self._writable:
            raise TransportError('transport is not writable')
        try:
            self._handle.send(addr, data, self._on_send_complete)
        except pyuv.error.UVError as e:
            error = TransportError.from_errno(e.args[0])
            # Try to discern between permanent and transient errors. Permanent
            # errors close the transport. This list is very likely not complete.
            if error.errno != pyuv.errno.UV_EBADF:
                raise error
            self._error = error
            self.abort()
        self._write_buffer_size += 1
        self._maybe_pause_protocol()
240040
function gotData() {
  var currentString = serial.readLine();  // read the incoming string
  trim(currentString);                    // remove any trailing whitespace
  if (!currentString) return;             // if the string is empty, do no more
  console.log(currentString);             // println the string
  latestData = currentString;            // save it for the draw method
}
614522
def process_data(self, new_data):
        
        self.buffer.feed(new_data)

        # process each non-empty line after logging all lines
        for line in self.buffer:
            log.debug("FROM SERVER: %s", line)
            if not line:
                continue
            self._process_line(line)
863190
def send(self, data):
        

        if self.sock is None:
            if self.auto_open:
                self.connect()
            else:
                raise NotConnected()

        if self.debuglevel > 0:
            print("send:", repr(data))
        blocksize = 8192
        # Python 2.7 array objects have a read method which is incompatible
        # with the 2-arg calling syntax below.
        if hasattr(data, "read") and not isinstance(data, array):
            if self.debuglevel > 0:
                print("sendIng a read()able")
            encode = False
            try:
                mode = data.mode
            except AttributeError:
                # io.BytesIO and other file-like objects don't have a `mode`
                # attribute.
                pass
            else:
                if "b" not in mode:
                    encode = True
                    if self.debuglevel > 0:
                        print("encoding file using iso-8859-1")
            while 1:
                datablock = data.read(blocksize)
                if not datablock:
                    break
                if encode:
                    datablock = datablock.encode("iso-8859-1")
                self.sock.sendall(datablock)
            return
        try:
            self.sock.sendall(data)
        except TypeError:
            if isinstance(data, collections.Iterable):
                for d in data:
                    self.sock.sendall(d)
            else:
                raise TypeError("data should be a bytes-like object "
                                "or an iterable, got %r" % type(data))
837680
def data_callback(data_type, buffer, the_end, options = {})
      return unless @marks.has_key? data_type
      callback(data_type, buffer, @marks[data_type], the_end)
      unless options[:clear]
        @marks[data_type] = 0
      else
        @marks.delete data_type
      end
    end
414696
def data_received(self, data):
        """"""
        if self._on_data:
            self._on_data(data)
            return
        self._queued_data.append(data)
525910
def update_value(self, offset, value):
        

        if offset + len(value) > self.total_size:
            return Error.INPUT_BUFFER_TOO_LONG

        if len(self.current_value) < offset:
            self.current_value += bytearray(offset - len(self.current_value))
        if len(self.current_value) > offset:
            self.current_value = self.current_value[:offset]

        self.current_value += bytearray(value)
        return 0
633150
def data_received(self, data):
        
        _LOGGER.debug("Starting: data_received")
        _LOGGER.debug('Received %d bytes from PLM: %s',
                      len(data), binascii.hexlify(data))
        self._buffer.put_nowait(data)
        asyncio.ensure_future(self._peel_messages_from_buffer(),
                              loop=self._loop)

        _LOGGER.debug("Finishing: data_received")
351893
def _flush(self, buffer):
        
        if not self.state.should_try():
            logger.error("dropping flushed data due to transport failure back-off")
        else:
            fileobj = buffer.fileobj  # get a reference to the fileobj before closing the gzip file
            buffer.close()

            # StringIO on Python 2 does not have getbuffer, so we need to fall back to getvalue
            data = fileobj.getbuffer() if hasattr(fileobj, "getbuffer") else fileobj.getvalue()
            try:
                self.send(data)
                self.handle_transport_success()
            except Exception as e:
                self.handle_transport_fail(e)
450841
def get_raw_data_from_buffer(self, filter_func=None, converter_func=None):
        '''
        '''
        if self._is_running:
            raise RuntimeError('Readout thread running')
        if not self.fill_buffer:
            logging.warning('Data buffer is not activated')
        return [convert_data_array(data_array_from_data_iterable(data_iterable), filter_func=filter_func, converter_func=converter_func) for data_iterable in self._data_buffer]
828336
private void sendBufferedValues() {
    ArrayList<Attribute> attributesToSend = new ArrayList<Attribute>();
    int num = 0;
    while (!this.attributeBuffer.isEmpty()) {
      num += this.attributeBuffer.drainTo(attributesToSend);
    }
    if (num > 0) {
      this.wmi.updateAttributes(attributesToSend);
      log.info("Sent {} buffered attribute updates.", Integer.valueOf(num));
    }
  }