client.c for LwIP native socket, v0.2

This commit is contained in:
Takashi Kojo
2014-02-20 15:38:35 +09:00
parent cca013b6d9
commit 5d5a8dbabd
4 changed files with 37 additions and 25 deletions

View File

@@ -37,7 +37,7 @@
#else #else
#include <string.h> #include <string.h>
#include <sys/types.h> #include <sys/types.h>
#ifndef CYASSL_LEANPSK #if !defined(CYASSL_LEANPSK) && !defined(HAVE_LWIP_NATIVE)
#include <unistd.h> #include <unistd.h>
#include <netdb.h> #include <netdb.h>
#include <netinet/in.h> #include <netinet/in.h>
@@ -59,6 +59,14 @@
#define SNPRINTF snprintf #define SNPRINTF snprintf
#endif /* USE_WINDOWS_API */ #endif /* USE_WINDOWS_API */
#if defined(HAVE_LWIP_NATIVE)
#include <string.h>
#include "lwip/tcp.h"
#include "lwip/sockets.h"
#include "lwip/inet.h"
#include "lwip/ip_addr.h"
#endif
#ifdef HAVE_CAVIUM #ifdef HAVE_CAVIUM
#include "cavium_sysdep.h" #include "cavium_sysdep.h"
#include "cavium_common.h" #include "cavium_common.h"
@@ -81,7 +89,7 @@
/* HPUX doesn't use socklent_t for third parameter to accept, unless /* HPUX doesn't use socklent_t for third parameter to accept, unless
_XOPEN_SOURCE_EXTENDED is defined */ _XOPEN_SOURCE_EXTENDED is defined */
#if !defined(__hpux__) && !defined(CYASSL_MDK_ARM) #if !defined(__hpux__) && !defined(CYASSL_MDK_ARM) && !defined(CYASSL_IAR_ARM)
typedef socklen_t* ACCEPT_THIRD_T; typedef socklen_t* ACCEPT_THIRD_T;
#else #else
#if defined _XOPEN_SOURCE_EXTENDED #if defined _XOPEN_SOURCE_EXTENDED

View File

@@ -658,15 +658,14 @@ CASE(CLIENT_SSL_CONN):
/* see note at top of README */ /* see note at top of README */
int err = CyaSSL_get_error(ssl, 0); int err = CyaSSL_get_error(ssl, 0);
#if defined(HAVE_LWIP_NATIVE) #if defined(HAVE_LWIP_NATIVE)
if(err == SSL_ERROR_WANT_READ) if(err == SSL_ERROR_WANT_READ)
BREAK ; BREAK ;
#endif #endif
char buffer[CYASSL_MAX_ERROR_SZ]; char buffer[CYASSL_MAX_ERROR_SZ];
printf("err = %d, %s\n", err, printf("err = %d, %s\n", err,
CyaSSL_ERR_error_string(err, buffer)); CyaSSL_ERR_error_string(err, buffer));
err_sys("SSL_connect failed"); err_sys("SSL_connect failed");
/* if you're getting an error here */ /* if you're getting an error here */
BREAK ;
} }
#else #else
timeout.tv_sec = 2; timeout.tv_sec = 2;

View File

@@ -30,27 +30,33 @@ static enum Client_Stat {
CLIENT_TCP_CONN , CLIENT_TCP_CONN ,
CLIENT_SSL_CONN , CLIENT_SSL_CONN ,
CLIENT_SSL_READ , CLIENT_SSL_READ ,
} client_stat ; } client_stat ;
int tcp_connect_nb(struct tcp_pcb **pcb, const char* ip, word16 port, int udp);
void tcp_CloseSocket_nb(struct tcp_pcb *pcb) ;
#define tcp_connect(s, h, p, f) tcp_connect_nb(s, h, p, f)
#define CloseSocket(s) tcp_CloseSocket_nb(s)
#define CyaSSL_set_fd(ssl, s)
int tcp_connect_nb(struct tcp_pcb **pcb, const char* ip, word16 port, int udp);
void tcp_CloseSocket_nb(struct tcp_pcb *pcb) ;
#define tcp_connect(s, h, p, f) tcp_connect_nb(s, h, p, f)
#define CloseSocket(s) tcp_CloseSocket_nb(s)
#define CyaSSL_set_fd(ssl, s)
#endif #endif
#if defined(HAVE_LWIP_NATIVE) #if defined(HAVE_LWIP_NATIVE)
#define SWITCH_STAT switch(client_stat) { case CLIENT_BEGIN:
#define SWITCH_STAT switch(client_stat) { case CLIENT_BEGIN:
#define CASE(stat) client_stat = stat ; case stat #define CASE(stat) client_stat = stat ; case stat
#define BREAK break #define BREAK break
#define END_SWITCH } #define END_SWITCH }
#define STATIC_NB static #define STATIC_NB static
#else
#else
#define SWITCH_STAT #define SWITCH_STAT
#define CASE(value) #define CASE(value)
#define BREAK #define BREAK
#define END_SWITHCH #define END_SWITHCH
#define STATIC_NB #define STATIC_NB
#endif #endif

View File

@@ -1096,6 +1096,7 @@ static int CyaSSL_GetDataFromPbuf(char *buff, CYASSL *ssl, int size)
int skipLen = 0 ; int skipLen = 0 ;
p = ssl->lwipCtx.pbuf ; p = ssl->lwipCtx.pbuf ;
#if defined(DEBUG_PBUF) #if defined(DEBUG_PBUF)
printf("WantRead Size=%d\n", size) ; printf("WantRead Size=%d\n", size) ;
do { do {
@@ -1176,14 +1177,8 @@ err_t CyaSSL_LwIP_recv_cb(void *cb, struct tcp_pcb *pcb, struct pbuf *p, s8_t er
ssl->lwipCtx.pbuf = p ; ssl->lwipCtx.pbuf = p ;
} }
ssl->lwipCtx.pulled = 0 ; ssl->lwipCtx.pulled = 0 ;
ssl->lwipCtx.wait = 10000 ;
if(((ssl->options.connectState != CONNECT_BEGIN) && if(ssl->lwipCtx.recv)
(ssl->options.connectState != SECOND_REPLY_DONE))||
((ssl->options.acceptState != ACCEPT_BEGIN) &&
(ssl->options.connectState != ACCEPT_THIRD_REPLY_DONE)))
{
ssl->lwipCtx.wait = 100000 ;
} else if(ssl->lwipCtx.recv)
return ssl->lwipCtx.recv(ssl->lwipCtx.arg, pcb, p, err) ; return ssl->lwipCtx.recv(ssl->lwipCtx.arg, pcb, p, err) ;
/* user callback */ /* user callback */
return ERR_OK; return ERR_OK;
@@ -1206,6 +1201,10 @@ int CyaSSL_LwIP_Receive(CYASSL* ssl, char *buf, int sz, void *cb)
DBG_PRINTF_CB("CyaSSL_LwIP_Receive: ssl_nb = %x\n", ssl) ; DBG_PRINTF_CB("CyaSSL_LwIP_Receive: ssl_nb = %x\n", ssl) ;
if(ssl->lwipCtx.pbuf) { if(ssl->lwipCtx.pbuf) {
if(ssl->lwipCtx.wait){
ssl->lwipCtx.wait-- ;
return CYASSL_CBIO_ERR_WANT_READ ;
}
DBG_PRINTF_CB("Received Len=%d, Want Len= %d\n", ssl->lwipCtx.pbuf->tot_len, sz) ; DBG_PRINTF_CB("Received Len=%d, Want Len= %d\n", ssl->lwipCtx.pbuf->tot_len, sz) ;
ret = CyaSSL_GetDataFromPbuf(buf, ssl, sz) ; ret = CyaSSL_GetDataFromPbuf(buf, ssl, sz) ;
if(ret == 0) if(ret == 0)
@@ -1221,7 +1220,7 @@ int CyaSSL_LwIP_Send(CYASSL* ssl, char *buf, int sz, void *cb)
{ {
err_t ret ; err_t ret ;
DBG_PRINTF_CB("CyaSSL_LwIP_Send: ssl = %x\n", ssl) ; DBG_PRINTF_CB("CyaSSL_LwIP_Send: ssl = %x, pcb = %x\n", ssl, ssl->lwipCtx.pcb) ;
DBG_PRINTF_CB("Send buf[0,1,2,3]=%x,%x,%x,%x, sz=%d\n", buf[0], buf[1], buf[2], buf[3], sz) ; DBG_PRINTF_CB("Send buf[0,1,2,3]=%x,%x,%x,%x, sz=%d\n", buf[0], buf[1], buf[2], buf[3], sz) ;
ret = tcp_write(ssl->lwipCtx.pcb, buf, sz, TCP_WRITE_FLAG_COPY) ; ret = tcp_write(ssl->lwipCtx.pcb, buf, sz, TCP_WRITE_FLAG_COPY) ;
if(ret == ERR_OK) if(ret == ERR_OK)