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 */
6int
7SWaitUntilReadyForReading(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;
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 */
44 return (0);
45 }
46 tleft = (int) (done - now);
47 } else {
48 /* timed-out */
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 */
61int
62SWaitUntilReadyForWriting(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;
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 */
99 return (0);
100 }
101 tleft = (int) (done - now);
102 } else {
103 /* timed-out */
105 return (0);
106 }
107 }
108} /* SWaitUntilReadyForWriting */
int SWaitUntilReadyForReading(const int sfd, const int tlen)
Definition: SWait.c:7
int SWaitUntilReadyForWriting(const int sfd, const int tlen)
Definition: SWait.c:62
#define EINTR
Definition: acclib.h:80
#define EBADF
Definition: acclib.h:82
#define NULL
Definition: types.h:112
unsigned int(__cdecl typeof(jpeg_read_scanlines))(struct jpeg_decompress_struct *
Definition: typeof.h:31
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
#define ETIMEDOUT
Definition: errno.h:121
__kernel_time_t time_t
Definition: linux.h:252
time_t now
Definition: finger.c:65
GLuint64EXT * result
Definition: glext.h:11304
#define ss
Definition: i386-dis.c:441
#define SELECT_TYPE_ARG234
Definition: wincfg.h:4
__u16 time
Definition: mkdosfs.c:8
#define forever
Definition: ncftp.h:73
#define errno
Definition: errno.h:18
Definition: winsock.h:66
unsigned long tv_sec
Definition: linux.h:1738
unsigned long tv_usec
Definition: linux.h:1739
#define FD_ZERO(set)
Definition: winsock.h:96
#define FD_SET(fd, set)
Definition: winsock.h:89