lwip-users
[Top][All Lists]
Advanced

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

Re: [lwip-users] Handling sudden disappearance of network i/f


From: Janusz U.
Subject: Re: [lwip-users] Handling sudden disappearance of network i/f
Date: Tue, 26 Sep 2006 11:33:37 +0200


I think you misunderstand how TCP connections are closed.

you are right - i am still learning.

 A FIN does
not mean the connection is closed.  It just means that whoever sent it
doesn't want to send any more data.  The connection is still open in the
other direction, and it is perfectly valid (and quite normal) for one
side to send a FIN, but the other end to still send data.  A connection
is not closed until both applications close it.

yes, but if FIN is sent by serwer lwIP should return from netconn_recv and inform me about. Ather I can close the socket...

I've just had a look at how FINs are processed in the case of the
netconn API.  The core lwIP will call the raw API recv callback with a
NULL buffer.  This will post NULL to the netconn API's recv mbox.  The
netconn_recv() function, when it gets NULL from the mbox, returns a
length of 0.  This is standard semantics for "there are no more data to
read".

oh, thanks a lot! I thought about but I hoped recv return to me null buffer:
if ((getPPPstate() == pppCONNECTED) &&
 (inet_aton(userCfg.srv.name, &srv_ip_addr)) &&
 (userCfg.srv.port != 0)) {
 pxSRVconn = netconn_new(NETCONN_TCP);          // init conn
 if (pxSRVconn != NULL)
  if (pxSRVconn->pcb.tcp != NULL) {
pxSRVconn->pcb.tcp->keepalive = 120000; // set keepalive time in ms pxSRVconn->pcb.tcp->so_options |= SO_KEEPALIVE; // turn on keep-alive
  }
 setSRVstate(srvCONNECTING);
 kprintf("SRV connecting\n");
 // start client-server connection
if (netconn_connect(pxSRVconn, &srv_ip_addr, userCfg.srv.port) == ERR_OK) { // open socket
  setSRVstate(srvCONNECTED);
  kprintf("SRV connected !!!!!!!!!!!!!!!!!!!!!!!\n");
  // data receiving loop
  while ((pxRxBuffer = netconn_recv(pxSRVconn)) != NULL) {
   kprintf("SRV recv\n");
   // get all data and send it into BT
   do {
    netbuf_data(pxRxBuffer, (void *) &pcRxString, &usLength);
    // debug
    /*
    kprintf("\n-START-\n");
    //for (i=0; i<usLength; i++) kprintf("%02x", pcRxString[i]);
    for (i=0; i<usLength; i++) kprintf("%c", pcRxString[i]);
    kprintf("\n-END-\n");
    */
    if (getBTstate() == btCONNECTED)
     comm_write(BT_DEV, pcRxString, usLength);
   } while (netbuf_next(pxRxBuffer) >= 0);
   netbuf_delete(pxRxBuffer);
  }
  netconn_close(pxSRVconn);            // close socket
 }
 setSRVstate(srvDISCONNECTED);
 kprintf("SRV disconnected\n");
 netconn_delete(pxSRVconn);             // done conn
} else vTaskDelay(50);               // unblock the task

should I check buffer len for the zero?

kind regards
Janusz





reply via email to

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