// File: /workspace/github_cpp_makefile_star2_O2/ixchow[P]http-tweak/./http.hpp
// Function: http::server::server(unsigned short)
inline server::server(uint16_t port) {

	#ifdef _WIN32
	{ //init winsock:
		WSADATA info;
		if (WSAStartup((2 << 8) | 2, &info) != 0) {
			throw std::runtime_error("WSAStartup failed.");
		}
	}
	#endif

	//----------- socket setup -----------
	{ //create socket:
		listen_socket = ::socket(AF_INET, SOCK_STREAM, 0);
		if (listen_socket == -1) {
			throw std::system_error(errno, std::system_category(), "failed to create socket");
		}
	}
	{ //make it okay to reuse port:
		#ifdef _WIN32
		BOOL one = TRUE;
		int ret = setsockopt(listen_socket, SOL_SOCKET, SO_REUSEADDR, reinterpret_cast< const char * >(&one), sizeof(one));
		#else
		int one = 1;
		int ret = setsockopt(listen_socket, SOL_SOCKET, SO_REUSEADDR, &one, sizeof(one));
		#endif
		if (ret != 0) {
			std::cerr << "[server::server] WARNING: Failed to set socket reuse address." << std::endl;
		}
	}
	{ //bind to address
		struct sockaddr_in addr;
		memset(&addr, 0, sizeof(addr));
		addr.sin_family = AF_INET;
		addr.sin_port = htons(port);
		addr.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
		int ret = bind(listen_socket, reinterpret_cast< sockaddr * >(&addr), sizeof(addr));
		if (ret < 0) {
			closesocket(listen_socket);
			throw std::system_error(errno, std::system_category(), "failed to bind socket");
		}
	}
	{ //listen on socket
		int ret = ::listen(listen_socket, 5);
		if (ret < 0) {
			closesocket(listen_socket);
			throw std::system_error(errno, std::system_category(), "failed to listen on socket");
		}
	}


	std::cout << "[server::server] Server started at localhost:" << port << "." << std::endl;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x10, %rsp
movq %rdi, %r14
orl $-0x1, (%rdi)
movl %esi, %r15d
leaq 0x8(%rdi), %rbx
movq %rbx, 0x10(%rdi)
movq %rbx, 0x8(%rdi)
andq $0x0, 0x18(%rdi)
movb $0x0, 0x20(%rdi)
andq $0x0, 0x28(%rdi)
pushq $0x2
popq %rdi
pushq $0x1
popq %rsi
xorl %edx, %edx
callq 0x30e0
movl %eax, (%r14)
cmpl $-0x1, %eax
je 0x8644
leaq -0x30(%rbp), %rcx
movl $0x1, (%rcx)
pushq $0x1
popq %rsi
pushq $0x2
popq %rdx
pushq $0x4
popq %r8
movl %eax, %edi
callq 0x3550
testl %eax, %eax
je 0x85bb
movq 0x6a41(%rip), %rdi      # 0xefe8
leaq 0x201e(%rip), %rsi      # 0xa5cc
callq 0x3360
movq %rax, %rdi
callq 0x31d0
leaq -0x30(%rbp), %rsi
andq $0x0, 0x8(%rsi)
movl %r15d, %eax
rolw $0x8, %ax
movw $0x2, (%rsi)
movw %ax, 0x2(%rsi)
movl $0x100007f, 0x4(%rsi)   # imm = 0x100007F
movl (%r14), %edi
pushq $0x10
popq %rdx
callq 0x3090
testl %eax, %eax
js 0x868c
movl (%r14), %edi
pushq $0x5
popq %rsi
callq 0x33b0
testl %eax, %eax
js 0x86d9
movq 0x69b0(%rip), %rdi      # 0xefb8
leaq 0x202c(%rip), %rsi      # 0xa63b
callq 0x3360
movzwl %r15w, %esi
movq %rax, %rdi
callq 0x3500
leaq 0x2086(%rip), %rsi      # 0xa6ad
movq %rax, %rdi
callq 0x3360
movq %rax, %rdi
callq 0x31d0
addq $0x10, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
pushq $0x20
popq %rdi
callq 0x31e0
movq %rax, %r12
callq 0x3060
movl (%rax), %r15d
callq 0x3230
leaq 0x1f51(%rip), %rcx      # 0xa5b4
movq %r12, %rdi
movl %r15d, %esi
movq %rax, %rdx
callq 0x875a
movq 0x6900(%rip), %rsi      # 0xef78
movq 0x6929(%rip), %rdx      # 0xefa8
movq %r12, %rdi
callq 0x3520
jmp 0x8724
movl (%r14), %edi
callq 0x35b0
pushq $0x20
popq %rdi
callq 0x31e0
movq %rax, %r12
callq 0x3060
movl (%rax), %r15d
callq 0x3230
leaq 0x1f57(%rip), %rcx      # 0xa60a
movq %r12, %rdi
movl %r15d, %esi
movq %rax, %rdx
callq 0x875a
movq 0x68b0(%rip), %rsi      # 0xef78
movq 0x68d9(%rip), %rdx      # 0xefa8
movq %r12, %rdi
callq 0x3520
jmp 0x8724
movl (%r14), %edi
callq 0x35b0
pushq $0x20
popq %rdi
callq 0x31e0
movq %rax, %r12
callq 0x3060
movl (%rax), %r15d
callq 0x3230
leaq 0x1f20(%rip), %rcx      # 0xa620
movq %r12, %rdi
movl %r15d, %esi
movq %rax, %rdx
callq 0x875a
movq 0x6863(%rip), %rsi      # 0xef78
movq 0x688c(%rip), %rdx      # 0xefa8
movq %r12, %rdi
callq 0x3520
jmp 0x8728
jmp 0x8728
movq %rax, %r15
movq %r12, %rdi
callq 0x32c0
jmp 0x873e
jmp 0x873b
jmp 0x873b
jmp 0x873b
movq %rax, %r15
addq $0x28, %r14
movq %r14, %rdi
callq 0x6ad8
movq %rbx, %rdi
callq 0x6b10
movq %r15, %rdi
callq 0x3540