// File: metopa[P]HTTP_Server/src/main.cpp
// Function: main
int main( int argc, char * argv[] ) {
	try {
		signalNS::blockSignals();
		signalNS::setEmptyHandler( SIGUSR1 );

		config.load( argc, argv );
		Log.init( config.getLogFile() );
		Log.welcome();
		Log.options();

		CThreadSafeQueue<CRequest *, nullptr> queue( config.getPortCount() );

		CRunnable::ptr_t signalHandler( new CSignalThread( &queue ) );

		vector<CRunnable::ptr_t> ports;
		for ( unsigned int i = 0; i < config.getPortCount(); i++ ) {
			try {
				ports.push_back( CRunnable::ptr_t( new CPortThread( i, config.getPorts()[i].c_str(), 10, &queue ) ) );
				Log.ger<>( NETWORK, "Port", config.getPorts()[i], "obtained" );
			}
			catch ( PortInitializationException& e ) {
				queue.notifyProducerStopped();
				Log.ger<>( CRITICAL, e );
			}
		}

		vector<CRunnable::ptr_t> workers;
		for ( unsigned int i = 0; i < config.getWorkerCount(); i++ )
			workers.push_back( CRunnable::ptr_t( new CWorkerThread( i, config.getWorkDir().c_str(), &queue ) ) );

		CThreadPool sigThread( signalHandler );
		CThreadPool portThreads( ports.begin(), ports.end() );
		CThreadPool workerThreads( workers.begin(), workers.end() );

		Log.ger<>( CRITICAL, "Server started" );

		workerThreads.join();
		portThreads.stop();
		sigThread.stop();
		Log.ger<>( CRITICAL, "Server stoped" );
	}
	catch ( GeneralException& e ) {
		Log.ger<>( CRITICAL, e );
	}

	return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x530, %rsp            # imm = 0x530
movl $0x0, -0x4(%rbp)
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
callq 0x29510
jmp 0x20a00
movl $0xa, %edi
callq 0x295a0
jmp 0x20a0c
movl -0x8(%rbp), %esi
movq -0x10(%rbp), %rdx
leaq 0x1ebc6(%rip), %rdi     # 0x3f5e0
callq 0x6c70
jmp 0x20a21
leaq 0x1ebb8(%rip), %rdi     # 0x3f5e0
callq 0x8610
movq %rax, -0x4b0(%rbp)
jmp 0x20a36
movq -0x4b0(%rbp), %rsi
leaq 0x1ec9c(%rip), %rdi     # 0x3f6e0
callq 0x1ff60
jmp 0x20a4b
leaq 0x1ec8e(%rip), %rdi     # 0x3f6e0
callq 0x20260
jmp 0x20a59
leaq 0x1ec80(%rip), %rdi     # 0x3f6e0
callq 0x20360
jmp 0x20a67
leaq 0x1eb72(%rip), %rdi     # 0x3f5e0
callq 0x85d0
movq %rax, -0x4b8(%rbp)
jmp 0x20a7c
movq -0x4b8(%rbp), %rsi
leaq -0x3c0(%rbp), %rdi
callq 0x210e0
jmp 0x20a91
movl $0x10, %edi
callq 0x64d0
movq %rax, -0x4c0(%rbp)
jmp 0x20aa4
movq -0x4c0(%rbp), %rdi
leaq -0x3c0(%rbp), %rsi
callq 0x2a110
jmp 0x20ab9
movq -0x4c0(%rbp), %rsi
leaq -0x3d0(%rbp), %rdi
callq 0x211a0
jmp 0x20ace
leaq -0x3e8(%rbp), %rdi
callq 0x211d0
movl $0x0, -0x3ec(%rbp)
movl -0x3ec(%rbp), %eax
movq %rax, -0x4d0(%rbp)
leaq 0x1eae8(%rip), %rdi     # 0x3f5e0
callq 0x85d0
movq %rax, -0x4c8(%rbp)
jmp 0x20b06
movq -0x4d0(%rbp), %rax
movq -0x4c8(%rbp), %rcx
cmpq %rcx, %rax
jae 0x20d31
movl $0x30, %edi
callq 0x64d0
movq %rax, -0x4d8(%rbp)
jmp 0x20b30
movl -0x3ec(%rbp), %eax
movl %eax, -0x4e4(%rbp)
leaq 0x1ea9d(%rip), %rdi     # 0x3f5e0
callq 0x85b0
movq %rax, -0x4e0(%rbp)
jmp 0x20b51
movq -0x4e0(%rbp), %rdi
movl -0x3ec(%rbp), %eax
movl %eax, %esi
callq 0x21220
movq %rax, %rdi
callq 0x6240
movq -0x4d8(%rbp), %rdi
movl -0x4e4(%rbp), %esi
movq %rax, %rdx
movl $0xa, %ecx
leaq -0x3c0(%rbp), %r8
callq 0x295f0
jmp 0x20b90
movq -0x4d8(%rbp), %rsi
leaq -0x400(%rbp), %rdi
callq 0x21240
jmp 0x20ba5
leaq -0x3e8(%rbp), %rdi
leaq -0x400(%rbp), %rsi
callq 0x211f0
jmp 0x20bba
leaq -0x400(%rbp), %rdi
callq 0x21270
leaq 0x1ea13(%rip), %rdi     # 0x3f5e0
callq 0x85b0
movq %rax, -0x4f0(%rbp)
jmp 0x20bdb
movq -0x4f0(%rbp), %rdi
movl -0x3ec(%rbp), %eax
movl %eax, %esi
callq 0x21220
movq %rax, %rcx
leaq 0x1eae7(%rip), %rdi     # 0x3f6e0
leaq 0xbc84(%rip), %rdx      # 0x2c884
leaq 0xbc82(%rip), %r8       # 0x2c889
movl $0x4, %esi
callq 0x21290
jmp 0x20c13
jmp 0x20d03
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x18(%rbp)
movl %eax, -0x1c(%rbp)
jmp 0x21071
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x18(%rbp)
movl %eax, -0x1c(%rbp)
jmp 0x21065
movq -0x4c0(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x18(%rbp)
movl %eax, -0x1c(%rbp)
movl $0x10, %esi
callq 0x64e0
jmp 0x21065
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x18(%rbp)
movl %eax, -0x1c(%rbp)
jmp 0x2104d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x18(%rbp)
movl %eax, -0x1c(%rbp)
jmp 0x20cb2
movq -0x4d8(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x18(%rbp)
movl %eax, -0x1c(%rbp)
movl $0x30, %esi
callq 0x64e0
jmp 0x20cb2
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x18(%rbp)
movl %eax, -0x1c(%rbp)
leaq -0x400(%rbp), %rdi
callq 0x21270
movl -0x1c(%rbp), %eax
movl $0x2, %ecx
cmpl %ecx, %eax
jne 0x2104d
movq -0x18(%rbp), %rdi
callq 0x6230
movq %rax, -0x408(%rbp)
leaq -0x3c0(%rbp), %rdi
callq 0x21360
jmp 0x20ce0
movq -0x408(%rbp), %rdx
leaq 0x1e9f2(%rip), %rdi     # 0x3f6e0
movl $0x1, %esi
callq 0x213c0
jmp 0x20cfa
callq 0x6880
jmp 0x20d01
jmp 0x20d03
jmp 0x20d05
movl -0x3ec(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3ec(%rbp)
jmp 0x20ae4
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x18(%rbp)
movl %eax, -0x1c(%rbp)
callq 0x6880
jmp 0x20d2c
jmp 0x2104d
leaq -0x420(%rbp), %rdi
callq 0x211d0
movl $0x0, -0x424(%rbp)
movl -0x424(%rbp), %eax
movq %rax, -0x500(%rbp)
leaq 0x1e885(%rip), %rdi     # 0x3f5e0
callq 0x8630
movq %rax, -0x4f8(%rbp)
jmp 0x20d69
movq -0x500(%rbp), %rax
movq -0x4f8(%rbp), %rcx
cmpq %rcx, %rax
jae 0x20e78
movl $0x20, %edi
callq 0x64d0
movq %rax, -0x508(%rbp)
jmp 0x20d93
movl -0x424(%rbp), %eax
movl %eax, -0x514(%rbp)
leaq 0x1e83a(%rip), %rdi     # 0x3f5e0
callq 0x85f0
movq %rax, -0x510(%rbp)
jmp 0x20db4
movq -0x510(%rbp), %rdi
callq 0x6240
movq -0x508(%rbp), %rdi
movl -0x514(%rbp), %esi
movq %rax, %rdx
leaq -0x3c0(%rbp), %rcx
callq 0x2a880
jmp 0x20dde
movq -0x508(%rbp), %rsi
leaq -0x438(%rbp), %rdi
callq 0x21480
jmp 0x20df3
leaq -0x420(%rbp), %rdi
leaq -0x438(%rbp), %rsi
callq 0x211f0
jmp 0x20e08
leaq -0x438(%rbp), %rdi
callq 0x21270
movl -0x424(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x424(%rbp)
jmp 0x20d47
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x18(%rbp)
movl %eax, -0x1c(%rbp)
jmp 0x21041
movq -0x508(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x18(%rbp)
movl %eax, -0x1c(%rbp)
movl $0x20, %esi
callq 0x64e0
jmp 0x21041
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x18(%rbp)
movl %eax, -0x1c(%rbp)
leaq -0x438(%rbp), %rdi
callq 0x21270
jmp 0x21041
leaq 0x9271(%rip), %rdx      # 0x2a0f0
leaq -0x450(%rbp), %rdi
leaq -0x3d0(%rbp), %rsi
callq 0x214b0
jmp 0x20e94
leaq -0x3e8(%rbp), %rdi
movq %rdi, -0x520(%rbp)
callq 0x215c0
movq -0x520(%rbp), %rdi
movq %rax, -0x470(%rbp)
callq 0x215f0
movq %rax, -0x478(%rbp)
leaq 0x9228(%rip), %rcx      # 0x2a0f0
leaq -0x468(%rbp), %rdi
leaq -0x470(%rbp), %rsi
leaq -0x478(%rbp), %rdx
callq 0x21620
jmp 0x20ee4
leaq -0x420(%rbp), %rdi
movq %rdi, -0x528(%rbp)
callq 0x215c0
movq -0x528(%rbp), %rdi
movq %rax, -0x498(%rbp)
callq 0x215f0
movq %rax, -0x4a0(%rbp)
leaq 0x91d8(%rip), %rcx      # 0x2a0f0
leaq -0x490(%rbp), %rdi
leaq -0x498(%rbp), %rsi
leaq -0x4a0(%rbp), %rdx
callq 0x21620
jmp 0x20f34
leaq 0x1e7a5(%rip), %rdi     # 0x3f6e0
leaq 0xb950(%rip), %rdx      # 0x2c892
movl $0x1, %esi
callq 0x21770
jmp 0x20f4e
leaq -0x490(%rbp), %rdi
callq 0x2a4f0
jmp 0x20f5c
leaq -0x468(%rbp), %rdi
movl $0xa, %esi
callq 0x2a6f0
jmp 0x20f6f
leaq -0x450(%rbp), %rdi
movl $0xa, %esi
callq 0x2a6f0
jmp 0x20f82
leaq 0x1e757(%rip), %rdi     # 0x3f6e0
leaq 0xb911(%rip), %rdx      # 0x2c8a1
movl $0x1, %esi
callq 0x21830
jmp 0x20f9c
leaq -0x490(%rbp), %rdi
callq 0x218f0
leaq -0x468(%rbp), %rdi
callq 0x218f0
leaq -0x450(%rbp), %rdi
callq 0x218f0
leaq -0x420(%rbp), %rdi
callq 0x21910
leaq -0x3e8(%rbp), %rdi
callq 0x21910
leaq -0x3d0(%rbp), %rdi
callq 0x21270
leaq -0x3c0(%rbp), %rdi
callq 0x21970
jmp 0x210ac
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x18(%rbp)
movl %eax, -0x1c(%rbp)
jmp 0x21035
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x18(%rbp)
movl %eax, -0x1c(%rbp)
jmp 0x21029
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x18(%rbp)
movl %eax, -0x1c(%rbp)
leaq -0x490(%rbp), %rdi
callq 0x218f0
leaq -0x468(%rbp), %rdi
callq 0x218f0
leaq -0x450(%rbp), %rdi
callq 0x218f0
leaq -0x420(%rbp), %rdi
callq 0x21910
leaq -0x3e8(%rbp), %rdi
callq 0x21910
leaq -0x3d0(%rbp), %rdi
callq 0x21270
leaq -0x3c0(%rbp), %rdi
callq 0x21970
movl -0x1c(%rbp), %eax
movl $0x1, %ecx
cmpl %ecx, %eax
jne 0x210cc
movq -0x18(%rbp), %rdi
callq 0x6230
movq %rax, -0x4a8(%rbp)
movq -0x4a8(%rbp), %rdx
leaq 0x1e645(%rip), %rdi     # 0x3f6e0
movl $0x1, %esi
callq 0x219c0
jmp 0x210a7
callq 0x6880
xorl %eax, %eax
addq $0x530, %rsp            # imm = 0x530
popq %rbp
retq
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x18(%rbp)
movl %eax, -0x1c(%rbp)
callq 0x6880
jmp 0x210ca
jmp 0x210cc
movq -0x18(%rbp), %rdi
callq 0x6920
movq %rax, %rdi
callq 0xb060
nopl (%rax)