Total bytes sent from the router to external network
339466
def totalBytesSent()
            joinThread()
            v = MiniUPnP.UPNP_GetTotalBytesSent(@urls.controlURL_CIF,
                        @data.servicetype_CIF)
            if v < 0 then
                raise UPnPException.new, "Error while retriving total bytes sent."
            end
            return v
        end
1193844
def packet_write(self):
        """"""
        bytes_written = 0
        
        if self.sock == NC.INVALID_SOCKET:
            return NC.ERR_NO_CONN, bytes_written
        
        while len(self.out_packet) > 0:
            pkt = self.out_packet[0]
            write_length, status = nyamuk_net.write(self.sock, pkt.payload)
            if write_length > 0:
                pkt.to_process -= write_length
                pkt.pos += write_length
                
                bytes_written += write_length
                
                if pkt.to_process > 0:
                    return NC.ERR_SUCCESS, bytes_written
            else:
                if status == errno.EAGAIN or status == errno.EWOULDBLOCK:
                    return NC.ERR_SUCCESS, bytes_written
                elif status == errno.ECONNRESET:
                    return NC.ERR_CONN_LOST, bytes_written
                else:
                    return NC.ERR_UNKNOWN, bytes_written
            
            """
            if pkt.command & 0xF6 == NC.CMD_PUBLISH and self.on_publish is not None:
                self.in_callback = True
                self.on_publish(pkt.mid)
                self.in_callback = False
            """
            
            #next
            del self.out_packet[0]
            
            #free data (unnecessary)
            
            self.last_msg_out = time.time()
            
        
        return NC.ERR_SUCCESS, bytes_written
439436
def ber_from_socket(s):
    
    if isinstance(s, network.SocketClient):
        recv = s.receive
    else:
        recv = s.recv
    data = recv(1)

    length = data[0]
    bytes_read = 1
    if length > 127:
        bytes_read += length & 127 # Strip off the high bit
        data += recv(bytes_read - 1)
        length = 0
        for i in range(1, bytes_read):
            length += data[i] << (8 * (bytes_read - i - 1))
    return length, bytes_read, data
1010528
def read(self):
        

        data = self.dev.read()

        if len(data) == 0:
            self.log.warning("READ : Nothing received")
            return

        if data == b'\x00':
            self.log.warning("READ : Empty packet (Got \\x00)")
            return

        pkt = bytearray(data)
        data = self.dev.read(pkt[0])
        pkt.extend(bytearray(data))

        self.log.info("READ : %s" % self.format_packet(pkt))
        self.do_callback(pkt)
        return pkt
589035
def _send_outgoing_route(self, outgoing_route):
        

        path = outgoing_route.path
        block, blocked_cause = self._apply_out_filter(path)

        nlri_str = outgoing_route.path.nlri.formatted_nlri_str
        sent_route = SentRoute(outgoing_route.path, self, block)
        self._adj_rib_out[nlri_str] = sent_route
        self._signal_bus.adj_rib_out_changed(self, sent_route)

        # TODO(PH): optimized by sending several prefixes per update.
        # Construct and send update message.
        if not block:
            update_msg = self._construct_update(outgoing_route)
            self._protocol.send(update_msg)
            # Collect update statistics.
            self.state.incr(PeerCounterNames.SENT_UPDATES)
        else:
            LOG.debug('prefix : %s is not sent by filter : %s',
                      path.nlri, blocked_cause)

        # We have to create sent_route for every OutgoingRoute which is
        # not a withdraw or was for route-refresh msg.
        if (not outgoing_route.path.is_withdraw and
                not outgoing_route.for_route_refresh):
            # Update the destination with new sent route.
            tm = self._core_service.table_manager
            tm.remember_sent_route(sent_route)
1017900
def socket_recv(self):
        
        try:
            data = self.sock.recv(2048)
        except socket.error, ex:
            print ("?? socket.recv() error '%d:%s' from %s" %
                (ex[0], ex[1], self.addrport()))
            raise BogConnectionLost()

        ## Did they close the connection?
        size = len(data)
        if size == 0:
            raise BogConnectionLost()

        ## Update some trackers
        self.last_input_time = time.time()
        self.bytes_received += size

        ## Test for telnet commands
        for byte in data:
            self._iac_sniffer(byte)

        ## Look for newline characters to get whole lines from the buffer
        while True:
            mark = self.recv_buffer.find('\n')
            if mark == -1:
                break
            cmd = self.recv_buffer[:mark].strip()
            self.command_list.append(cmd)
            self.cmd_ready = True
            self.recv_buffer = self.recv_buffer[mark+1:]
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
12097
def write(self, data):
        """"""
        # If nobody is connected, act like all data was written anyway.
        if self.connected is None:
            return 0
        data = to_bytes_safe(data)
        size = len(data)
        remaining = size
        while remaining:
            count = self._abstract_socket.write(data)
            remaining -= count
            if remaining:
                data = data[count:]
        return size
29250
def dump(self):
        """"""
        data = dict(
            # Sessions
            sessions_active=self.sess_active,

            # Connections
            connections_active=self.conn_active,
            connections_ps=self.conn_ps.last_average,

            # Packets
            packets_sent_ps=self.pack_sent_ps.last_average,
            packets_recv_ps=self.pack_recv_ps.last_average
            )

        for k, v in self.sess_transports.items():
            data['transp_' + k] = v

        return data
563341
public boolean sendTCPBytes(ByteBuffer[] srcbuffers, int length)
    {
        boolean success = false;
        try
        {
            ByteBuffer header = createHeader(length);
            ByteBuffer[] buffers = new ByteBuffer[1 + srcbuffers.length];
            buffers[0] = header;
            for (int i = 0; i < srcbuffers.length; i++)
                buffers[i + 1] = srcbuffers[i];
            if (TCPUtils.isLogging())
            {
                long t1 = System.nanoTime();
                long bytesWritten = write(buffers);
                long t2 = System.nanoTime();
                double rate = 1000.0 * 1000.0 * 1000.0 * (double) (bytesWritten) / (1024.0 * (double) (t2 - t1));
                Log(Level.INFO, "Sent " + bytesWritten + " bytes at " + rate + " Kb/s");
            }
            else
            {
                write(buffers);
            }
            success = true;
        }
        catch (Exception e)
        {
            SysLog(Level.SEVERE, "Failed to send TCP bytes: " + e);
            try { channel.close(); } catch (IOException ioe) {}
        }
        return success;
    }
312505
def _net_write(sock, data, expiration):
    
    current = 0
    l = len(data)
    while current < l:
        _wait_for_writable(sock, expiration)
        current += sock.send(data[current:])
649878
@Override
	public boolean appendOutgoingData()
	{
		while (outputBuffer.remaining() > 0)
		{
			if (packetOutputBuffer.size() == 0)
			{
				if (sendQueue.size() == 0)
					return true; // No more packet to send
				
				if (outputBuffer.remaining() < 4) // packet_size = sizeof(int) = 4
					return true; // Not enough space to proceed
				
				// Write packet size
				if (!serializePacket(sendQueue.getFirst(),packetOutputBuffer))
					return false; // Invalid packet
				outputBuffer.putInt(packetOutputBuffer.size());
				currentOutputOffset = 0;
			}
			else
			{
				int writeAmount = Math.min(outputBuffer.remaining(),packetOutputBuffer.size() - currentOutputOffset);
				packetOutputBuffer.putTo(outputBuffer, currentOutputOffset, writeAmount);
				currentOutputOffset += writeAmount;
				
				// Packet completly sent ?
				if (currentOutputOffset == packetOutputBuffer.size())
				{
					AbstractPacket sentPacket;
					synchronized (sendQueue)
					{
						sentPacket = sendQueue.removeFirst();
					}
					packetOutputBuffer.clear();
					
					if (listener != null)
						listener.packetSent(sentPacket);
				}
			}
		}
		return true;
	}
88094
def data_received(self, data):
        """"""
        self.buffer += data.decode()
        self.log.debug('Received %d bytes from AVR: %s', len(self.buffer), self.buffer)
        self._assemble_buffer()
1066321
def send(self, data):
        """"""
        bytes_sent = self._sock.send(extract_bytes(data))
        self.bytes_written += bytes_sent
        return bytes_sent
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;
    }
1301232
def send(self, out, addr=_MDNS_ADDR, port=_MDNS_PORT):
        """"""
        # This is a quick test to see if we can parse the packets we generate
        #temp = DNSIncoming(out.packet())
        for i in self.intf.values():
            try:
                return i.sendto(out.packet(), 0, (addr, port))
            except:
                traceback.print_exc()
                # Ignore this, it may be a temporary loss of network connection
                return -1
55576
def __send_receive_buffer(self):
        
        self.__clear_in_buffer()
        self.__send_buffer()
        read_string = self.serial.read(len(self.__in_buffer))
        if self.DEBUG_MODE:
            print("Read: '{}'".format(binascii.hexlify(read_string)))
        if len(read_string) != len(self.__in_buffer):
            raise IOError("{} bytes received for input buffer of size {}".format(len(read_string),
                                                                                 len(self.__in_buffer)))
        if not self.__is_valid_checksum(read_string):
            raise IOError("Checksum validation failed on received data")
        self.__in_buffer.value = read_string