// File: roberty65[P]bServer/frame/testClient/testBenchmark.cpp
// Function: async_worker(void*)
static void *async_worker(void *p)
{
	int id = (int)(long)p;
	char tag[128]; snprintf(tag, sizeof tag, "thread-%d", id);

	size_t msize = sizeof(struct proto_h16_head) + pkgSize;
	char *reqbuf = new char[msize];
	char *rspbuf = new char[msize];

	memset(reqbuf, 0, msize);
	memset(rspbuf, 0, msize);

	int fd = -1;
	while (true) {	
 		if (fd < 0) {
			fd = beyondy::XbsClient(host, O_NONBLOCK, timeout);
			if (fd < 0) {
				fprintf(stdout, "%s connect failed: %m\n", tag);
				continue;	
			}
		}

		int events = beyondy::XbsWaitPollable(fd, POLLIN|POLLOUT, 10);
		if (events == -1) continue;

		if (events & POLLOUT) {
			if (__send_req(fd, cmd, reqbuf, pkgSize, tag) < 0) {
				fprintf(stdout, "%s send req failed: %m\n", tag);
				close(fd); fd = -1;
				continue;
			}

			++pkgSent[id];
			byteSent[id] += pkgSize;
		}

		if (events & POLLIN) {
			if (__read_rsp(fd, rspbuf, pkgSize, tag) < 0) {
				fprintf(stdout, "%s send req failed: %m\n", tag);
				close(fd); fd = -1;
				continue;
			}

			++pkgRspd[id];
			byteRspd[id] += pkgSize;
		}
	}

	return NULL;

}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xb0, %rsp
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rax
movl %eax, -0xc(%rbp)
leaq -0x90(%rbp), %rdi
movl -0xc(%rbp), %ecx
movl $0x80, %esi
leaq 0x25b2(%rip), %rdx      # 0x520e
movb $0x0, %al
callq 0x2250
movslq 0x450e(%rip), %rax      # 0x7178
addq $0x10, %rax
movq %rax, -0x98(%rbp)
movq -0x98(%rbp), %rdi
callq 0x2030
movq %rax, -0xa0(%rbp)
movq -0x98(%rbp), %rdi
callq 0x2030
movq %rax, -0xa8(%rbp)
movq -0xa0(%rbp), %rdi
movq -0x98(%rbp), %rdx
xorl %esi, %esi
callq 0x2100
movq -0xa8(%rbp), %rdi
movq -0x98(%rbp), %rdx
xorl %esi, %esi
callq 0x2100
movl $0xffffffff, -0xac(%rbp) # imm = 0xFFFFFFFF
cmpl $0x0, -0xac(%rbp)
jge 0x2d22
movq 0x44a1(%rip), %rdi      # 0x7180
movslq 0x44a2(%rip), %rdx      # 0x7188
movl $0x800, %esi            # imm = 0x800
callq 0x3f50
movl %eax, -0xac(%rbp)
cmpl $0x0, -0xac(%rbp)
jge 0x2d20
movq 0x42b2(%rip), %rax      # 0x6fb8
movq (%rax), %rdi
leaq -0x90(%rbp), %rdx
leaq 0x2501(%rip), %rsi      # 0x5218
movb $0x0, %al
callq 0x2210
jmp 0x2ccf
jmp 0x2d22
movl -0xac(%rbp), %edi
movl $0x5, %esi
movl $0xa, %edx
callq 0x3060
movl %eax, -0xb0(%rbp)
cmpl $-0x1, -0xb0(%rbp)
jne 0x2d48
jmp 0x2ccf
movl -0xb0(%rbp), %eax
andl $0x4, %eax
cmpl $0x0, %eax
je 0x2df1
movl -0xac(%rbp), %edi
movl 0x440a(%rip), %esi      # 0x7170
movq -0xa0(%rbp), %rdx
movl 0x4405(%rip), %ecx      # 0x7178
leaq -0x90(%rbp), %r8
callq 0x2ea0
cmpl $0x0, %eax
jge 0x2dbd
movq 0x422d(%rip), %rax      # 0x6fb8
movq (%rax), %rdi
leaq -0x90(%rbp), %rdx
leaq 0x2493(%rip), %rsi      # 0x522f
movb $0x0, %al
callq 0x2210
movl -0xac(%rbp), %edi
callq 0x22b0
movl $0xffffffff, -0xac(%rbp) # imm = 0xFFFFFFFF
jmp 0x2ccf
movq 0x43d4(%rip), %rax      # 0x7198
movslq -0xc(%rbp), %rcx
movq (%rax,%rcx,8), %rdx
addq $0x1, %rdx
movq %rdx, (%rax,%rcx,8)
movslq 0x439d(%rip), %rsi      # 0x7178
movq 0x43be(%rip), %rax      # 0x71a0
movslq -0xc(%rbp), %rcx
movq (%rax,%rcx,8), %rdx
addq %rsi, %rdx
movq %rdx, (%rax,%rcx,8)
movl -0xb0(%rbp), %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0x2e94
movl -0xac(%rbp), %edi
movq -0xa8(%rbp), %rsi
movl 0x4362(%rip), %edx      # 0x7178
leaq -0x90(%rbp), %rcx
callq 0x2f90
cmpl $0x0, %eax
jge 0x2e60
movq 0x418a(%rip), %rax      # 0x6fb8
movq (%rax), %rdi
leaq -0x90(%rbp), %rdx
leaq 0x23f0(%rip), %rsi      # 0x522f
movb $0x0, %al
callq 0x2210
movl -0xac(%rbp), %edi
callq 0x22b0
movl $0xffffffff, -0xac(%rbp) # imm = 0xFFFFFFFF
jmp 0x2ccf
movq 0x4341(%rip), %rax      # 0x71a8
movslq -0xc(%rbp), %rcx
movq (%rax,%rcx,8), %rdx
addq $0x1, %rdx
movq %rdx, (%rax,%rcx,8)
movslq 0x42fa(%rip), %rsi      # 0x7178
movq 0x432b(%rip), %rax      # 0x71b0
movslq -0xc(%rbp), %rcx
movq (%rax,%rcx,8), %rdx
addq %rsi, %rdx
movq %rdx, (%rax,%rcx,8)
jmp 0x2ccf
nopl (%rax)