lwip-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[lwip-users] Raw Lwip - TCP application


From: Paul C
Subject: [lwip-users] Raw Lwip - TCP application
Date: Tue, 21 Dec 2004 13:25:04 +1030

Hi Everyone.


I have been developing a TCP application that connects via tcp to 
a server. I have been using code like this

// PSEUDO CODE #1
        ushort svr_port = 1234;
        struct ip_addr svr;
        struct tcp_pcb *PotentialHost = tcp_new();

        if (PotentialHost == NULL) return;        
        IP4_ADDR(&svr, 10.0.0.1);        
        err = tcp_bind(PotentialHost, IP_ADDR_ANY, 0);

        tcp_accept(PotentialHost, a_new_connection); 
        tcp_err(PotentialHost,    connection_err);
        tcp_poll(PotentialHost,   connection_poll, 1);
        tcp_recv(PotentialHost,   connection_recv);
        tcp_sent(PotentialHost,   connection_sent);
        tcp_arg(PotentialHost, (void *)StateInformation);
        err = tcp_connect(PotentialHost, &svr, svr_port,
        connection_start); 


// END CODE #1

However I have a problem with a pbuf leak that appears to be caused when
the
server sends a TCP_RST when the connection is trying to open. (There is
no
leak normally, only when there have been multiple restarts. I don't use
a
clock
to set the start sequence so the TCP start sequence can be inside the
server's acceptable window for several seconds!) I think 
that the problem is caused because although the connection is started
the 
connection is not "running" until the connection_start function is
called. 
However with Code #1 the connection_poll function can be called by the 
tcp_slow_tmr(), which (in my case) has a tcp_close() inactivity timer.

So I am thinking that it is preferable to have the connection start
function
set these values after the connection is open. Like in CODE #2.

// PSEUDO CODE #2

connection_start( ...)
{
        tcp_err(PotentialHost,    connection_err);
        tcp_poll(PotentialHost,   connection_poll, 1);
        tcp_recv(PotentialHost,   connection_recv);
        tcp_sent(PotentialHost,   connection_sent);
        tcp_arg(PotentialHost, (void *)StateInformation);
}

// AND start the connection like this

        ushort svr_port = 1234;
        struct ip_addr svr;
        struct tcp_pcb *PotentialHost = tcp_new();

        if (PotentialHost == NULL) return;        
        IP4_ADDR(&svr, 10.0.0.1);        
        err = tcp_bind(PotentialHost, IP_ADDR_ANY, 0);

        tcp_accept(PotentialHost, a_new_connection);
        tcp_err(PotentialHost,    NULL);
        tcp_poll(PotentialHost,   NULL, 1);
        tcp_recv(PotentialHost,   NULL);
        tcp_sent(PotentialHost,   NULL);
        tcp_arg(PotentialHost, NULL);
        err = tcp_connect(PotentialHost, &svr, svr_port,
        connection_start); 

// END CODE #2

Does anyone have any comments on which way the code should be written?

Thanks

Paul Clarke




reply via email to

[Prev in Thread] Current Thread [Next in Thread]