// File: roberty65[P]bServer/frame/testClient/testBenchmark.cpp
// Function: sync_worker(void*)
static void *sync_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;
			}
		}

		if (__send_req(fd, cmd, reqbuf, pkgSize, tag) < 0) {
			fprintf(stdout, "%s send req failed: %m\n", tag);
			close(fd); fd = -1;
			continue;
		}
		else {
			++pkgSent[id];
			byteSent[id] += pkgSize;
		}

		if (__read_rsp(fd, rspbuf, pkgSize, tag) < 0) {
			fprintf(stdout, "%s read rsp failed: %m\n", tag);
			close(fd); fd = -1;
			continue;	
		}
		else {
			++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 0x27d2(%rip), %rdx      # 0x520e
movb $0x0, %al
callq 0x2250
movslq 0x472e(%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 0x2b02
movq 0x46c1(%rip), %rdi      # 0x7180
movslq 0x46c2(%rip), %rdx      # 0x7188
movl $0x800, %esi            # imm = 0x800
callq 0x3f50
movl %eax, -0xac(%rbp)
cmpl $0x0, -0xac(%rbp)
jge 0x2b00
movq 0x44d2(%rip), %rax      # 0x6fb8
movq (%rax), %rdi
leaq -0x90(%rbp), %rdx
leaq 0x2721(%rip), %rsi      # 0x5218
movb $0x0, %al
callq 0x2210
jmp 0x2aaf
jmp 0x2b02
movl -0xac(%rbp), %edi
movl 0x4662(%rip), %esi      # 0x7170
movq -0xa0(%rbp), %rdx
movl 0x465d(%rip), %ecx      # 0x7178
leaq -0x90(%rbp), %r8
callq 0x2ea0
cmpl $0x0, %eax
jge 0x2b65
movq 0x4485(%rip), %rax      # 0x6fb8
movq (%rax), %rdi
leaq -0x90(%rbp), %rdx
leaq 0x26eb(%rip), %rsi      # 0x522f
movb $0x0, %al
callq 0x2210
movl -0xac(%rbp), %edi
callq 0x22b0
movl $0xffffffff, -0xac(%rbp) # imm = 0xFFFFFFFF
jmp 0x2aaf
movq 0x462c(%rip), %rax      # 0x7198
movslq -0xc(%rbp), %rcx
movq (%rax,%rcx,8), %rdx
addq $0x1, %rdx
movq %rdx, (%rax,%rcx,8)
movslq 0x45f5(%rip), %rsi      # 0x7178
movq 0x4616(%rip), %rax      # 0x71a0
movslq -0xc(%rbp), %rcx
movq (%rax,%rcx,8), %rdx
addq %rsi, %rdx
movq %rdx, (%rax,%rcx,8)
movl -0xac(%rbp), %edi
movq -0xa8(%rbp), %rsi
movl 0x45cc(%rip), %edx      # 0x7178
leaq -0x90(%rbp), %rcx
callq 0x2f90
cmpl $0x0, %eax
jge 0x2bf6
movq 0x43f4(%rip), %rax      # 0x6fb8
movq (%rax), %rdi
leaq -0x90(%rbp), %rdx
leaq 0x2672(%rip), %rsi      # 0x5247
movb $0x0, %al
callq 0x2210
movl -0xac(%rbp), %edi
callq 0x22b0
movl $0xffffffff, -0xac(%rbp) # imm = 0xFFFFFFFF
jmp 0x2aaf
movq 0x45ab(%rip), %rax      # 0x71a8
movslq -0xc(%rbp), %rcx
movq (%rax,%rcx,8), %rdx
addq $0x1, %rdx
movq %rdx, (%rax,%rcx,8)
movslq 0x4564(%rip), %rsi      # 0x7178
movq 0x4595(%rip), %rax      # 0x71b0
movslq -0xc(%rbp), %rcx
movq (%rax,%rcx,8), %rdx
addq %rsi, %rdx
movq %rdx, (%rax,%rcx,8)
jmp 0x2aaf
nop