// File: cybozu[P]yrmcds/src/memcache/sockets.cpp
// Function: yrmcds::memcache::repl_socket::on_readable(int)
bool repl_socket::on_readable(int fd) {
    // recv and drop.
    while( true ) {
        ssize_t n = ::recv(fd, &m_recvbuf[0], MAX_RECVSIZE, 0);
        if( n == -1 ) {
            if( errno == EAGAIN || errno == EWOULDBLOCK )
                break;
            if( errno == EINTR )
                continue;
            if( errno == ECONNRESET ) {
                std::string addr = "unknown address";
                try {
                    addr = cybozu::get_peer_ip_address(fd).str();
                } catch (...) {
                    // ignore errors
                }
                cybozu::logger::info() << "The connection to the slave (" << addr << ") has been reset.";
                return invalidate();
            }
            cybozu::throw_unix_error(errno, "recv");
        }
        if( n == 0 ) {
            std::string addr = "unknown address";
            try {
                addr = cybozu::get_peer_ip_address(fd).str();
            } catch (...) {
                // ignore errors
            }
            cybozu::logger::info() << "The connection to the slave (" << addr << ") has been closed.";
            return invalidate();
        }
        m_last_heartbeat = g_current_time.load(relaxed);
    }
    return true;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x190, %rsp            # imm = 0x190
movq %rdi, -0x28(%rbp)
movl %esi, -0x2c(%rbp)
movq -0x28(%rbp), %rax
movq %rax, -0x140(%rbp)
movq -0x140(%rbp), %rdi
movl -0x2c(%rbp), %eax
movl %eax, -0x144(%rbp)
addq $0x108, %rdi            # imm = 0x108
xorl %eax, %eax
movl %eax, %esi
callq 0x51520
movl -0x144(%rbp), %edi
movq %rax, %rsi
movl $0x200000, %edx         # imm = 0x200000
xorl %ecx, %ecx
callq 0x81b0
movq %rax, -0x38(%rbp)
cmpq $-0x1, -0x38(%rbp)
jne 0x4551a
callq 0x8050
cmpl $0xb, (%rax)
je 0x45375
callq 0x8050
cmpl $0xb, (%rax)
jne 0x4537a
jmp 0x45741
callq 0x8050
cmpl $0x4, (%rax)
jne 0x45386
jmp 0x4531d
callq 0x8050
cmpl $0x68, (%rax)
jne 0x45507
leaq -0x59(%rbp), %rdi
movq %rdi, -0x150(%rbp)
callq 0x8bd0
movq -0x150(%rbp), %rdx
leaq 0x36280(%rip), %rsi     # 0x7b632
leaq -0x58(%rbp), %rdi
callq 0xa160
jmp 0x453bd
leaq -0x59(%rbp), %rdi
callq 0x86a0
movl -0x2c(%rbp), %esi
leaq -0xb0(%rbp), %rdi
callq 0x2a5c0
jmp 0x453d7
leaq -0x90(%rbp), %rdi
leaq -0xb0(%rbp), %rsi
callq 0x2a250
jmp 0x453ec
leaq -0x58(%rbp), %rdi
leaq -0x90(%rbp), %rsi
callq 0x8790
leaq -0x90(%rbp), %rdi
callq 0x83f0
jmp 0x45442
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
leaq -0x59(%rbp), %rdi
callq 0x86a0
jmp 0x45753
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
movq -0x68(%rbp), %rdi
callq 0x8230
callq 0x8ae0
jmp 0x45440
jmp 0x45442
leaq -0xc0(%rbp), %rdi
callq 0x22390
jmp 0x45450
leaq 0x37319(%rip), %rsi     # 0x7c770
leaq -0xc0(%rbp), %rdi
callq 0x51540
movq %rax, -0x158(%rbp)
jmp 0x4546c
movq -0x158(%rbp), %rdi
leaq -0x58(%rbp), %rsi
callq 0xa690
movq %rax, -0x160(%rbp)
jmp 0x45485
movq -0x160(%rbp), %rdi
leaq 0x372fb(%rip), %rsi     # 0x7c78e
callq 0x3a5a0
jmp 0x4549a
leaq -0xc0(%rbp), %rdi
callq 0xa770
movq -0x140(%rbp), %rdi
callq 0x23290
movb %al, -0x161(%rbp)
jmp 0x454ba
movb -0x161(%rbp), %al
andb $0x1, %al
movb %al, -0x19(%rbp)
leaq -0x58(%rbp), %rdi
callq 0x83f0
jmp 0x45745
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
jmp 0x454f9
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
leaq -0xc0(%rbp), %rdi
callq 0xa770
leaq -0x58(%rbp), %rdi
callq 0x83f0
jmp 0x45753
callq 0x8050
movl (%rax), %edi
leaq 0x35e90(%rip), %rsi     # 0x7b3a5
callq 0xa320
cmpq $0x0, -0x38(%rbp)
jne 0x456b0
leaq -0xe1(%rbp), %rdi
movq %rdi, -0x170(%rbp)
callq 0x8bd0
movq -0x170(%rbp), %rdx
leaq 0x360ec(%rip), %rsi     # 0x7b632
leaq -0xe0(%rbp), %rdi
callq 0xa160
jmp 0x45554
leaq -0xe1(%rbp), %rdi
callq 0x86a0
movl -0x2c(%rbp), %esi
leaq -0x128(%rbp), %rdi
callq 0x2a5c0
jmp 0x45571
leaq -0x108(%rbp), %rdi
leaq -0x128(%rbp), %rsi
callq 0x2a250
jmp 0x45586
leaq -0xe0(%rbp), %rdi
leaq -0x108(%rbp), %rsi
callq 0x8790
leaq -0x108(%rbp), %rdi
callq 0x83f0
jmp 0x455e2
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
leaq -0xe1(%rbp), %rdi
callq 0x86a0
jmp 0x45753
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
movq -0x68(%rbp), %rdi
callq 0x8230
callq 0x8ae0
jmp 0x455e0
jmp 0x455e2
leaq -0x138(%rbp), %rdi
callq 0x22390
jmp 0x455f0
leaq 0x37179(%rip), %rsi     # 0x7c770
leaq -0x138(%rbp), %rdi
callq 0x51540
movq %rax, -0x178(%rbp)
jmp 0x4560c
movq -0x178(%rbp), %rdi
leaq -0xe0(%rbp), %rsi
callq 0xa690
movq %rax, -0x180(%rbp)
jmp 0x45628
movq -0x180(%rbp), %rdi
leaq 0x3716a(%rip), %rsi     # 0x7c7a0
callq 0xdf20
jmp 0x4563d
leaq -0x138(%rbp), %rdi
callq 0xa770
movq -0x140(%rbp), %rdi
callq 0x23290
movb %al, -0x181(%rbp)
jmp 0x4565d
movb -0x181(%rbp), %al
andb $0x1, %al
movb %al, -0x19(%rbp)
leaq -0xe0(%rbp), %rdi
callq 0x83f0
jmp 0x45745
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
jmp 0x4569f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
leaq -0x138(%rbp), %rdi
callq 0xa770
leaq -0xe0(%rbp), %rdi
callq 0x83f0
jmp 0x45753
leaq 0x6a909(%rip), %rax     # 0xaffc0
movq %rax, -0x8(%rbp)
movl $0x0, -0xc(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x190(%rbp)
movl -0xc(%rbp), %edi
movl $0xffff, %esi           # imm = 0xFFFF
callq 0x104e0
movl %eax, -0x10(%rbp)
movl -0xc(%rbp), %eax
movl %eax, -0x188(%rbp)
decl %eax
subl $0x2, %eax
jb 0x4570c
jmp 0x456ef
movl -0x188(%rbp), %eax
subl $0x5, %eax
je 0x4571c
jmp 0x456fc
movq -0x190(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x18(%rbp)
jmp 0x4572a
movq -0x190(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x18(%rbp)
jmp 0x4572a
movq -0x190(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x18(%rbp)
movq -0x140(%rbp), %rax
movq -0x18(%rbp), %rcx
movq %rcx, 0x140(%rax)
jmp 0x4531d
movb $0x1, -0x19(%rbp)
movb -0x19(%rbp), %al
andb $0x1, %al
addq $0x190, %rsp            # imm = 0x190
popq %rbp
retq
movq -0x68(%rbp), %rdi
callq 0x8bc0
nopl (%rax)