mirror of
https://github.com/lxsang/ant-http
synced 2025-04-19 17:06:44 +02:00
fix read write pb
This commit is contained in:
parent
6a066c4d2d
commit
64554bd2f5
@ -170,19 +170,20 @@ int antd_send(void *src, const void* data, int len)
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
#endif
|
#endif
|
||||||
|
ptr = (char* )data;
|
||||||
writelen = len > BUFFLEN?BUFFLEN:len;
|
writelen = len > BUFFLEN?BUFFLEN:len;
|
||||||
written = 0;
|
written = 0;
|
||||||
while (writelen > 0)
|
while (writelen > 0)
|
||||||
{
|
{
|
||||||
count = send(source->sock, data, len, 0);
|
count = send(source->sock, ptr+written, writelen, 0);
|
||||||
if (count > 0)
|
if (count > 0)
|
||||||
{
|
{
|
||||||
written += count;
|
written += count;
|
||||||
writelen = (len - written) > BUFFLEN?BUFFLEN:(len-written);
|
writelen = (len - written) > BUFFLEN?BUFFLEN:(len-written);
|
||||||
}
|
}
|
||||||
else if(errno != EAGAIN && errno != EWOULDBLOCK)
|
else if(count == -1 && errno != EAGAIN && errno != EWOULDBLOCK)
|
||||||
{
|
{
|
||||||
return -1;
|
return written;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#ifdef USE_OPENSSL
|
#ifdef USE_OPENSSL
|
||||||
@ -197,10 +198,10 @@ int antd_send(void *src, const void* data, int len)
|
|||||||
int antd_recv(void *src, void* data, int len)
|
int antd_recv(void *src, void* data, int len)
|
||||||
{
|
{
|
||||||
if(!src) return -1;
|
if(!src) return -1;
|
||||||
int read;
|
int read=0;
|
||||||
char* ptr;
|
char* ptr = NULL;
|
||||||
int received;
|
int received=0;
|
||||||
int readlen;
|
int readlen=0;
|
||||||
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())
|
||||||
@ -317,20 +318,24 @@ int antd_recv(void *src, void* data, int len)
|
|||||||
read = 0;
|
read = 0;
|
||||||
while (readlen > 0 )//&& source->attempt < MAX_ATTEMPT
|
while (readlen > 0 )//&& source->attempt < MAX_ATTEMPT
|
||||||
{
|
{
|
||||||
received = recv(((int) source->sock), data, len, 0);
|
received = recv(((int) source->sock), ptr+read, readlen, 0);
|
||||||
|
LOG("Read : %c\n", *ptr);
|
||||||
if (received > 0)
|
if (received > 0)
|
||||||
{
|
{
|
||||||
read += received;
|
read += received;
|
||||||
readlen = (len - read) > BUFFLEN?BUFFLEN:(len-read);
|
readlen = (len - read) > BUFFLEN?BUFFLEN:(len-read);
|
||||||
|
LOG("Read len is %d\n", readlen);
|
||||||
}
|
}
|
||||||
else if(errno != EAGAIN && errno != EWOULDBLOCK)
|
else if(errno != EAGAIN && errno != EWOULDBLOCK)
|
||||||
{
|
{
|
||||||
return -1;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
//read = recv(((int) source->sock), data, len, 0);
|
||||||
#ifdef USE_OPENSSL
|
#ifdef USE_OPENSSL
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
//LOG("Received %d bytes\n", read);
|
||||||
/*if(ret == 0)
|
/*if(ret == 0)
|
||||||
{
|
{
|
||||||
antd_close(src);
|
antd_close(src);
|
||||||
@ -610,6 +615,7 @@ int read_buf(void* sock, char*buf,int size)
|
|||||||
n = antd_recv(sock, &c, 1);
|
n = antd_recv(sock, &c, 1);
|
||||||
if (n > 0)
|
if (n > 0)
|
||||||
{
|
{
|
||||||
|
//LOG("Data : %c\n", c);
|
||||||
buf[i] = c;
|
buf[i] = c;
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user