兼容 asr1903
Change-Id: I3888f1adc86ea1fa73af4996d31f40223c0e5735
diff --git a/mbtk/libmbtk_lib/net/mbtk_sock2.c b/mbtk/libmbtk_lib/net/mbtk_sock2.c
index 45ae0b6..6d2c7fb 100755
--- a/mbtk/libmbtk_lib/net/mbtk_sock2.c
+++ b/mbtk/libmbtk_lib/net/mbtk_sock2.c
@@ -10,7 +10,9 @@
#include <sys/time.h>
#include <fcntl.h>
#include <netdb.h>
+#include <pthread.h>
+#ifdef MBTK_SSL_SUPPORT
#ifdef MBTK_POLARSSL_SUPPORT
#include <polarssl/net.h>
#include <polarssl/ssl.h>
@@ -34,6 +36,8 @@
#define DFL_CRT_FILE "/client.crt"
#define DFL_KEY_FILE "/client.key"
#endif
+#endif
+
#include <sys/ioctl.h>
#ifdef LOG_TAG
@@ -54,7 +58,7 @@
static int epoll_fd = -1;
static int pipe_fds[2];
static struct epoll_event epoll_events[20];
-static pthread_t sock_thread_id = -1;
+static pthread_t sock_thread_id;
static bool sock_thread_running = FALSE;
static mbtk_sock_s *mbtk_sock[MBTK_HANDLE_MAX_NUM] = {NULL};
@@ -290,6 +294,7 @@
return handle;
}
+#ifdef MBTK_SSL_SUPPORT
#ifdef MBTK_POLARSSL_SUPPORT
static int mbtk_polarssl_open(int fd ,bool ingnore_cert,mbtk_sock_inter_info_s* inter_info)
{
@@ -657,6 +662,7 @@
}
#endif
+#endif
extern mbtk_sock_session mbtk_sock_open(mbtk_sock_handle handle,mbtk_sock_info *info,
unsigned int timeout,
@@ -849,6 +855,7 @@
}
#endif
if(info->is_support_ssl){
+#ifdef MBTK_SSL_SUPPORT
#ifdef MBTK_POLARSSL_SUPPORT
if(mbtk_polarssl_open(mbtk_sock[handle]->inter_infos[index_free].fd,info->ingnore_cert,&mbtk_sock[handle]->inter_infos[index_free]) == -1){
LOGE("mbtk_openssl_init fail");
@@ -862,6 +869,8 @@
#endif
+
+#endif
}
*mbtk_errno = MBTK_SOCK_SUCCESS;
@@ -890,11 +899,15 @@
break;
}
}
+#ifdef MBTK_SSL_SUPPORT
#ifdef MBTK_POLARSSL_SUPPORT
return mbtk_polarssl_open(mbtk_sock[handle]->inter_infos[index_free].fd,ingnore_cert,&mbtk_sock[handle]->inter_infos[index_free]);
#else
return mbtk_openssl_open(mbtk_sock[handle]->inter_infos[index_free].fd,ingnore_cert,&mbtk_sock[handle]->inter_infos[index_free]);
#endif
+#else
+ return -1;
+#endif
}
extern int mbtk_ssl_close_func(mbtk_sock_handle handle ,bool ingnore_cert,mbtk_sock_session fd)
{
@@ -909,7 +922,7 @@
break;
}
}
-
+#ifdef MBTK_SSL_SUPPORT
#ifdef MBTK_POLARSSL_SUPPORT
if(mbtk_sock[handle]->inter_infos[index_free].ssl!=NULL)
printf("\nmbtk_sock[handle]->inter_infos[index_free].ssl not empty\n");
@@ -919,6 +932,10 @@
printf("\nmbtk_sock[handle]->inter_infos[index_free].ssl not empty\n");
return mbtk_openssl_close(&mbtk_sock[handle]->inter_infos[index_free]);
#endif
+
+#else
+ return -1;
+#endif
}
extern int mbtk_sock_write(mbtk_sock_handle handle,mbtk_sock_session session,
@@ -966,12 +983,17 @@
if(mbtk_sock[handle]->infos[index].type == MBTK_SOCK_TCP) {
while(count < buf_len){
if(mbtk_sock[handle]->infos[index].is_support_ssl) {
+#ifdef MBTK_SSL_SUPPORT
#ifdef MBTK_POLARSSL_SUPPORT
len = mbtk_polarssl_write(inter_info->ssl,(const unsigned char*)buffer + count,buf_len - count);
#else
len = mbtk_openssl_write(inter_info->ssl,(const unsigned char *)buffer + count,buf_len - count);
#endif
+
+#else
+ return -1;
+#endif
} else
len = write(inter_info->fd,(char*)buffer + count,buf_len - count);
if(len < 0){
@@ -1075,12 +1097,16 @@
while(count < buf_len){
try_count++;
if(mbtk_sock[handle]->infos[index].is_support_ssl) {
+#ifdef MBTK_SSL_SUPPORT
#ifdef MBTK_POLARSSL_SUPPORT
len = mbtk_polarssl_read(inter_info->ssl,(unsigned char*)buffer + count,buf_len - count);
#else
len = mbtk_openssl_read(inter_info->ssl,(unsigned char *)buffer + count,buf_len - count);
#endif
+#else
+ return -1;
+#endif
} else
len = read(inter_info->fd,(char*)buffer + count,buf_len - count);
if(len < 0){
@@ -1133,7 +1159,7 @@
while(TRUE){
try_count++;
seraddr_len = sizeof(struct sockaddr_in);
- len = recvfrom(inter_info->fd,buffer,buf_len,0,&seraddr,&seraddr_len);
+ len = recvfrom(inter_info->fd,buffer,buf_len,0,(struct sockaddr*)&seraddr,&seraddr_len);
if(len < 0){
if(errno == EWOULDBLOCK){// No data can read.
if(count > 0) // Read data
@@ -1251,11 +1277,15 @@
while(count < buf_len){
try_count++;
if(mbtk_sock[handle]->infos[index].is_support_ssl) {
+#ifdef MBTK_SSL_SUPPORT
#ifdef MBTK_POLARSSL_SUPPORT
len = mbtk_polarssl_read(inter_info->ssl,(unsigned char*)buffer + count,buf_len - count);
#else
len = mbtk_openssl_read(inter_info->ssl,(unsigned char*)buffer + count,buf_len - count);
#endif
+#else
+ return -1;
+#endif
} else
len = read(inter_info->fd,(char*)buffer + count,buf_len - count);
*read_line_count = len;
@@ -1325,7 +1355,7 @@
while(TRUE){
try_count++;
seraddr_len = sizeof(struct sockaddr_in);
- len = recvfrom(inter_info->fd,buffer,buf_len,0,&seraddr,&seraddr_len);
+ len = recvfrom(inter_info->fd,buffer,buf_len,0,(struct sockaddr*)&seraddr,&seraddr_len);
if(len < 0){
if(errno == EWOULDBLOCK){// No data can read.
if(count > 0) // Read data
@@ -1427,12 +1457,16 @@
memset(buffer,0x0,buf_len);
while(read_count < buf_len) {
if(mbtk_sock[handle]->infos[index].is_support_ssl) {
+#ifdef MBTK_SSL_SUPPORT
#ifdef MBTK_POLARSSL_SUPPORT
len = ssl_read(inter_info->ssl,(unsigned char*)buffer + read_count,buf_len - read_count);
#else
len = mbtk_openssl_read(inter_info->ssl,(unsigned char*)buffer + read_count,buf_len - read_count);
#endif
+#else
+ return -1;
+#endif
} else
len = read(inter_info->fd,(char*)buffer + read_count,buf_len - read_count);
@@ -1455,7 +1489,7 @@
memset(buffer,0x0,buf_len);
while(read_count < buf_len) {
- len = recvfrom(inter_info->fd,buffer + read_count,buf_len - read_count,0,&seraddr,&seraddr_len);
+ len = recvfrom(inter_info->fd,buffer + read_count,buf_len - read_count,0,(struct sockaddr*)&seraddr,&seraddr_len);
if(len > 0) {
read_count += len;
@@ -1518,12 +1552,16 @@
TCP_READ_AGAIN:
memset(buffer,0x0,buf_len);
if(mbtk_sock[handle]->infos[index].is_support_ssl) {
+#ifdef MBTK_SSL_SUPPORT
#ifdef MBTK_POLARSSL_SUPPORT
len = ssl_read(inter_info->ssl,(unsigned char*)buffer,buf_len);
#else
len = mbtk_openssl_read(inter_info->ssl,(unsigned char*)buffer,buf_len);
#endif
+#else
+ return -1;
+#endif
} else
len = read(inter_info->fd,(char*)buffer,buf_len);
if(len < 0){
@@ -1543,7 +1581,7 @@
UDP_READ_AGAIN:
memset(buffer,0x0,buf_len);
seraddr_len = sizeof(struct sockaddr_in);
- len = recvfrom(inter_info->fd,buffer,buf_len,0,&seraddr,&seraddr_len);
+ len = recvfrom(inter_info->fd,buffer,buf_len,0,(struct sockaddr*)&seraddr,&seraddr_len);
if(len < 0){
if(errno == EWOULDBLOCK){
usleep(100000);
@@ -1617,6 +1655,7 @@
}
if(mbtk_sock[handle]->infos[index].is_support_ssl){
+#ifdef MBTK_SSL_SUPPORT
#ifdef MBTK_POLARSSL_SUPPORT
if(mbtk_polarssl_close(inter_info)== -1)
{
@@ -1631,6 +1670,7 @@
}
#endif
+#endif
}
*mbtk_errno = MBTK_SOCK_SUCCESS;