mirror of
https://github.com/wolfSSL/wolfssl.git
synced 2025-08-03 04:34:41 +02:00
client.c for LwIP native socket, v0.2
This commit is contained in:
@@ -37,7 +37,7 @@
|
||||
#else
|
||||
#include <string.h>
|
||||
#include <sys/types.h>
|
||||
#ifndef CYASSL_LEANPSK
|
||||
#if !defined(CYASSL_LEANPSK) && !defined(HAVE_LWIP_NATIVE)
|
||||
#include <unistd.h>
|
||||
#include <netdb.h>
|
||||
#include <netinet/in.h>
|
||||
@@ -59,6 +59,14 @@
|
||||
#define SNPRINTF snprintf
|
||||
#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
|
||||
#include "cavium_sysdep.h"
|
||||
#include "cavium_common.h"
|
||||
@@ -81,7 +89,7 @@
|
||||
|
||||
/* HPUX doesn't use socklent_t for third parameter to accept, unless
|
||||
_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;
|
||||
#else
|
||||
#if defined _XOPEN_SOURCE_EXTENDED
|
||||
|
@@ -658,15 +658,14 @@ CASE(CLIENT_SSL_CONN):
|
||||
/* see note at top of README */
|
||||
int err = CyaSSL_get_error(ssl, 0);
|
||||
#if defined(HAVE_LWIP_NATIVE)
|
||||
if(err == SSL_ERROR_WANT_READ)
|
||||
BREAK ;
|
||||
if(err == SSL_ERROR_WANT_READ)
|
||||
BREAK ;
|
||||
#endif
|
||||
char buffer[CYASSL_MAX_ERROR_SZ];
|
||||
printf("err = %d, %s\n", err,
|
||||
CyaSSL_ERR_error_string(err, buffer));
|
||||
err_sys("SSL_connect failed");
|
||||
/* if you're getting an error here */
|
||||
BREAK ;
|
||||
}
|
||||
#else
|
||||
timeout.tv_sec = 2;
|
||||
|
@@ -30,27 +30,33 @@ static enum Client_Stat {
|
||||
CLIENT_TCP_CONN ,
|
||||
CLIENT_SSL_CONN ,
|
||||
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
|
||||
|
||||
|
||||
#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 BREAK break
|
||||
#define END_SWITCH }
|
||||
#define STATIC_NB static
|
||||
#else
|
||||
#define BREAK break
|
||||
#define END_SWITCH }
|
||||
#define STATIC_NB static
|
||||
|
||||
#else
|
||||
|
||||
#define SWITCH_STAT
|
||||
#define CASE(value)
|
||||
#define BREAK
|
||||
#define END_SWITHCH
|
||||
#define STATIC_NB
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
17
src/io.c
17
src/io.c
@@ -1096,6 +1096,7 @@ static int CyaSSL_GetDataFromPbuf(char *buff, CYASSL *ssl, int size)
|
||||
int skipLen = 0 ;
|
||||
|
||||
p = ssl->lwipCtx.pbuf ;
|
||||
|
||||
#if defined(DEBUG_PBUF)
|
||||
printf("WantRead Size=%d\n", size) ;
|
||||
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.pulled = 0 ;
|
||||
|
||||
if(((ssl->options.connectState != CONNECT_BEGIN) &&
|
||||
(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)
|
||||
ssl->lwipCtx.wait = 10000 ;
|
||||
if(ssl->lwipCtx.recv)
|
||||
return ssl->lwipCtx.recv(ssl->lwipCtx.arg, pcb, p, err) ;
|
||||
/* user callback */
|
||||
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) ;
|
||||
|
||||
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) ;
|
||||
ret = CyaSSL_GetDataFromPbuf(buf, ssl, sz) ;
|
||||
if(ret == 0)
|
||||
@@ -1221,7 +1220,7 @@ int CyaSSL_LwIP_Send(CYASSL* ssl, char *buf, int sz, void *cb)
|
||||
{
|
||||
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) ;
|
||||
ret = tcp_write(ssl->lwipCtx.pcb, buf, sz, TCP_WRITE_FLAG_COPY) ;
|
||||
if(ret == ERR_OK)
|
||||
|
Reference in New Issue
Block a user