-
Notifications
You must be signed in to change notification settings - Fork 21
/
functions.c
47 lines (43 loc) · 951 Bytes
/
functions.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#include <sys/socket.h>
#include <netinet/in.h>
#include <stdint.h>
int full_send(int fd,void *buf,int size)
{
int ret,total=0;
while(size){
ret=send(fd, buf, size,0);
total+=ret;
if(ret<0) return ret;
size=size-ret;
buf+=ret;
}
return total;
}
int full_recv(int fd,void *buf,int size)
{
int ret,total=0;
while(size){
ret=recv(fd, buf, size,0);
total+=ret;
if(ret<=0) return ret;
size=size-ret;
buf+=ret;
}
return total;
}
int wsend(int fd,void *buf,int size)
{
int ret;
ret = full_send(fd, &size, sizeof(int32_t));
if(ret<0) return ret;
ret = full_send(fd,buf,size);
return ret;
}
int wrecv(int fd,void *buf)
{
int ret,size;
ret=full_recv(fd, &size, sizeof(int32_t));
if(ret<=0) return ret;
ret = full_recv(fd,buf,size);
return ret;
}