'Read data from this connection.  Generally this is just called by the
main OpenFlow loop below.
Note: This function will block if data is not available.'

def read(self):

    try:
        d = self.sock.recv(2048)
    except:
        return False
    if (len(d) == 0):
        return False
    self.buf += d
    buf_len = len(self.buf)
    offset = 0
    while ((buf_len - offset) >= 8):
        ofp_type = ord(self.buf[(offset + 1)])
        if (ord(self.buf[offset]) != of.OFP_VERSION):
            if (ofp_type == of.OFPT_HELLO):
                pass
            else:
                log.warning(('Bad    OpenFlow    version    (0x%02x)    on    connection    %s' % (ord(self.buf[offset]), self)))
                return False
        msg_length = ((ord(self.buf[(offset + 2)]) << 8) | ord(self.buf[(offset + 3)]))
        if ((buf_len - offset) < msg_length):
            break
        (new_offset, msg) = unpackers[ofp_type](self.buf, offset)
        assert ((new_offset - offset) == msg_length)
        offset = new_offset
        try:
            h = handlers[ofp_type]
            h(self, msg)
        except:
            log.exception(('%s:    Exception    while    handling    OpenFlow    message:\n' + '%s    %s'), self, self, (('\n' + str(self)) + '    ').join(str(msg).split('\n')))
            continue
    if (offset != 0):
        self.buf = self.buf[offset:]
    return True
