ReactOS
0.4.16-dev-136-g52192f1
SWait.c
Go to the documentation of this file.
1
#include "
syshdrs.h
"
2
3
/*
4
* Return zero if the operation timed-out or erred-out, otherwise non-zero.
5
*/
6
int
7
SWaitUntilReadyForReading
(
const
int
sfd,
const
int
tlen)
8
{
9
fd_set
ss
, ss2;
10
struct
timeval
tv;
11
int
result
;
12
int
tleft;
13
time_t
now
, done;
14
15
if
(sfd < 0) {
16
errno
=
EBADF
;
17
return
(0);
18
}
19
20
time
(&
now
);
21
done =
now
+ tlen;
22
tleft = tlen;
23
24
forever
{
25
FD_ZERO
(&
ss
);
26
FD_SET
(sfd, &
ss
);
27
ss2 =
ss
;
28
tv.
tv_sec
= tleft;
29
tv.
tv_usec
= 0;
30
result
=
select
(sfd + 1,
SELECT_TYPE_ARG234
&
ss
,
NULL
,
SELECT_TYPE_ARG234
&ss2, &tv);
31
if
(
result
== 1) {
32
/* ready */
33
return
(1);
34
}
else
if
(
result
< 0) {
35
if
(
errno
!=
EINTR
) {
36
/* error */
37
return
(0);
38
}
39
/* try again */
40
time
(&
now
);
41
if
(
now
> done) {
42
/* timed-out */
43
errno
=
ETIMEDOUT
;
44
return
(0);
45
}
46
tleft = (
int
) (done -
now
);
47
}
else
{
48
/* timed-out */
49
errno
=
ETIMEDOUT
;
50
return
(0);
51
}
52
}
53
}
/* SWaitUntilReadyForReading */
54
55
56
57
58
/*
59
* Return zero if the operation timed-out or erred-out, otherwise non-zero.
60
*/
61
int
62
SWaitUntilReadyForWriting
(
const
int
sfd,
const
int
tlen)
63
{
64
fd_set
ss
, ss2;
65
struct
timeval
tv;
66
int
result
;
67
int
tleft;
68
time_t
now
, done;
69
70
if
(sfd < 0) {
71
errno
=
EBADF
;
72
return
(0);
73
}
74
75
time
(&
now
);
76
done =
now
+ tlen;
77
tleft = tlen;
78
79
forever
{
80
FD_ZERO
(&
ss
);
81
FD_SET
(sfd, &
ss
);
82
ss2 =
ss
;
83
tv.
tv_sec
= tleft;
84
tv.
tv_usec
= 0;
85
result
=
select
(sfd + 1,
NULL
,
SELECT_TYPE_ARG234
&
ss
,
SELECT_TYPE_ARG234
&ss2, &tv);
86
if
(
result
== 1) {
87
/* ready */
88
return
(1);
89
}
else
if
(
result
< 0) {
90
if
(
errno
!=
EINTR
) {
91
/* error */
92
return
(0);
93
}
94
/* try again */
95
time
(&
now
);
96
if
(
now
> done) {
97
/* timed-out */
98
errno
=
ETIMEDOUT
;
99
return
(0);
100
}
101
tleft = (
int
) (done -
now
);
102
}
else
{
103
/* timed-out */
104
errno
=
ETIMEDOUT
;
105
return
(0);
106
}
107
}
108
}
/* SWaitUntilReadyForWriting */
SWaitUntilReadyForReading
int SWaitUntilReadyForReading(const int sfd, const int tlen)
Definition:
SWait.c:7
SWaitUntilReadyForWriting
int SWaitUntilReadyForWriting(const int sfd, const int tlen)
Definition:
SWait.c:62
EINTR
#define EINTR
Definition:
acclib.h:80
EBADF
#define EBADF
Definition:
acclib.h:82
NULL
#define NULL
Definition:
types.h:112
int
unsigned int(__cdecl typeof(jpeg_read_scanlines))(struct jpeg_decompress_struct *
Definition:
typeof.h:31
select
INT WSAAPI select(IN INT s, IN OUT LPFD_SET readfds, IN OUT LPFD_SET writefds, IN OUT LPFD_SET exceptfds, IN CONST struct timeval *timeout)
Definition:
select.c:41
ETIMEDOUT
#define ETIMEDOUT
Definition:
errno.h:121
time_t
__kernel_time_t time_t
Definition:
linux.h:252
now
time_t now
Definition:
finger.c:65
result
GLuint64EXT * result
Definition:
glext.h:11304
ss
#define ss
Definition:
i386-dis.c:441
SELECT_TYPE_ARG234
#define SELECT_TYPE_ARG234
Definition:
wincfg.h:4
time
__u16 time
Definition:
mkdosfs.c:8
forever
#define forever
Definition:
ncftp.h:73
errno
#define errno
Definition:
errno.h:18
syshdrs.h
fd_set
Definition:
winsock.h:66
timeval
Definition:
linux.h:1737
timeval::tv_sec
unsigned long tv_sec
Definition:
linux.h:1738
timeval::tv_usec
unsigned long tv_usec
Definition:
linux.h:1739
FD_ZERO
#define FD_ZERO(set)
Definition:
winsock.h:96
FD_SET
#define FD_SET(fd, set)
Definition:
winsock.h:89
modules
rosapps
applications
net
ncftp
sio
SWait.c
Generated on Tue Oct 15 2024 06:06:13 for ReactOS by
1.9.6