-
Notifications
You must be signed in to change notification settings - Fork 0
/
smstcpstream.h
executable file
·64 lines (57 loc) · 1.29 KB
/
smstcpstream.h
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#ifndef SMS_09AE022D_EC13_4b0f_9A93_06A65268A4DB
#define SMS_51AD2DAD_B486_4391_A641_84C4719FF7DE
#include <errno.h>
namespace SMS {
class CSMSTcpStream:public tcpstream{
public:
ssize_t write(void* buf, ssize_t bufLen){
sigset_t sigmask,oldmask;
int i=0;
int sended=0;
sigemptyset(&sigmask);
sigaddset(&sigmask,SIGUSR1);
sigaddset(&sigmask,SIGUSR2);
sigprocmask(SIG_BLOCK,&sigmask,&oldmask);
while (i=tcpstream::writeData(((char*)buf)+sended,bufLen-sended)) {
if ( i<0) {
if (getErrorNumber()==errTimeout)
return TIMEOUT;
if (errno==EINTR)
continue;
else {
sigprocmask(SIG_SETMASK,&oldmask,NULL);
return ERROR;
}
}
sended+=i;
if (sended>=bufLen)
break;
}
sigprocmask(SIG_SETMASK,&oldmask,NULL);
return sended;
}
ssize_t read(void* buf, ssize_t bufLen, timeout_t timeout=0){
if (bufLen==0)
return 0;
int readed;
int i;
readed=0;
while (i=tcpstream::readData(((char*)buf)+readed,bufLen-readed,0,timeout)) {
if (i<0){
if (getErrorNumber()==errTimeout)
return TIMEOUT;
if (errno==EINTR) {
continue;
} else {
return ERROR;
}
} else
readed+=i;
if (readed>=bufLen)
break;
}
return readed;
}
};
}
#endif