// File: jBlinden[P]private-codis/./socket.h
// Function: CSocket::Receive(void*, int, int)
int Receive(void* pBuf, int nLen, int nFlags = 0) {
    struct timespec start, stop;
    clock_gettime( CLOCK_REALTIME, &start);

    bytesReceived += nLen;

    char* p = (char*) pBuf;
    int n = nLen;
    int ret = 0;
    while (n > 0) {
      ret = recv(m_hSock, p, n, 0);
      if (ret < 0) {
        if (errno == EAGAIN) {
          cout << "socket recv eror: EAGAIN" << endl;
          usleep(200);
          continue;
        } else {
          cout << "socket recv error: " << errno << endl;
          
          clock_gettime( CLOCK_REALTIME, &stop);
          networkTime += (stop.tv_sec - start.tv_sec) * BILLION + stop.tv_nsec - start.tv_nsec;
          return ret;
        }
      } else if (ret == 0) {
        clock_gettime( CLOCK_REALTIME, &stop);
        networkTime += (stop.tv_sec - start.tv_sec) * BILLION + stop.tv_nsec - start.tv_nsec;
        return ret;
      }
      p += ret;
      n -= ret;
    }
    clock_gettime( CLOCK_REALTIME, &stop);
    networkTime += (stop.tv_sec - start.tv_sec) * BILLION + stop.tv_nsec - start.tv_nsec;
    return nLen;
  }

// Assembly:
subq $0x68, %rsp
movq %rdi, 0x58(%rsp)
movq %rsi, 0x50(%rsp)
movl %edx, 0x4c(%rsp)
movl %ecx, 0x48(%rsp)
movq 0x58(%rsp), %rax
movq %rax, 0x10(%rsp)
xorl %edi, %edi
leaq 0x38(%rsp), %rsi
callq 0x3250
movq 0x10(%rsp), %rax
movslq 0x4c(%rsp), %rcx
addq 0x10(%rax), %rcx
movq %rcx, 0x10(%rax)
movq 0x50(%rsp), %rax
movq %rax, 0x20(%rsp)
movl 0x4c(%rsp), %eax
movl %eax, 0x1c(%rsp)
movl $0x0, 0x18(%rsp)
cmpl $0x0, 0x1c(%rsp)
jle 0x8799
movq 0x10(%rsp), %rax
movl (%rax), %edi
movq 0x20(%rsp), %rsi
movslq 0x1c(%rsp), %rdx
xorl %ecx, %ecx
callq 0x3100
movl %eax, 0x18(%rsp)
cmpl $0x0, 0x18(%rsp)
jge 0x872b
callq 0x3040
cmpl $0xb, (%rax)
jne 0x86b2
movq 0x494d(%rip), %rdi      # 0xcfd8
leaq 0x1c61(%rip), %rsi      # 0xa2f3
callq 0x32a0
movq %rax, %rdi
movq 0x491f(%rip), %rsi      # 0xcfc0
callq 0x32f0
movl $0xc8, %edi
callq 0x33d0
jmp 0x8648
movq 0x491f(%rip), %rdi      # 0xcfd8
leaq 0x1c4c(%rip), %rsi      # 0xa30c
callq 0x32a0
movq %rax, 0x8(%rsp)
callq 0x3040
movq 0x8(%rsp), %rdi
movl (%rax), %esi
callq 0x3450
movq %rax, %rdi
movq 0x48db(%rip), %rsi      # 0xcfc0
callq 0x32f0
xorl %edi, %edi
leaq 0x28(%rsp), %rsi
callq 0x3250
movq 0x10(%rsp), %rax
movq 0x28(%rsp), %rcx
subq 0x38(%rsp), %rcx
imulq $0x3b9aca00, %rcx, %rcx # imm = 0x3B9ACA00
addq 0x30(%rsp), %rcx
subq 0x40(%rsp), %rcx
addq 0x18(%rax), %rcx
movq %rcx, 0x18(%rax)
movl 0x18(%rsp), %eax
movl %eax, 0x64(%rsp)
jmp 0x87d5
cmpl $0x0, 0x18(%rsp)
jne 0x8770
xorl %edi, %edi
leaq 0x28(%rsp), %rsi
callq 0x3250
movq 0x10(%rsp), %rax
movq 0x28(%rsp), %rcx
subq 0x38(%rsp), %rcx
imulq $0x3b9aca00, %rcx, %rcx # imm = 0x3B9ACA00
addq 0x30(%rsp), %rcx
subq 0x40(%rsp), %rcx
addq 0x18(%rax), %rcx
movq %rcx, 0x18(%rax)
movl 0x18(%rsp), %eax
movl %eax, 0x64(%rsp)
jmp 0x87d5
jmp 0x8772
movl 0x18(%rsp), %ecx
movq 0x20(%rsp), %rax
movslq %ecx, %rcx
addq %rcx, %rax
movq %rax, 0x20(%rsp)
movl 0x18(%rsp), %ecx
movl 0x1c(%rsp), %eax
subl %ecx, %eax
movl %eax, 0x1c(%rsp)
jmp 0x8648
xorl %edi, %edi
leaq 0x28(%rsp), %rsi
callq 0x3250
movq 0x10(%rsp), %rax
movq 0x28(%rsp), %rcx
subq 0x38(%rsp), %rcx
imulq $0x3b9aca00, %rcx, %rcx # imm = 0x3B9ACA00
addq 0x30(%rsp), %rcx
subq 0x40(%rsp), %rcx
addq 0x18(%rax), %rcx
movq %rcx, 0x18(%rax)
movl 0x4c(%rsp), %eax
movl %eax, 0x64(%rsp)
movl 0x64(%rsp), %eax
addq $0x68, %rsp
retq
nop