lwip-users
[Top][All Lists]
Advanced

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

Re: [lwip-users] lwIP tcp_write fails: specifically tcp_sndbufreturning


From: Noam weissman
Subject: Re: [lwip-users] lwIP tcp_write fails: specifically tcp_sndbufreturning 0
Date: Thu, 25 Apr 2013 16:15:10 +0300

Hi,

I do not see all your code so it is a problem understanding.

Are you aware that when you create a TCP server you get one PCB (the listening 
PCB) and a different 
PCB for connection... they are different ?

In your init server you call the following:

   pcb = tcp_new(); // this is local PCB !

     // bind local IP with our port
     err = tcp_bind(pcb, IP_ADDR_ANY, TcpTermPort);
     
     if(err == ERR_OK)
     {
       // The tcp_listen() function returns a new connection control block, and 
       // the one passed as an argument to the function will be deallocated. 
The 
       // reason for this behavior is that less memory is needed for a 
connection 
       // that is listening, so tcp_listen() will reclaim the memory needed for 
       // the original connection and allocate a new smaller memory block for 
the 
       // listening connection.       
       Listening_pcb = tcp_listen(pcb);
   
       // if we are here that mean that we did not use all available connection
       // and we are ready to treat another one.
       tcp_setprio(Listening_pcb, TCP_PRIO_MIN);  // <<<<<< This is a Global 
PCB if you need it
              
       tcp_accept(Listening_pcb, tcp_term_accept);
.
.
.
.

In your accept function:
static err_t tcp_term_accept(void *arg, struct tcp_pcb *pcb, err_t err)
{
.
.
.
    // disable nagle algorithm, improve performance with winxp.
    tcp_nagle_disable(pcb); 
               
    // set sent call back function
    tcp_sent(pcb, tcp_term_sent);
    
    // Tell TCP that we wish to be informed of incoming data by a call to the 
    tcp_recv(pcb, tcp_term_recv);

    // set error call back function
    tcp_err(pcb, tcp_term_conn_err); 
          
    // set polling call back function    
    tcp_poll(pcb, tcp_term_poll, POLL_INTERVAL); 


    // Tell TCP that this is the structure we wish to be passed for our 
callbacks if you have one ???.
    tcp_arg(pcb, ts);    
    
    
    // this function call does nothing. Usefull only if TCP_LISTEN_BACKLOG is 
set
    tcp_accepted(Listening_pcb);

}


When you send something out via the above connection you use the pcb that was 
passed 
In the tcp_term_accept


Hope that helps.

BR,
Noam.







-----Original Message-----
From: address@hidden [mailto:address@hidden On Behalf Of address@hidden
Sent: ה 25 אפריל 2013 15:35
To: address@hidden
Subject: [lwip-users] lwIP tcp_write fails: specifically tcp_sndbufreturning 0


I have seen MANY MANY posts about this topic, but none are quite the same 
situation as mine, and thus do not pose any solutions that work for me.


What I have:  I have a basic echo server example running on a Stellaris 
LM3S6611.  I wrote the example based on code I found here 
http://www.ultimaserial.com/avr_lwip_tcp.html .  I used the 'Raw API 
Programming example'.  That code works fine.  I can connect to my board using 
telnet, from a linux laptop, and send (I defined it this way) capital 'T' 
characters to toggle an LED on my board, while ALSO echoing back the typed in 
data (T in this case).


What I want:  I want to extend this example to send a message over THE SAME 
socket, when a button is pressed.


The problem:  I moved my pcb to global scope.  I added a button handler with 
the following code:


void API_pushButtonState(void)
{
        int len;
        strncpy(buf, "button", 6);
        len = tcp_sndbuf(pcb);

        tcp_write(pcb, buf, len, TCP_WRITE_FLAG_COPY);
        tcp_sent(pcb, NULL);
        tcp_output(pcb);
}


>From my understanding, and the LOADS of documentation I have read, this should 
>send my message out.  This will not work.  I have checked with Wireshark.  
>Nothing is being sent out the wire.  I can see both messages of the echo 
>request (the msg from the computer to the board, and the echo response from 
>the board to the computer), but nothing when I press my button.


I have debugged the code to verify that when I press the button I am indeed 
entering the function above.  I'm assuming my misunderstanding is with 
tcp_sndbuf.  It always returns 0 when called from this function.  I can't 
decide if the debugger is just lying to me, or if it actually is 0.  If I call 
tcp_sndbuf at startup, I get some massive number (like 26285 or something).  If 
I check the disassembly window DURING the call to this function, it looks to me 
like when the tcp_sndbuf function gets called, its literally two assembly 
instructions that move a constant value of 0 into a register used for the 
length variable.


Im baffled.  Do I have something set up improperly with lwipopts.h?  What am I 
missing?



This email, and any document attached hereto, may contain confidential and/or 
privileged information.  If you are not the intended recipient (or have 
received this email in error) please notify the sender immediately and destroy 
this email.  Any unauthorized, direct or indirect, copying, disclosure, 
distribution or other use of the material or parts thereof is strictly 
forbidden.

_______________________________________________
lwip-users mailing list
address@hidden
https://lists.nongnu.org/mailman/listinfo/lwip-users

 
 
************************************************************************************
This footnote confirms that this email message has been scanned by PineApp 
Mail-SeCure for the presence of malicious code, vandals & computer viruses.
************************************************************************************






************************************************************************************
This footnote confirms that this email message has been scanned by
PineApp Mail-SeCure for the presence of malicious code, vandals & computer 
viruses.
************************************************************************************






reply via email to

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