// File: davmac314[P]dinit/src/control.cc
// Function: control_conn_t::data_ready()
bool control_conn_t::data_ready() noexcept
{
    int fd = iob.get_watched_fd();
    
    int r = rbuf.fill(fd);
    
    // Note file descriptor is non-blocking
    if (r == -1) {
        if (errno != EAGAIN && errno != EWOULDBLOCK && errno != EINTR) {
            if (errno != ECONNRESET) {
                log(loglevel_t::WARN, "Error reading from control connection: ", strerror(errno));
            }
            return true;
        }
        return false;
    }
    
    if (r == 0) {
        return true;
    }
    
    // complete packet?
    while (rbuf.get_length() >= chklen) {
        try {
            if (!process_packet() || bad_conn_close) {
                return false;
            }
        }
        catch (std::bad_alloc &baexc) {
            do_oom_close();
            return false;
        }

        chklen = std::max(chklen, 1u);
    }

    if (rbuf.get_length() == rbuf.get_size()) {
        // Too big packet
        log(loglevel_t::WARN, "Received too-large control packet; dropping connection");
        bad_conn_close = true;
    }
    
    return false;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x60, %rsp
movq %rdi, -0x10(%rbp)
movq -0x10(%rbp), %rdi
movq %rdi, -0x48(%rbp)
addq $0x10, %rdi
callq 0x5fb70
movl %eax, -0x40(%rbp)
jmp 0x5cc72
movq -0x48(%rbp), %rdi
movl -0x40(%rbp), %eax
movl %eax, -0x14(%rbp)
addq $0x80, %rdi
movl -0x14(%rbp), %esi
callq 0x5fc30
movl %eax, -0x18(%rbp)
cmpl $-0x1, -0x18(%rbp)
jne 0x5ccf3
callq 0xa060
cmpl $0xb, (%rax)
je 0x5ccea
callq 0xa060
cmpl $0xb, (%rax)
je 0x5ccea
callq 0xa060
cmpl $0x4, (%rax)
je 0x5ccea
callq 0xa060
cmpl $0x68, (%rax)
je 0x5cce1
callq 0xa060
movl (%rax), %edi
callq 0xa1f0
movq %rax, -0x20(%rbp)
movl $0x2, %edi
leaq 0x1c82f(%rip), %rsi     # 0x79507
leaq -0x20(%rbp), %rdx
callq 0x5ce20
movb $0x1, -0x1(%rbp)
jmp 0x5cdfd
movb $0x0, -0x1(%rbp)
jmp 0x5cdfd
cmpl $0x0, -0x18(%rbp)
jne 0x5cd02
movb $0x1, -0x1(%rbp)
jmp 0x5cdfd
jmp 0x5cd04
movq -0x48(%rbp), %rdi
addq $0x80, %rdi
callq 0x5e200
movq -0x48(%rbp), %rcx
cmpl 0x7c(%rcx), %eax
jb 0x5cdbc
movq -0x48(%rbp), %rdi
callq 0x57fc0
movb %al, -0x49(%rbp)
jmp 0x5cd2f
movb -0x49(%rbp), %al
testb $0x1, %al
jne 0x5cd38
jmp 0x5cd42
movq -0x48(%rbp), %rax
testb $0x1, 0x78(%rax)
je 0x5cd88
movb $0x0, -0x1(%rbp)
jmp 0x5cdfd
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x28(%rbp)
movl %eax, -0x2c(%rbp)
movl -0x2c(%rbp), %eax
movl $0x2, %ecx
cmpl %ecx, %eax
jne 0x5ce10
movq -0x28(%rbp), %rdi
callq 0xa240
movq -0x48(%rbp), %rdi
movq %rax, -0x38(%rbp)
callq 0x5eff0
movb $0x0, -0x1(%rbp)
callq 0xac30
jmp 0x5cd8a
jmp 0x5cd8c
jmp 0x5cdfd
movq -0x48(%rbp), %rdi
addq $0x7c, %rdi
movl $0x1, -0x3c(%rbp)
leaq -0x3c(%rbp), %rsi
callq 0x52bc0
movq %rax, -0x58(%rbp)
jmp 0x5cdaa
movq -0x48(%rbp), %rax
movq -0x58(%rbp), %rcx
movl (%rcx), %ecx
movl %ecx, 0x7c(%rax)
jmp 0x5cd04
movq -0x48(%rbp), %rdi
subq $-0x80, %rdi
callq 0x5e200
movl %eax, -0x60(%rbp)
callq 0x5fd00
movl %eax, -0x5c(%rbp)
jmp 0x5cdd6
movl -0x60(%rbp), %eax
movl -0x5c(%rbp), %ecx
cmpl %ecx, %eax
jne 0x5cdf9
movl $0x2, %edi
leaq 0x1c743(%rip), %rsi     # 0x7952f
callq 0x6b540
movq -0x48(%rbp), %rax
movb $0x1, 0x78(%rax)
movb $0x0, -0x1(%rbp)
movb -0x1(%rbp), %al
andb $0x1, %al
addq $0x60, %rsp
popq %rbp
retq
movq %rax, %rdi
callq 0xfa30
movq -0x28(%rbp), %rdi
callq 0xfa30
nopl (%rax)