// File: /workspace/github_cpp_makefile_star2_O2/CDISC2020[P]Projet_satellite_agile/src/ARINC/ARINC_Com.cpp
// Function: SamplingPort::ReadSamplingMsg(char*)
int SamplingPort::ReadSamplingMsg(char* M){

		// Setting bit masks
  		FD_ZERO(&readfds);
		FD_SET(s_d, &readfds);
  		FD_ZERO(&writefds);
  		FD_ZERO(&exceptfds);

        int lc_a = sizeof(c_a);
	char e_t[LNGMAX]; // input buffer for message
        int le_t; // number of characters received

	int replys=0;

	// Reading loop until last message
	int last =0;

	// Socket desc id
	printf("Socket desc id = %d\n", s_d);

	// Table size
	printf("desc table size = %d\n", nds);

	while (last==0) {
		
    		 if ((nfds = select(nds,&readfds, &writefds, &exceptfds ,&timeout)) == SOCK_ERR) {
			printf("TRACE : errno = %d\n", errno);
    			perror("S-> select");
    			bye(s_d);
		}
    		else
			if (nfds==0) { // No more message in input queue, timeout elapsed
                       		printf("TRACE : no more message in the input queue \n");
                        	last=1;
                        }
			else { // Yes a message was read! nfds != 0)
                			//printf("TRACE : nfds = %d\n",nfds);
                			//printf("TRACE : reception sur PORT1\n");
                			lc_a = sizeof(c_a); le_t=0;
                			if ((le_t = recvfrom(s_d,e_t,sizeof(e_t),0,(struct sockaddr *)&c_a,(socklen_t *)&lc_a)) == SOCK_ERR) {
                			perror("S-> recvfrom");
                			bye(s_d);
                			}
                			else {
						//printf("TRACE : S-> %d ! Longueur tampon = %d\n", replys, le_t);
                        			//printf("TRACE : S-> tampon = %s\n", e_t);
                        			h_emetteur = gethostbyaddr(&c_a.sin_addr,sizeof(&c_a.sin_addr),c_a.sin_family); 
                        			//printf("TRACE : S-> Emetteur = %s \n",h_emetteur->h_name);
                        			//printf("TRACE : S-> Adresse IP: "); DisplaySocketAddress(&c_a);
                        			replys++;
                     			}
      				}

	} // end of while

	// Now , it's time to return last message and its size
	strcpy(M,e_t); // return the content of the message

	return(le_t); // return size of message

}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x428, %rsp            # imm = 0x428
movq %rsi, -0x40(%rbp)
movq %rdi, %rbx
leaq 0x4e0(%rdi), %rax
movq %rax, -0x38(%rbp)
xorl %eax, %eax
movq -0x38(%rbp), %rcx
cmpq $0x10, %rax
je 0x2c3e
andq $0x0, (%rcx,%rax,8)
incq %rax
jmp 0x2c2e
movl 0x404(%rbx), %esi
pushq $0x40
popq %rcx
movl %esi, %eax
cltd
idivl %ecx
movslq %eax, %rdx
shll $0x6, %eax
movl %esi, %ecx
subl %eax, %ecx
pushq $0x1
popq %rax
shlq %cl, %rax
orq %rax, 0x4e0(%rbx,%rdx,8)
leaq 0x560(%rbx), %r12
xorl %eax, %eax
cmpq $0x10, %rax
je 0x2c7d
andq $0x0, (%r12,%rax,8)
incq %rax
jmp 0x2c6d
leaq 0x5e0(%rbx), %r13
xorl %eax, %eax
cmpq $0x10, %rax
je 0x2c97
andq $0x0, (%r13,%rax,8)
incq %rax
jmp 0x2c86
leaq -0x2c(%rbp), %rax
movl $0x10, (%rax)
leaq 0x24c8(%rip), %rdi      # 0x5170
xorl %eax, %eax
callq 0x2040
movl 0x4d8(%rbx), %esi
leaq 0x24c9(%rip), %rdi      # 0x5185
xorl %eax, %eax
callq 0x2040
leaq 0x4c8(%rbx), %r14
leaq 0x418(%rbx), %rax
movq %rax, -0x50(%rbp)
leaq 0x41c(%rbx), %rax
movq %rax, -0x48(%rbp)
movl 0x4d8(%rbx), %edi
movq -0x38(%rbp), %rsi
movq %r12, %rdx
movq %r13, %rcx
movq %r14, %r8
callq 0x2230
movl %eax, 0x4c4(%rbx)
testl %eax, %eax
je 0x2d54
cmpl $-0x1, %eax
je 0x2d85
movl $0x10, -0x2c(%rbp)
movl 0x404(%rbx), %edi
movl $0x400, %edx            # imm = 0x400
leaq -0x450(%rbp), %rsi
xorl %ecx, %ecx
movq -0x50(%rbp), %r8
leaq -0x2c(%rbp), %r9
callq 0x21b0
movq %rax, %r15
cmpl $-0x1, %r15d
je 0x2da3
movzwl 0x418(%rbx), %edx
movq -0x48(%rbp), %rdi
pushq $0x8
popq %rsi
callq 0x22f0
movq %rax, 0x4b8(%rbx)
jmp 0x2ce0
leaq 0x245f(%rip), %rdi      # 0x51ba
callq 0x2390
leaq -0x450(%rbp), %rsi
movq -0x40(%rbp), %rdi
callq 0x2210
movl %r15d, %eax
addq $0x428, %rsp            # imm = 0x428
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x2030
movl (%rax), %esi
leaq 0x2408(%rip), %rdi      # 0x519b
xorl %eax, %eax
callq 0x2040
leaq 0x240e(%rip), %rdi      # 0x51af
jmp 0x2daa
leaq 0x2362(%rip), %rdi      # 0x510c
callq 0x21c0
movl 0x404(%rbx), %edi
callq 0x275c
nop