Eliminated unessecary logic when defining chunk size
Dependents: ECE_4180_Lab_4 IoT_Security_WIFI ESP8266_HTTP_HelloWorld ESP8266_ws_hw ... more
Fork of HTTPClient-SSL by
Diff: HTTPClient.cpp
- Revision:
- 50:a18a06b000f3
- Parent:
- 49:a564fc323921
--- a/HTTPClient.cpp Fri Jun 05 22:10:21 2015 +0000 +++ b/HTTPClient.cpp Tue Jun 09 16:26:02 2015 +0000 @@ -52,9 +52,8 @@ #include <../CyaSSL/cyassl/ssl.h> #include "HTTPClient.h" -#include "TCPSocketConnection.h" -static TCPSocketConnection m_sock; + // ************ should be a better way to adjust for platform limitations @@ -85,34 +84,7 @@ static char send_buf[SEND_BUF_SIZE] ; static char *send_buf_p = NULL; - -static int SocketReceive(CYASSL* ssl, char *buf, int sz, void *ctx) -{ - int n ; - int i ; -#define RECV_RETRY 3 - - for(i=0; i<RECV_RETRY; i++) { - n = m_sock.receive(buf, sz) ; - if(n >= 0)return n ; - Thread::wait(200) ; - } - ERR("SocketReceive:%d/%d\n", n, sz) ; - return n ; -} - -static int SocketSend(CYASSL* ssl, char *buf, int sz, void *ctx) -{ - int n ; - - Thread::wait(100) ; - n = m_sock.send(buf, sz); - if(n > 0) { - Thread::wait(300) ; - return n ; - } else ERR("SocketSend:%d/%d\n", n, sz); - return n ; -} +static TCPSocketConnection* m_sock_p = NULL; static void base64enc(char *out, const char *in) { const char code[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=" ; @@ -133,13 +105,38 @@ } out[i] = '\0' ; } +int SocketReceive(CYASSL* ssl, char *buf, int sz, void *ctx) +{ + int n ; + int i ; +#define RECV_RETRY 3 + + for(i=0; i<RECV_RETRY; i++) { + n = m_sock_p->receive(buf, sz) ; + if(n >= 0)return n ; + Thread::wait(200) ; + } + ERR("SocketReceive:%d/%d\n", n, sz) ; + return n ; +} +int SocketSend(CYASSL* ssl, char *buf, int sz, void *ctx) +{ + int n ; + + Thread::wait(100) ; + n = m_sock_p->send(buf, sz); + if(n > 0) { + Thread::wait(300) ; + return n ; + } else ERR("SocketSend:%d/%d\n", n, sz); + return n ; +} HTTPClient::HTTPClient() : m_basicAuthUser(NULL), m_basicAuthPassword(NULL), m_httpResponseCode(0), m_oauthToken(NULL) { // To DEBUG the underlying SSL - uncomment this... //CyaSSL_Debugging_ON(); - ctx = 0 ; ssl = 0 ; SSLver = 3 ; @@ -150,6 +147,7 @@ redirect_url = NULL ; redirect = 0 ; header = NULL ; + m_sock_p = &m_sock; } HTTPClient::~HTTPClient() @@ -157,6 +155,7 @@ } + HTTPResult HTTPClient::oauthToken(const char *token) { // OAUTH2 Authentication // reset if called if (m_oauthToken != NULL) free((void *)m_oauthToken);