// File: /workspace/github_cpp_makefile_star2_O3/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 -0x290(%rbp), %rdi
callq 0x3aa4
leaq -0xa90(%rbp), %r12
movq %r12, -0x10(%r12)
leaq 0x4991(%rip), %rsi      # 0x8014
leaq 0x4997(%rip), %rdx      # 0x8021
leaq -0xaa0(%rbp), %rdi
callq 0x3a04
leaq -0x290(%rbp), %rbx
leaq -0xaa0(%rbp), %r14
movq %rbx, %rdi
movq %r14, %rsi
movl $0x50, %edx
callq 0x4284
movl %eax, %r15d
movq -0xaa0(%rbp), %rdi
cmpq %r12, %rdi
je 0x36c8
callq 0x31e0
testb %r15b, %r15b
je 0x37af
movq 0x98f8(%rip), %r15      # 0xcfd0
leaq 0x4954(%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 0x98c6(%rip), %rdi      # 0xcfd0
callq 0x3030
movq %rax, %rdi
callq 0x3150
leaq -0x38(%rbp), %r15
movq %r15, -0x10(%r15)
leaq 0x4924(%rip), %rsi      # 0x804a
leaq 0x495c(%rip), %rdx      # 0x8089
leaq -0x48(%rbp), %rdi
callq 0x3a04
movl $0x801, %edx            # imm = 0x801
movq %r14, %rdi
xorl %esi, %esi
callq 0x3120
movq -0x48(%rbp), %rsi
movq -0x40(%rbp), %rdx
leaq -0x68(%rbp), %rcx
movq %rbx, (%rcx)
movq %r14, 0x8(%rcx)
leaq 0x11f(%rip), %rax       # 0x387e
movq %rax, 0x18(%rcx)
leaq 0x1c6(%rip), %rax       # 0x3930
movq %rax, 0x10(%rcx)
movq %rbx, %rdi
callq 0x4dfc
movq -0x58(%rbp), %rax
testq %rax, %rax
je 0x378d
leaq -0x68(%rbp), %rdi
movq %rdi, %rsi
movl $0x3, %edx
callq *%rax
movq 0x984c(%rip), %rdi      # 0xcfe0
leaq -0x21(%rbp), %rsi
callq 0x3230
movq -0x48(%rbp), %rdi
cmpq %r15, %rdi
je 0x37ab
callq 0x31e0
xorl %ebx, %ebx
jmp 0x37fa
movq 0x981a(%rip), %rbx      # 0xcfd0
leaq 0x4865(%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 0x97e8(%rip), %rdi      # 0xcfd0
callq 0x3030
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
movq %rax, %rdi
callq 0x3150
leaq -0x290(%rbp), %rdi
callq 0x411e
movl %ebx, %eax
addq $0xa80, %rsp            # imm = 0xA80
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
jmp 0x3844
movq %rax, %rbx
jmp 0x3839
movq %rax, %rbx
movq -0x58(%rbp), %rax
testq %rax, %rax
je 0x3839
leaq -0x68(%rbp), %rdi
movq %rdi, %rsi
movl $0x3, %edx
callq *%rax
movq -0x48(%rbp), %rdi
cmpq %r15, %rdi
jne 0x385d
jmp 0x3869
movq %rax, %rdi
callq 0x395d
jmp 0x3866
movq %rax, %rbx
movq -0xaa0(%rbp), %rdi
cmpq %r12, %rdi
je 0x3869
callq 0x31e0
jmp 0x3869
jmp 0x3866
movq %rax, %rbx
leaq -0x290(%rbp), %rdi
callq 0x411e
movq %rbx, %rdi
callq 0x3310
nop