// File: /workspace/github_cpp_makefile_star2_O1/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 $0x438, %rsp            # imm = 0x438
movq %rsi, -0x40(%rbp)
movq %rdi, %r14
leaq 0x4e0(%rdi), %rax
movq %rax, -0x58(%rbp)
xorps %xmm0, %xmm0
movups %xmm0, 0x550(%rdi)
movups %xmm0, 0x540(%rdi)
movups %xmm0, 0x530(%rdi)
movups %xmm0, 0x520(%rdi)
movups %xmm0, 0x510(%rdi)
movups %xmm0, 0x500(%rdi)
movups %xmm0, 0x4f0(%rdi)
movups %xmm0, 0x4e0(%rdi)
leaq 0x404(%rdi), %rax
movq %rax, -0x38(%rbp)
movl 0x404(%rdi), %esi
leal 0x3f(%rsi), %eax
testl %esi, %esi
cmovnsl %esi, %eax
movl %eax, %edx
andl $-0x40, %edx
movl %esi, %ecx
subl %edx, %ecx
movl $0x1, %edx
shlq %cl, %rdx
sarl $0x6, %eax
cltq
orq %rdx, 0x4e0(%rdi,%rax,8)
leaq 0x560(%rdi), %r13
movups %xmm0, 0x5d0(%rdi)
movups %xmm0, 0x5c0(%rdi)
movups %xmm0, 0x5b0(%rdi)
movups %xmm0, 0x5a0(%rdi)
movups %xmm0, 0x590(%rdi)
movups %xmm0, 0x580(%rdi)
movups %xmm0, 0x570(%rdi)
movups %xmm0, 0x560(%rdi)
leaq 0x5e0(%rdi), %rbx
movups %xmm0, 0x5e0(%rdi)
movups %xmm0, 0x5f0(%rdi)
movups %xmm0, 0x600(%rdi)
movups %xmm0, 0x610(%rdi)
movups %xmm0, 0x620(%rdi)
movups %xmm0, 0x630(%rdi)
movups %xmm0, 0x640(%rdi)
movups %xmm0, 0x650(%rdi)
leaq -0x2c(%rbp), %rax
movl $0x10, (%rax)
leaq 0x2f4b(%rip), %rdi      # 0x7170
xorl %eax, %eax
callq 0x3050
movl 0x4d8(%r14), %esi
leaq 0x2f4b(%rip), %rdi      # 0x7185
xorl %eax, %eax
callq 0x3050
leaq 0x4c8(%r14), %r12
leaq 0x418(%r14), %rax
movq %rax, -0x50(%rbp)
leaq 0x41c(%r14), %rax
movq %rax, -0x48(%rbp)
movl 0x4d8(%r14), %edi
movq -0x58(%rbp), %rsi
movq %r13, %rdx
movq %rbx, %rcx
movq %r12, %r8
callq 0x3270
movl %eax, 0x4c4(%r14)
testl %eax, %eax
je 0x42dd
cmpl $-0x1, %eax
je 0x4318
movl $0x10, -0x2c(%rbp)
movq -0x38(%rbp), %rax
movl (%rax), %edi
movl $0x400, %edx            # imm = 0x400
leaq -0x460(%rbp), %rsi
xorl %ecx, %ecx
movq -0x50(%rbp), %r8
leaq -0x2c(%rbp), %r9
callq 0x31e0
movq %rax, %r15
cmpl $-0x1, %r15d
je 0x4321
movzwl 0x418(%r14), %edx
movq -0x48(%rbp), %rdi
movl $0x8, %esi
callq 0x3350
movq %rax, 0x4b8(%r14)
movb $0x1, %al
jmp 0x42eb
leaq 0x2ed6(%rip), %rdi      # 0x71ba
callq 0x33e0
xorl %eax, %eax
testb %al, %al
jne 0x425e
leaq -0x460(%rbp), %rsi
movq -0x40(%rbp), %rdi
callq 0x3250
movl %r15d, %eax
addq $0x438, %rsp            # imm = 0x438
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq -0x38(%rbp), %rdi
callq 0x3578
movq -0x38(%rbp), %rdi
callq 0x35a9
nop