EthernetNetIf Compatibility.
Dependents: XBeeWiFi_SPI_example
Fork of NetServicesSource by
Diff: if/lwip/lwipNetTcpSocket.cpp
- Revision:
- 5:dd63a1e02b1b
- Parent:
- 2:a4f97773c90f
--- a/if/lwip/lwipNetTcpSocket.cpp Fri Jul 09 14:46:47 2010 +0000 +++ b/if/lwip/lwipNetTcpSocket.cpp Tue Jul 27 15:59:42 2010 +0000 @@ -33,9 +33,12 @@ LwipNetTcpSocket::LwipNetTcpSocket(tcp_pcb* pPcb /*= NULL*/) : NetTcpSocket(), m_pPcb(pPcb), m_lpInNetTcpSocket(), //Passes a pcb if already created (by an accept req for instance), in that case transfers ownership m_pReadPbuf(NULL) { - DBG("\r\nNew NetTcpSocket %p\r\n", (void*)this); + DBG("New NetTcpSocket %p\n", (void*)this); if(!m_pPcb) + { m_pPcb = tcp_new(); + DBG("Creating new PCB %p\n", m_pPcb); + } if(m_pPcb) { //Setup callbacks @@ -46,7 +49,7 @@ tcp_err( (tcp_pcb*) m_pPcb, LwipNetTcpSocket::sErrCb ); //Connected callback is defined in connect() //Accept callback is defined in listen() - DBG("\r\nNetTcpSocket created.\r\n"); + DBG("NetTcpSocket created.\n"); } } @@ -104,7 +107,7 @@ ip_addr_t ip = host.getIp().getStruct(); err_t err = tcp_connect( (tcp_pcb*) m_pPcb, &ip, host.getPort(), LwipNetTcpSocket::sConnectedCb ); - if(!err) + if(err) return NETTCPSOCKET_MEM; return NETTCPSOCKET_OK; @@ -156,7 +159,7 @@ /* if(*ppNewNetTcpSocket == NULL) { - DBG("\r\nNot enough mem, socket dropped in LwipNetTcpSocket::accept.\r\n"); + DBG("Not enough mem, socket dropped in LwipNetTcpSocket::accept.\n"); tcp_abort(pInPcb); }*/ @@ -253,7 +256,7 @@ NetTcpSocketErr LwipNetTcpSocket::close() { - //DBG("\r\nLwipNetTcpSocket::close() : Closing...\r\n"); + //DBG("LwipNetTcpSocket::close() : Closing...\n"); if(m_closed) return NETTCPSOCKET_OK; //Already being closed @@ -267,13 +270,13 @@ if( !!tcp_close( (tcp_pcb*) m_pPcb) ) { - DBG("\r\nLwipNetTcpSocket::close() could not close properly, abort.\r\n"); + DBG("LwipNetTcpSocket::close() could not close properly, abort.\n"); tcp_abort( (tcp_pcb*) m_pPcb); m_pPcb = NULL; return NETTCPSOCKET_MEM; } - DBG("\r\nLwipNetTcpSocket::close() : connection closed successfully.\r\n"); + DBG("LwipNetTcpSocket::close() : connection closed successfully.\n"); m_pPcb = NULL; return NETTCPSOCKET_OK; @@ -291,7 +294,7 @@ { if(err) { - DBG("\r\nError %d in LwipNetTcpSocket::acceptCb.\r\n", err); + DBG("Error %d in LwipNetTcpSocket::acceptCb.\n", err); return err; } //FIXME: MEM Errs @@ -300,7 +303,7 @@ if(pNewNetTcpSocket == NULL) { - DBG("\r\nNot enough mem, socket dropped in LwipNetTcpSocket::acceptCb.\r\n"); + DBG("Not enough mem, socket dropped in LwipNetTcpSocket::acceptCb.\n"); tcp_abort(newpcb); return ERR_ABRT; } @@ -322,7 +325,7 @@ void LwipNetTcpSocket::errCb(err_t err) { - DBG("\r\nNetTcpSocket %p - Error %d in LwipNetTcpSocket::errCb.\r\n", (void*)this, err); + DBG("NetTcpSocket %p - Error %d in LwipNetTcpSocket::errCb.\n", (void*)this, err); //WARN: At this point, m_pPcb has been freed by lwIP m_pPcb = NULL; //These errors are fatal, discard all events queued before so that the errors are handled first @@ -337,7 +340,7 @@ err_t LwipNetTcpSocket::sentCb(tcp_pcb* tpcb, u16_t len) { -// DBG("\r\n%d bytes ACKed by host.\r\n", len); +// DBG("%d bytes ACKed by host.\n", len); queueEvent(NETTCPSOCKET_WRITEABLE); return ERR_OK; } @@ -345,7 +348,7 @@ err_t LwipNetTcpSocket::recvCb(tcp_pcb* tpcb, pbuf *p, err_t err) { //Store pbuf ptr - // DBG("\r\nReceive CB with err = %d & len = %d.\r\n", err, p->tot_len); + // DBG("Receive CB with err = %d & len = %d.\n", err, p->tot_len); // tcp_recved( (tcp_pcb*) m_pPcb, p->tot_len); //Acknowledge the reception if(err) @@ -355,7 +358,7 @@ } else if(!p) { - DBG("\r\nNetTcpSocket %p - Connection closed by remote host (LwipNetTcpSocket::recvCb).\r\n", (void*)this); + DBG("NetTcpSocket %p - Connection closed by remote host (LwipNetTcpSocket::recvCb).\n", (void*)this); //Buf is NULL, that means that the connection has been closed by remote host //FIX: 27/05/2010: We do not want to deallocate the socket while some data might still be readable @@ -398,7 +401,7 @@ if( m_pReadPbuf ) { - DBG("\r\nDeallocating unread data.\r\n"); + DBG("Deallocating unread data.\n"); pbuf_free((pbuf*)m_pReadPbuf); //Free all unread data m_pReadPbuf = NULL; recv(NULL,0); //Update recv ptr position @@ -423,7 +426,7 @@ { if( !arg ) { - DBG("\r\nNetTcpSocket - Error %d in LwipNetTcpSocket::sErrCb.\r\n", err); + DBG("NetTcpSocket - Error %d in LwipNetTcpSocket::sErrCb.\n", err); return; //The socket has been destroyed, discard error } LwipNetTcpSocket* pMe = (LwipNetTcpSocket*) arg;