// File: /workspace/github_cpp_makefile_star2_O1/asdfz1346[P]MyServer/MyServer.cpp
// Function: MyServer::accept_thread_proc(void*)
void *MyServer::accept_thread_proc(void *args){
	MyServer* pthis = ((ARG*)args)->p;
	while(pthis->nstop){
		pthread_mutex_lock(&pthis->accept_mutex);
		pthread_cond_wait(&pthis->accept_cond,&pthis->accept_mutex);//block

		/*accept already,create newclientfd*/
		struct sockaddr_in clientaddr;
		socklen_t addrlen;
		int newfd = accept(pthis->listenfd,(struct sockaddr*)&clientaddr,&addrlen);
		pthread_mutex_unlock(&pthis->accept_mutex);
		if(newfd==-1) continue;
		/*set newfd sndbuf*/
		int nSndBufferLen = 4*1024*1024;
		int nLen          = sizeof(int);
		setsockopt(newfd,SOL_SOCKET,SO_SNDBUF,(char*)&nSndBufferLen,nLen);

		/*set newfd non-blocking;*/
		int oldflag = fcntl(newfd, F_GETFL, 0);
		int newflag = oldflag | O_NONBLOCK;
		if (fcntl(newfd, F_SETFL, newflag) == -1){
			std::cout << "fcntl error, oldflag = " << oldflag << ", newflag = " << newflag << std::endl;
			continue;
		}
		/*insert newfd to the set*/
	pthread_mutex_lock(&pthis->clientset_mutex);
		pthis->clientset.insert(newfd);
		pthread_mutex_unlock(&pthis->clientset_mutex);
		std::cout << "new client connect fd:"<<newfd<<std::endl;
		
		/*add epoll*/
		struct epoll_event e;
		memset (&e,0,sizeof e);
		e.events = EPOLLIN|EPOLLET;
		e.data.fd = newfd;
		if(epoll_ctl(pthis->epollfd,EPOLL_CTL_ADD,newfd,&e)==-1){
			std::cout << "epoll_ctl error,\n"<<std::endl;
		}

	}
	return NULL;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movq (%rdi), %r13
cmpb $0x1, 0x118(%r13)
jne 0x2a6c
leaq 0x70(%r13), %rbx
leaq 0xe8(%r13), %rax
movq %rax, -0x58(%rbp)
leaq 0x98(%r13), %rax
movq %rax, -0x50(%rbp)
leaq 0x40(%r13), %rax
movq %rax, -0x48(%rbp)
movq %rbx, %rdi
callq 0x2300
movq -0x58(%rbp), %rdi
movq %rbx, %rsi
callq 0x2310
movl 0x18(%r13), %edi
leaq -0x6c(%rbp), %rsi
leaq -0x5c(%rbp), %rdx
callq 0x20c0
movl %eax, -0x2c(%rbp)
movq %rbx, %rdi
callq 0x21d0
movl -0x2c(%rbp), %edi
cmpl $-0x1, %edi
je 0x2a5e
movl $0x400000, -0x30(%rbp)  # imm = 0x400000
movl $0x1, %esi
movl $0x7, %edx
leaq -0x30(%rbp), %rcx
movl $0x4, %r8d
callq 0x2390
movl -0x2c(%rbp), %edi
movl $0x3, %esi
xorl %edx, %edx
xorl %eax, %eax
callq 0x2160
movl %eax, %r15d
movl %eax, %r12d
orl $0x800, %r12d           # imm = 0x800
movl -0x2c(%rbp), %edi
movl $0x4, %esi
movl %r12d, %edx
xorl %eax, %eax
callq 0x2160
cmpl $-0x1, %eax
je 0x29ec
movq -0x50(%rbp), %r15
movq %r15, %rdi
callq 0x2300
movq -0x48(%rbp), %rdi
leaq -0x2c(%rbp), %rsi
callq 0x4bd0
movq %r15, %rdi
callq 0x21d0
movl $0x16, %edx
movq 0x469e(%rip), %r14      # 0x6fd8
movq %r14, %rdi
leaq 0x2712(%rip), %rsi      # 0x5056
callq 0x22a0
movl -0x2c(%rbp), %esi
movq %r14, %rdi
callq 0x2370
movq %rax, %r15
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r15, %rdi
movl $0xa, %esi
callq 0x2210
movsbl %al, %esi
movq %r15, %rdi
callq 0x2040
movq %rax, %rdi
callq 0x21a0
movq $0x0, -0x40(%rbp)
movl $0x0, -0x38(%rbp)
movl $0x80000001, -0x40(%rbp) # imm = 0x80000001
movl -0x2c(%rbp), %edx
movl %edx, -0x3c(%rbp)
movl 0x1c(%r13), %edi
movl $0x1, %esi
leaq -0x40(%rbp), %rcx
callq 0x22f0
cmpl $-0x1, %eax
jne 0x2a5e
movl $0x11, %edx
movq 0x4617(%rip), %r14      # 0x6fd8
movq %r14, %rdi
leaq 0x26a2(%rip), %rsi      # 0x506d
callq 0x22a0
movq (%r14), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x2210
movsbl %al, %esi
movq %r14, %rdi
jmp 0x2a51
movl $0x17, %edx
movq 0x45e0(%rip), %r14      # 0x6fd8
movq %r14, %rdi
leaq 0x262f(%rip), %rsi      # 0x5031
callq 0x22a0
movq %r14, %rdi
movl %r15d, %esi
callq 0x2370
movq %rax, %r15
movl $0xc, %edx
movq %rax, %rdi
leaq 0x2625(%rip), %rsi      # 0x5049
callq 0x22a0
movq %r15, %rdi
movl %r12d, %esi
callq 0x2370
movq %rax, %r15
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r15, %rdi
movl $0xa, %esi
callq 0x2210
movsbl %al, %esi
movq %r15, %rdi
callq 0x2040
movq %rax, %rdi
callq 0x21a0
cmpb $0x0, 0x118(%r13)
jne 0x2878
xorl %eax, %eax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop