// File: /workspace/github_cpp_makefile_star2_O3/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
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)
movl 0x404(%rdi), %ebx
leal 0x3f(%rbx), %eax
testl %ebx, %ebx
cmovnsl %ebx, %eax
movl %eax, %edx
andl $-0x40, %edx
movl %ebx, %ecx
subl %edx, %ecx
movl $0x1, %edx
shlq %cl, %rdx
sarl $0x6, %eax
cltq
orq %rdx, 0x4e0(%rdi,%rax,8)
leaq 0x4e0(%rdi), %rax
movq %rax, -0x58(%rbp)
leaq 0x404(%rdi), %rax
movq %rax, -0x38(%rbp)
addq $0x560, %rdi            # imm = 0x560
leaq 0x5e0(%r14), %rax
movq %rax, -0x48(%rbp)
movl $0x100, %edx            # imm = 0x100
movq %rdi, -0x50(%rbp)
xorl %esi, %esi
callq 0x3170
leaq -0x2c(%rbp), %rax
movl $0x10, (%rax)
leaq 0x2fb7(%rip), %rdi      # 0x7170
movl %ebx, %esi
xorl %eax, %eax
callq 0x3050
movl 0x4d8(%r14), %esi
leaq 0x2fb5(%rip), %rdi      # 0x7185
xorl %eax, %eax
callq 0x3050
leaq 0x4c8(%r14), %r15
leaq 0x418(%r14), %r12
leaq 0x41c(%r14), %rbx
movl 0x4d8(%r14), %edi
movq -0x58(%rbp), %rsi
movq -0x50(%rbp), %rdx
movq -0x48(%rbp), %rcx
movq %r15, %r8
callq 0x3280
movl %eax, 0x4c4(%r14)
testl %eax, %eax
je 0x4265
cmpl $-0x1, %eax
je 0x4296
movl $0x10, -0x2c(%rbp)
movq -0x38(%rbp), %rax
movl (%rax), %edi
movl $0x400, %edx            # imm = 0x400
leaq -0x460(%rbp), %rsi
xorl %ecx, %ecx
movq %r12, %r8
leaq -0x2c(%rbp), %r9
callq 0x31f0
movq %rax, %r13
cmpl $-0x1, %r13d
je 0x429f
movzwl 0x418(%r14), %edx
movq %rbx, %rdi
movl $0x8, %esi
callq 0x3360
movq %rax, 0x4b8(%r14)
jmp 0x41ec
leaq 0x2f4e(%rip), %rdi      # 0x71ba
callq 0x33f0
leaq -0x460(%rbp), %rsi
movq -0x40(%rbp), %rdi
callq 0x3260
movl %r13d, %eax
addq $0x438, %rsp            # imm = 0x438
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq -0x38(%rbp), %rdi
callq 0x3588
movq -0x38(%rbp), %rdi
callq 0x35b9