// File: cybozu[P]yrmcds/src/memcache/handler.cpp
// Function: yrmcds::memcache::handler::on_slave_start()
bool handler::on_slave_start() {
    using logger = cybozu::logger;

    auto master_host = g_config.vip().str();
    int fd;
    try {
        fd = cybozu::tcp_connect(master_host.c_str(), g_config.repl_port());
    } catch( std::runtime_error& err ) {
        logger::error() << "Failed to connect to the master (" << master_host << "): " << err.what();
        m_reactor.run_once();
        return false;
    }
    if( fd == -1 ) {
        logger::error() << "Failed to connect to the master (" << master_host << ")";
        m_reactor.run_once();
        return false;
    }

    // on_slave_start may be called multiple times over the lifetime.
    // Therefore we need to clear the hash table.
    clear();

    m_repl_client_socket = new repl_client_socket(fd, m_hash);
    m_reactor.add_resource(std::unique_ptr<cybozu::resource>(m_repl_client_socket),
                           cybozu::reactor::EVENT_IN|cybozu::reactor::EVENT_OUT );
    return true;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xf0, %rsp
movq %rdi, -0x10(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0xb0(%rbp)
leaq 0x7802f(%rip), %rdi     # 0xafd00
movq %rdi, -0xa0(%rbp)
callq 0x22f30
movq %rax, %rsi
leaq -0x30(%rbp), %rdi
movq %rdi, -0xa8(%rbp)
callq 0x2a250
movq -0xa8(%rbp), %rdi
callq 0x8240
movq -0xa0(%rbp), %rdi
movq %rax, -0x98(%rbp)
callq 0x39d00
movq -0x98(%rbp), %rdi
movzwl %ax, %esi
movl $0xa, %edx
callq 0x55250
movl %eax, -0x8c(%rbp)
jmp 0x37d2b
movl -0x8c(%rbp), %eax
movl %eax, -0x34(%rbp)
jmp 0x37e52
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
movl -0x44(%rbp), %eax
movl $0x1, %ecx
cmpl %ecx, %eax
jne 0x37fed
movq -0x40(%rbp), %rdi
callq 0x8230
movq %rax, -0x50(%rbp)
leaq -0x60(%rbp), %rdi
callq 0xa600
jmp 0x37d6d
leaq 0x43843(%rip), %rsi     # 0x7b5b7
leaq -0x60(%rbp), %rdi
callq 0x3a440
movq %rax, -0xb8(%rbp)
jmp 0x37d86
movq -0xb8(%rbp), %rdi
leaq -0x30(%rbp), %rsi
callq 0xa690
movq %rax, -0xc0(%rbp)
jmp 0x37d9f
movq -0xc0(%rbp), %rdi
leaq 0x42602(%rip), %rsi     # 0x7a3af
callq 0xa7f0
movq %rax, -0xc8(%rbp)
jmp 0x37dbb
movq -0x50(%rbp), %rdi
movq (%rdi), %rax
movq 0x10(%rax), %rax
callq *%rax
movq -0xc8(%rbp), %rdi
movq %rax, -0x68(%rbp)
leaq -0x68(%rbp), %rsi
callq 0xa720
jmp 0x37dde
leaq -0x60(%rbp), %rdi
callq 0xa770
movq -0xb0(%rbp), %rax
movq 0x28(%rax), %rdi
callq 0x3a480
jmp 0x37df9
movb $0x0, -0x1(%rbp)
movl $0x1, -0x6c(%rbp)
callq 0x8ae0
jmp 0x37e30
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
jmp 0x37e46
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
leaq -0x60(%rbp), %rdi
callq 0xa770
jmp 0x37e46
jmp 0x37fd6
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
jmp 0x37fed
callq 0x8ae0
jmp 0x37e4d
jmp 0x37fed
cmpl $-0x1, -0x34(%rbp)
jne 0x37ef3
leaq -0x80(%rbp), %rdi
callq 0xa600
jmp 0x37e67
leaq 0x43749(%rip), %rsi     # 0x7b5b7
leaq -0x80(%rbp), %rdi
callq 0x3a440
movq %rax, -0xd0(%rbp)
jmp 0x37e80
movq -0xd0(%rbp), %rdi
leaq -0x30(%rbp), %rsi
callq 0xa690
movq %rax, -0xd8(%rbp)
jmp 0x37e99
movq -0xd8(%rbp), %rdi
leaq 0x43004(%rip), %rsi     # 0x7aeab
callq 0xa650
jmp 0x37eae
leaq -0x80(%rbp), %rdi
callq 0xa770
movq -0xb0(%rbp), %rax
movq 0x28(%rax), %rdi
callq 0x3a480
jmp 0x37ec9
movb $0x0, -0x1(%rbp)
movl $0x1, -0x6c(%rbp)
jmp 0x37fd6
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
leaq -0x80(%rbp), %rdi
callq 0xa770
jmp 0x37fed
movq -0xb0(%rbp), %rdi
callq 0x38010
jmp 0x37f01
movl $0x130, %edi            # imm = 0x130
callq 0x8640
movq %rax, -0xe0(%rbp)
jmp 0x37f14
movq -0xe0(%rbp), %rdi
movq -0xb0(%rbp), %rdx
movl -0x34(%rbp), %esi
addq $0x40, %rdx
callq 0x3a4a0
jmp 0x37f30
movq -0xb0(%rbp), %rax
movq -0xe0(%rbp), %rcx
movq %rcx, 0xa8(%rax)
movq 0x28(%rax), %rcx
movq %rcx, -0xf0(%rbp)
movq 0xa8(%rax), %rsi
leaq -0x88(%rbp), %rdi
movq %rdi, -0xe8(%rbp)
callq 0x3a520
movq -0xf0(%rbp), %rdi
movq -0xe8(%rbp), %rsi
movl $0x5, %edx
callq 0xea00
jmp 0x37f84
leaq -0x88(%rbp), %rdi
callq 0x11290
movb $0x1, -0x1(%rbp)
movl $0x1, -0x6c(%rbp)
jmp 0x37fd6
movq -0xe0(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
movl $0x130, %esi            # imm = 0x130
callq 0x8650
jmp 0x37fed
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
leaq -0x88(%rbp), %rdi
callq 0x11290
jmp 0x37fed
leaq -0x30(%rbp), %rdi
callq 0x83f0
movb -0x1(%rbp), %al
andb $0x1, %al
addq $0xf0, %rsp
popq %rbp
retq
leaq -0x30(%rbp), %rdi
callq 0x83f0
movq -0x40(%rbp), %rdi
callq 0x8bc0
movq %rax, %rdi
callq 0xa7e0
nopw (%rax,%rax)