Revision of HTTPClient to fit the usage of NNN50_WIFI_API

Fork of HTTPClient by Donatien Garnier

Files at this revision

API Documentation at this revision

Comitter:
tsungta
Date:
Tue Jan 03 15:54:18 2017 +0000
Parent:
19:73fd8f9c4589
Commit message:
Change HTTPClient.cpp back to its origin due to the update of revision 11 of NNN50_WIFI_APIexcept CHUNK_SIZE is set to 1400

Changed in this revision

HTTPClient.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/HTTPClient.cpp	Tue Dec 13 08:43:12 2016 +0000
+++ b/HTTPClient.cpp	Tue Jan 03 15:54:18 2017 +0000
@@ -16,16 +16,14 @@
  * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  */
-#include "mbed.h"
-extern Serial uart;//temp used for NNN50
 
 //Debug is disabled by default
 #if 0
 //Enable debug
 #include <cstdio>
-#define DBG(x, ...) uart.printf("[HTTPClient : DBG]"x"\r\n", ##__VA_ARGS__); 
-#define WARN(x, ...) uart.printf("[HTTPClient : WARN]"x"\r\n", ##__VA_ARGS__); 
-#define ERR(x, ...) uart.printf("[HTTPClient : ERR]"x"\r\n", ##__VA_ARGS__); 
+#define DBG(x, ...) std::printf("[HTTPClient : DBG]"x"\r\n", ##__VA_ARGS__); 
+#define WARN(x, ...) std::printf("[HTTPClient : WARN]"x"\r\n", ##__VA_ARGS__); 
+#define ERR(x, ...) std::printf("[HTTPClient : ERR]"x"\r\n", ##__VA_ARGS__); 
 
 #else
 //Disable debug
@@ -42,7 +40,7 @@
 #define MIN(x,y) (((x)<(y))?(x):(y))
 #define MAX(x,y) (((x)>(y))?(x):(y))
 
-#define CHUNK_SIZE 1400//Tsungta, increase to max fit NNN50 WIFI_API
+#define CHUNK_SIZE 1400//Tsungta, increase to max to fit NNN50_WIFI_API
 
 #include <cstring>
 
@@ -574,7 +572,6 @@
 
 HTTPResult HTTPClient::recv(char* buf, size_t minLen, size_t maxLen, size_t* pReadLen) //0 on success, err code on failure
 {
-  minLen = maxLen;//Tsungta, change to fit NNN50 WIFI_API
   DBG("Trying to read between %d and %d bytes", minLen, maxLen);
   size_t readLen = 0;
       
@@ -585,27 +582,29 @@
   }
     
   int ret;
-//Tsungta, comment out following to fit NNN50 WIFI_API   
-//  while(readLen < maxLen)
-//  {
-//    if(readLen < minLen)
-//    {
+  while(readLen < maxLen)
+  {
+    if(readLen < minLen)
+    {
       DBG("Trying to read at most %d bytes [Blocking]", minLen - readLen);
       m_sock.set_blocking(false, m_timeout);
-      ret = m_sock.receive(buf + readLen, minLen - readLen);
-//    }
-//    else
-//    {
-//      DBG("Trying to read at most %d bytes [Not blocking]", maxLen - readLen);
-//      m_sock.set_blocking(false, 0);
-//      ret = m_sock.receive(buf + readLen, maxLen - readLen);
-//    }
+      ret = m_sock.receive_all(buf + readLen, minLen - readLen);
+    }
+    else
+    {
+      DBG("Trying to read at most %d bytes [Not blocking]", maxLen - readLen);
+      m_sock.set_blocking(false, 0);
+      ret = m_sock.receive(buf + readLen, maxLen - readLen);
+    }
     
     if( ret > 0)
     {
       readLen += ret;
     }
-
+    else if( ret == 0 )
+    {
+      break;
+    }
     else
     {
       if(!m_sock.is_connected())
@@ -614,16 +613,16 @@
         *pReadLen = readLen;
         return HTTP_CONN;
       }
-//      else
-//      {
-//        break;      
-//      }
-//    }
-//    
-//    if(!m_sock.is_connected())
-//    {
-//      break;
-//    }
+      else
+      {
+        break;      
+      }
+    }
+    
+    if(!m_sock.is_connected())
+    {
+      break;
+    }
   }
   DBG("Read %d bytes", readLen);
   *pReadLen = readLen;