fix read write bug wo ssl

This commit is contained in:
lxsang 2018-10-27 12:58:12 +02:00
parent 80069bf42e
commit 6a066c4d2d

View File

@ -73,14 +73,16 @@ int antd_send(void *src, const void* data, int len)
if(!src || !data) return -1; if(!src || !data) return -1;
int written; int written;
antd_client_t * source = (antd_client_t *) src; antd_client_t * source = (antd_client_t *) src;
char* ptr;
int writelen;
int count;
#ifdef USE_OPENSSL #ifdef USE_OPENSSL
if(usessl()) if(usessl())
{ {
//LOG("SSL WRITE\n"); //LOG("SSL WRITE\n");
//ret = SSL_write((SSL*) source->ssl, data, len); //ret = SSL_write((SSL*) source->ssl, data, len);
int count; ptr = (char* )data;
char* ptr = (char* )data; writelen = len > BUFFLEN?BUFFLEN:len;
int writelen = len > BUFFLEN?BUFFLEN:len;
written = 0; written = 0;
fd_set fds; fd_set fds;
struct timeval timeout; struct timeval timeout;
@ -168,7 +170,21 @@ int antd_send(void *src, const void* data, int len)
else else
{ {
#endif #endif
written = send(source->sock, data, len, 0); writelen = len > BUFFLEN?BUFFLEN:len;
written = 0;
while (writelen > 0)
{
count = send(source->sock, data, len, 0);
if (count > 0)
{
written += count;
writelen = (len - written) > BUFFLEN?BUFFLEN:(len-written);
}
else if(errno != EAGAIN && errno != EWOULDBLOCK)
{
return -1;
}
}
#ifdef USE_OPENSSL #ifdef USE_OPENSSL
} }
#endif #endif
@ -182,13 +198,15 @@ int antd_recv(void *src, void* data, int len)
{ {
if(!src) return -1; if(!src) return -1;
int read; int read;
char* ptr;
int received;
int readlen;
antd_client_t * source = (antd_client_t *) src; antd_client_t * source = (antd_client_t *) src;
#ifdef USE_OPENSSL #ifdef USE_OPENSSL
if(usessl()) if(usessl())
{ {
int received; ptr = (char* )data;
char* ptr = (char* )data; readlen = len > BUFFLEN?BUFFLEN:len;
int readlen = len > BUFFLEN?BUFFLEN:len;
read = 0; read = 0;
fd_set fds; fd_set fds;
struct timeval timeout; struct timeval timeout;
@ -294,7 +312,22 @@ int antd_recv(void *src, void* data, int len)
else else
{ {
#endif #endif
read = recv(((int) source->sock), data, len, 0); ptr = (char* )data;
readlen = len > BUFFLEN?BUFFLEN:len;
read = 0;
while (readlen > 0 )//&& source->attempt < MAX_ATTEMPT
{
received = recv(((int) source->sock), data, len, 0);
if (received > 0)
{
read += received;
readlen = (len - read) > BUFFLEN?BUFFLEN:(len-read);
}
else if(errno != EAGAIN && errno != EWOULDBLOCK)
{
return -1;
}
}
#ifdef USE_OPENSSL #ifdef USE_OPENSSL
} }
#endif #endif