Hello again, the problem continous, in this moment i have achived accept the
connection, then i have inserted in a select struct the three request socket
.

When the customer send me a request i awake in select, but i can read
anything, the program block in recv. The size of this reception is variable,
in my first connection i ´must receive 10 bytes.

The code:

 FD_ZERO(&readset);
      maxfd=0;
      for(i=1;i<4;i++)
       {
        FD_SET(aSocket[i], &readset);
        if (aSocket[i]> maxfd)
         maxfd = aSocket[i];
       }

      print_dbg(" Metemos los 3 Sockets por donde podemos recibir para
entrar en el select \n");

      while(1){
          // Check for received packets on configured sockets (blocking )
          ret = select(maxfd+1, &readset, NULL, NULL, NULL);

          if (ret > 0) //No error
            {
              //Check data for socket 1
              if (FD_ISSET(aSocket[1], &readset))
                ProcessRequestPC_to_RTU(aSocket[1]);

              //Check data for socket 2
              if (FD_ISSET(aSocket[2], &readset))
               ProcessRequestPC_to_PCU(aSocket[2]);

              //Check data for socket 3
              if (FD_ISSET(aSocket[3], &readset))
               ProcessRequestPC_Finish(aSocket[3]);
            }
          }
          }


and one fucntion:

void static ProcessRequestPC_to_RTU (int s)
{
 int result,nbytesRx;
 long code_command,length_command;

  nbytesRx=0; //Total=0;
  print_dbg(" Recibida peticion RTU por socket: ");
  print_dbg_ulong(s);
  print_dbg(" \n");



  result = recv(s, BufferRx,sizeof(BufferRx), 0);    //Block the program and
i saw with wireshark that the message is full with 10 bytes

  if (result<=0) //Error or close connection
   {
    CloseConnectionPC(aSocket,lSocket );
    return;
   }
  nbytesRx+=result; //Byte received

  //Calculate the Length. ¡¡¡¡¡ I supposed that 4 byte are received always
TAKE CARE!!!!!!!
  memcpy(&length_command, BufferRx, LENGHT_RX);
  if (length_command!=nbytesRx)
  {
   do{
       result = recv(s, BufferRx+nbytesRx, length_command-nbytesRx, 0);
       if (result<=0) //Error or close connection
          {
           CloseConnectionPC(aSocket,lSocket );
           return;
          }
       nbytesRx+=result;

     } while (nbytesRx<length_command);
  }
  //All message is received
  memcpy(&code_command, BufferRx+LENGHT_RX,L_CODE_RX); //copy the code of
message

  switch(code_command)
  {
    ......

More thing, the size of buffer is 2048m but i want to use a buffer of 12000
bytes. If i write this size of buffer crack the application, and don´t
create this task

Thanks
Oscar
_______________________________________________
lwip-users mailing list
[email protected]
http://lists.nongnu.org/mailman/listinfo/lwip-users

Reply via email to