// File: /workspace/github_cpp_makefile_star2_O2/roberty65[P]bServer/frame/main/EventManager.cpp
// Function: beyondy::Async::EventManager::EventManager(beyondy::Async::Queue<beyondy::Async::Message>*, int)
EventManager::EventManager(Queue<Message> *_outQueue, int _esize)
	: epoll_fd(-1), event_next(0), event_total(0), epoll_size(_esize), epoll_events(NULL),
	  outQueue(_outQueue)
{
	if (epoll_size < 1) epoll_size = 1024;

	if ((epoll_fd = epoll_create(epoll_size)) < 0) {
		char buf[512];
		snprintf(buf, sizeof buf, "epoll_create(%ld) failed: %m", (long)epoll_size);
		throw std::runtime_error(buf);
	}

	epoll_events = (struct epoll_event *)malloc(epoll_size * sizeof(struct epoll_event));
	if (epoll_events == NULL) {
		::close(epoll_fd);

		char buf[512];
		snprintf(buf, sizeof buf, "new epoll events[%ld] failed: %m", (long)epoll_size);
		throw std::runtime_error(buf);
	}

	event_next = 0;
	event_total = 0;

	INIT_LIST_HEAD(&lruHead);
	INIT_LIST_HEAD(&connectorsHead);
		
	struct rlimit r0;
	int retval = getrlimit(RLIMIT_NOFILE, &r0);
	if (retval < 0) {
		throw std::runtime_error("rlimit(NOFILE) failed");
	}

	next_flow = 1;
	flowRoot.rb_node = NULL;

	perCheckOutQueue = 100;
	connectionMaxIdle = 5 * 1000;
	reconnectDelay = 2 * 1000;	// will delay 2, 4, 6, 8, 10
}

// Assembly:
pushq %rbp
pushq %r14
pushq %rbx
subq $0x200, %rsp            # imm = 0x200
movq %rdi, %rbx
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
movq %rax, (%rdi)
andl $0x0, 0x8(%rdi)
movl %edx, 0xc(%rdi)
andq $0x0, 0x10(%rdi)
movq %rsi, 0x18(%rdi)
testl %edx, %edx
jg 0x488e
movl $0x400, 0xc(%rbx)       # imm = 0x400
movl $0x400, %edx            # imm = 0x400
movl %edx, %edi
callq 0x3650
movl %eax, (%rbx)
testl %eax, %eax
js 0x4914
movl %eax, %ebp
movslq 0xc(%rbx), %rax
imulq $0xc, %rax, %rdi
callq 0x34a0
movq %rax, 0x10(%rbx)
testq %rax, %rax
je 0x4949
andq $0x0, 0x4(%rbx)
leaq 0x20(%rbx), %rax
movq %rax, 0x20(%rbx)
movq %rax, 0x28(%rbx)
leaq 0x30(%rbx), %rax
movq %rax, 0x30(%rbx)
movq %rax, 0x38(%rbx)
pushq $0x7
popq %rdi
movq %rsp, %rsi
callq 0x34f0
testl %eax, %eax
js 0x4985
movl $0x1, 0x40(%rbx)
andq $0x0, 0x48(%rbx)
movl $0x64, 0x54(%rbx)
movl $0x1388, 0x60(%rbx)     # imm = 0x1388
movl $0x7d0, 0x6c(%rbx)      # imm = 0x7D0
addq $0x200, %rsp            # imm = 0x200
popq %rbx
popq %r14
popq %rbp
retq
movslq 0xc(%rbx), %rcx
leaq 0x5ad6(%rip), %rdx      # 0xa3f5
movq %rsp, %rbx
movl $0x200, %esi            # imm = 0x200
movq %rbx, %rdi
xorl %eax, %eax
callq 0x3590
pushq $0x10
popq %rdi
callq 0x3180
movq %rax, %r14
movq %rax, %rdi
movq %rbx, %rsi
callq 0x3120
jmp 0x499f
movl %ebp, %edi
callq 0x3660
movslq 0xc(%rbx), %rcx
leaq 0x5ab7(%rip), %rdx      # 0xa412
movq %rsp, %rbx
movl $0x200, %esi            # imm = 0x200
movq %rbx, %rdi
xorl %eax, %eax
callq 0x3590
pushq $0x10
popq %rdi
callq 0x3180
movq %rax, %r14
movq %rax, %rdi
movq %rbx, %rsi
callq 0x3120
jmp 0x499f
pushq $0x10
popq %rdi
callq 0x3180
movq %rax, %r14
leaq 0x5a9c(%rip), %rsi      # 0xa433
movq %rax, %rdi
callq 0x3120
movq 0xb652(%rip), %rsi      # 0xfff8
movq 0xb623(%rip), %rdx      # 0xffd0
movq %r14, %rdi
callq 0x35e0
jmp 0x49b9
jmp 0x49b9
movq %rax, %rbx
movq %r14, %rdi
callq 0x3230
movq %rbx, %rdi
callq 0x3600