Thank you again Kieran, first i would tell you the situation today.
i have three socket, i received data of two and fail in the other. The size
of the buffer today is 2048, but i have a message of 12000 bytes. In this
moment i can´t declare this buffer because the application crack and RTOS
don´t enter. this is my other problem and i hope solve too.
I have tested to define a little buffer ( 10 bytes ) but recv( ) don´t enter
in this socket. i don´t understand because in two socket work!! and in the
other no.
The other solution (" make recv non-blocking") should test, but one
question: If enter in the fucntion and the size received is not the total,
select wait again, no ? and i only would have to do the call to recv (not
blocking ) until the lengh of the message is total received.
please , if i want to define a big buffer 12000, what variable of config i
have to change in RTOS and lwipopts should i change. My micro is
AT32UC3A0512 and i think i have enough memory ( 512 Kb falsh and 64K of
SRAM). today the program need 200Kbytes en flash. Maybe i need to define the
buffer in internal flash and not in the RAM memory. I not sure but this
declaration fail:
static portCHAR BufferRx[TAM_RX_RTU]; TAM_RX_RTU=2048.
Any advice?
Regards
Thanks
Oscar
The CODE today:
while(1){
FD_ZERO(&readset);
maxfd=0;
print_dbg(" Metemos los 3 Sockets por donde podemos recibir para
entrar en el select \n");
for(i=1;i<4;i++)
{
FD_SET(aSocket[i], &readset);
print_dbg("socket : ");
print_dbg_ulong(aSocket[i]);
print_dbg("\n ");
if (aSocket[i]> maxfd)
maxfd = aSocket[i];
}
// Check for received packets on configured sockets (blocking )
ret = select(maxfd+1, &readset, NULL, NULL, NULL);
print_dbg("select ha entrado \n");
if (ret > 0) //No error
{
//Check data for socket 1
if (FD_ISSET(aSocket[1], &readset))
* ProcessRequestPC_to_RTU(aSocket[1]); //DON¨T RECEIVE*
//Check data for socket 2
if (FD_ISSET(aSocket[2], &readset))
* ProcessRequestPC_to_PCU(aSocket[2]);* *//RECEIVE OK*
//Check data for socket 3
if (FD_ISSET(aSocket[3], &readset))
* ProcessRequestPC_Finish(aSocket[3]); //RECEIVE OK*
}
else
{
print_dbg(" Error en select \n");
CloseConnectionPC(aSocket,lSocket );
return;
}
}
}
void static ProcessRequestPC_to_RTU (int s)
{
int result,nbytesRx;
long code_command,length_command;
print_dbg("Recibido mensaje RTU \n");
nbytesRx=0; //Total=0;
result = recv(s, BufferRx, TAM_RX_RTU, 0);
if (result<=0) //Error or close connection
{
print_dbg("Fallo Recv \n");
CloseConnectionPC(aSocket,lSocket );
return;
}
nbytesRx+=result; //Byte received
print_dbg("Procesando RTU 1 \n");
//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
{
print_dbg("Fallo Recv \n");
CloseConnectionPC(aSocket,lSocket );
return;
}
print_dbg("Procesando RTU 2 \n");
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)
{
}
}
void static ProcessRequestPC_to_PCU (int s)
{
int result,nbytesRx;
long code_command,length_command;
print_dbg("Recibido mensaje PCU \n");
nbytesRx=0;
result = recv(s, BufferRx, TAM_RX_RTU, 0);
if (result<=0)
{
print_dbg("Fallo Recv \n");
CloseConnectionPC(aSocket,lSocket );
return;
}
nbytesRx+=result;
//Calculate the Length
memcpy(&length_command, BufferRx, LENGHT_RX);
if (length_command!=nbytesRx)
{
do{
result = recv(s, BufferRx+nbytesRx, length_command-nbytesRx, 0);
if (result<=0)
{
print_dbg("Fallo Recv \n");
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)
{
}
}
void static ProcessRequestPC_Finish (int s)
{
int result,nbytesRx;
long code_command,length_command;
print_dbg("Recibido mensaje Finish \n");
nbytesRx=0;
result = recv(s, BufferRx, TAM_RX_RTU, 0);
if (result<=0)
{
print_dbg("Fallo Recv \n");
CloseConnectionPC(aSocket,lSocket );
return;
}
nbytesRx+=result;
print_dbg("Procesando finish 1 \n");
//Calculate the Length
memcpy(&length_command, BufferRx, LENGHT_RX);
if (length_command!=nbytesRx)
{
do{
result = recv(s, BufferRx+nbytesRx, length_command-nbytesRx, 0);
if (result<=0)
{
print_dbg("Fallo Recv \n");
CloseConnectionPC(aSocket,lSocket );
return;
}
print_dbg("Procesando finish 2 \n");
nbytesRx+=result;
} while (nbytesRx<length_command);
}
//All message is received
memcpy(&code_command, BufferRx+LENGHT_RX, L_CODE_RX); //copy the code
of message
print_dbg("Comando recibido= ");
print_dbg_ulong(code_command);
print_dbg("\n Longitud= ");
print_dbg_ulong(length_command);
switch(code_command)
{
case ID_SPR_01:
print_dbg("\n cerramos pero falla");
CloseConnectionPC(aSocket,lSocket );
return;
}
}
On Wed, Sep 30, 2009 at 4:44 PM, Kieran Mansley <[email protected]> wrote:
> On Wed, 2009-09-30 at 12:48 +0200, Oscar F wrote:
> > 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.
>
> My guess is that you're stuck in this bit:
>
> > result = recv(s, BufferRx,sizeof(BufferRx), 0); //Block the
> > program and i saw with wireshark that the message is full with 10
> > bytes
>
> What is sizeof(BufferRx)? The recv() function may block waiting for the
> buffer to be full, so if you have given it a large buffer, you could
> have to wait a while for it to fill up and return. If I remember from
> your earlier posts you don't have much memory allocated to network
> buffers, so it may be that there are just not enough network buffers to
> hold that amount of data, and it never gets full, and recv never
> returns.
>
> You could either:
> 1) give a smaller length argument to recv() - it sounds like you only
> want 10 bytes of data, so give it the value 10.
> 2) make recv non-blocking by passing the MSG_DONTWAIT flag in the flags
> argument - it will then return whatever data it can get (which may be
> nothing, but as select has said there is some it should return
> something).
>
> Kieran
>
>
>
> _______________________________________________
> lwip-users mailing list
> [email protected]
> http://lists.nongnu.org/mailman/listinfo/lwip-users
>
_______________________________________________
lwip-users mailing list
[email protected]
http://lists.nongnu.org/mailman/listinfo/lwip-users