// File: /workspace/github_cpp_makefile_star2_O3/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)
movl $0x0, 0x8(%rdi)
movl %edx, 0xc(%rdi)
movq $0x0, 0x10(%rdi)
movq %rsi, 0x18(%rdi)
testl %edx, %edx
jg 0x4a40
movl $0x400, 0xc(%rbx)       # imm = 0x400
movl $0x400, %edx            # imm = 0x400
movl %edx, %edi
callq 0x3620
movl %eax, (%rbx)
testl %eax, %eax
js 0x4ad6
movl %eax, %ebp
movslq 0xc(%rbx), %rax
shlq $0x2, %rax
leaq (%rax,%rax,2), %rdi
callq 0x3480
movq %rax, 0x10(%rbx)
testq %rax, %rax
je 0x4b0d
movq $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)
movq %rsp, %rsi
movl $0x7, %edi
callq 0x34c0
testl %eax, %eax
js 0x4b4b
movl $0x1, 0x40(%rbx)
movq $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 0x5914(%rip), %rdx      # 0xa3f5
movq %rsp, %rbx
movl $0x200, %esi            # imm = 0x200
movq %rbx, %rdi
xorl %eax, %eax
callq 0x3560
movl $0x10, %edi
callq 0x3170
movq %rax, %r14
movq %rax, %rdi
movq %rbx, %rsi
callq 0x3120
jmp 0x4b67
movl %ebp, %edi
callq 0x3630
movslq 0xc(%rbx), %rcx
leaq 0x58f3(%rip), %rdx      # 0xa412
movq %rsp, %rbx
movl $0x200, %esi            # imm = 0x200
movq %rbx, %rdi
xorl %eax, %eax
callq 0x3560
movl $0x10, %edi
callq 0x3170
movq %rax, %r14
movq %rax, %rdi
movq %rbx, %rsi
callq 0x3120
jmp 0x4b67
movl $0x10, %edi
callq 0x3170
movq %rax, %r14
leaq 0x58d4(%rip), %rsi      # 0xa433
movq %rax, %rdi
callq 0x3120
movq 0xb48a(%rip), %rsi      # 0xfff8
movq 0xb45b(%rip), %rdx      # 0xffd0
movq %r14, %rdi
callq 0x35b0
jmp 0x4b81
jmp 0x4b81
movq %rax, %rbx
movq %r14, %rdi
callq 0x3220
movq %rbx, %rdi
callq 0x35d0