// File: /workspace/github_cpp_makefile_star2_O1/nightmeng[P]net/examples/http/httptest.cpp
// Function: main
int main(){
	socket sock;

#if 1
	if(!sock.connect("www.baidu.com", 80)){
		std::cout << "connected failed" << std::endl;
		return -1;
	}
	std::cout << "connected successfully" << std::endl;
	
	std::string get = "GET / HTTP/1.1\r\n"
		"Host: www.baidu.com\r\n"
		"Connection: keep-alive\r\n\r\n";

	char buff[2049] = {0};
	sock.async_write(get.c_str(), get.size(), [&sock, &buff](int ec, int t){
		sock.async_read(buff, 2048, std::bind(handle_read, std::placeholders::_1,
				std::placeholders::_2, std::ref(sock)));
	});
#else
	char buff[2049] = {0};
	sock.async_connect("www.baidu.com", 80, [&sock, &buff](int ec){
		if(ec == 0){
			std::cout << "connect successfully" << std::endl;

			std::string get = "GET / HTTP/1.1\r\n"
				"Host: www.baidu.com\r\n"
				"Connection: keep-alive\r\n\r\n";

			sock.async_write(get.c_str(), get.size(), [&sock, &buff](int ec, int t){
				std::cout << "write ec = " << ec << ", t = " << t << std::endl;
				sock.async_read(buff, 2048, std::bind(handle_read, std::placeholders::_1,
					std::placeholders::_2, std::ref(sock)));
			});
		}
		else{
			std::cout << "connect failed" << std::endl;
		}
	});
#endif

	char c;
	std::cin >> c;

	return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0xa80, %rsp            # imm = 0xA80
leaq -0x298(%rbp), %rdi
callq 0x3ae4
leaq -0xa90(%rbp), %r12
movq %r12, -0x10(%r12)
leaq 0x495d(%rip), %rsi      # 0x8014
leaq 0x4963(%rip), %rdx      # 0x8021
leaq -0xaa0(%rbp), %rdi
callq 0x3a4a
leaq -0x298(%rbp), %rbx
leaq -0xaa0(%rbp), %r14
movq %rbx, %rdi
movq %r14, %rsi
movl $0x50, %edx
callq 0x42c2
movl %eax, %r15d
movq -0xaa0(%rbp), %rdi
cmpq %r12, %rdi
je 0x36fc
callq 0x31e0
testb %r15b, %r15b
je 0x37ed
movq 0x98c4(%rip), %r15      # 0xcfd0
leaq 0x4920(%rip), %rsi      # 0x8033
movl $0x16, %edx
movq %r15, %rdi
callq 0x3220
movq (%r15), %rax
addq -0x18(%rax), %r15
movq %r15, %rdi
movl $0xa, %esi
callq 0x31f0
movsbl %al, %esi
movq 0x9892(%rip), %rdi      # 0xcfd0
callq 0x3030
movq %rax, %rdi
callq 0x3150
leaq -0x38(%rbp), %r15
movq %r15, -0x10(%r15)
leaq 0x48f0(%rip), %rsi      # 0x804a
leaq 0x4928(%rip), %rdx      # 0x8089
leaq -0x48(%rbp), %rdi
callq 0x3a4a
movl $0x801, %edx            # imm = 0x801
movq %r14, %rdi
xorl %esi, %esi
callq 0x3120
movq -0x48(%rbp), %rsi
movq -0x40(%rbp), %rdx
xorps %xmm0, %xmm0
leaq -0x70(%rbp), %rcx
movaps %xmm0, (%rcx)
movaps %xmm0, 0x10(%rcx)
movq %rbx, (%rcx)
movq %r14, 0x8(%rcx)
leaq 0x11f(%rip), %rax       # 0x38bc
movq %rax, 0x18(%rcx)
leaq 0x1ca(%rip), %rax       # 0x3972
movq %rax, 0x10(%rcx)
movq %rbx, %rdi
callq 0x4e44
movq -0x60(%rbp), %rax
testq %rax, %rax
je 0x37cb
leaq -0x70(%rbp), %rdi
movq %rdi, %rsi
movl $0x3, %edx
callq *%rax
movq 0x980e(%rip), %rdi      # 0xcfe0
leaq -0x21(%rbp), %rsi
callq 0x3230
movq -0x48(%rbp), %rdi
cmpq %r15, %rdi
je 0x37e9
callq 0x31e0
xorl %ebx, %ebx
jmp 0x3838
movq 0x97dc(%rip), %rbx      # 0xcfd0
leaq 0x4827(%rip), %rsi      # 0x8022
movl $0x10, %edx
movq %rbx, %rdi
callq 0x3220
movq (%rbx), %rax
addq -0x18(%rax), %rbx
movq %rbx, %rdi
movl $0xa, %esi
callq 0x31f0
movsbl %al, %esi
movq 0x97aa(%rip), %rdi      # 0xcfd0
callq 0x3030
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
movq %rax, %rdi
callq 0x3150
leaq -0x298(%rbp), %rdi
callq 0x415e
movl %ebx, %eax
addq $0xa80, %rsp            # imm = 0xA80
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
jmp 0x3882
movq %rax, %rbx
jmp 0x3877
movq %rax, %rbx
movq -0x60(%rbp), %rax
testq %rax, %rax
je 0x3877
leaq -0x70(%rbp), %rdi
movq %rdi, %rsi
movl $0x3, %edx
callq *%rax
movq -0x48(%rbp), %rdi
cmpq %r15, %rdi
jne 0x389b
jmp 0x38a7
movq %rax, %rdi
callq 0x399f
jmp 0x38a4
movq %rax, %rbx
movq -0xaa0(%rbp), %rdi
cmpq %r12, %rdi
je 0x38a7
callq 0x31e0
jmp 0x38a7
jmp 0x38a4
movq %rax, %rbx
leaq -0x298(%rbp), %rdi
callq 0x415e
movq %rbx, %rdi
callq 0x3310
nop