cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
aod62
Observer
Observer
2,659 Views
Registered: ‎06-17-2011

lwip - RAW - two connections collide

Hi,

 

I am using the "standalone" program and lwip in "RAW" mode.  I have a problem when two connections connect requesting a file at the same-ish time.  The file is 16MByte so I am using  the sent_callback() function to send the file in blocks when there is some space in tcp_sndbuf().  If one connection has downloaded say 1/2 the file and another connection requests the same file.  The system gets it's knickers in a twist and you have to request the file from one connection several times to get it to download properly.

 

Any ideas?

 

I have included the sent_callback() function below in case I am doing something silly

 

err_t sent_callback(struct http_arg *arg, struct tcp_pcb *tpcb, struct pbuf *p, u16_t len)
{
    int num, bytesleft;
//    Xuint8 *rambuf = (Xuint8*)MFS_IMAGE_BASEADDR;

    /* if connection is closed, or there is no data to send */
    if (tpcb->state > ESTABLISHED) {
    return ERR_OK;
    }


    if(arg->fsize)
    {

        num = tcp_sndbuf(tpcb);
        bytesleft = arg->fsize;

        if(num > (TCP_SND_BUF/2) || num >= bytesleft)   //set to 1/2 the send buffer length
        {
            if(num > bytesleft)
            {
                //rambuf = (Xuint32)MFS_IMAGE_BASEADDR + (Xuint32)(DATA_FILESIZE-bytesleft);
                tcp_write(tpcb, (Xuint32*)arg->buff, bytesleft, 1);
                arg->fsize = 0;
                pbuf_free(p);
                //tcp_close(tpcb);

            }else{
                //rambuf = (Xuint32)MFS_IMAGE_BASEADDR + (Xuint32)(DATA_FILESIZE-bytesleft);
                tcp_write(tpcb, (Xuint32*)arg->buff, num, 1);
                arg->fsize -= num;
                arg->buff += num;
                //xil_printf("%d - %d,",num,arg->fsize);
            }


        }
    }else
        //tcp_close(tpcb);


    return ERR_OK;
}

0 Kudos
0 Replies