ReactOS 0.4.15-dev-8344-g0574987
SWait.c File Reference
#include "syshdrs.h"
Include dependency graph for SWait.c:

Go to the source code of this file.

Functions

int SWaitUntilReadyForReading (const int sfd, const int tlen)
 
int SWaitUntilReadyForWriting (const int sfd, const int tlen)
 

Function Documentation

◆ SWaitUntilReadyForReading()

int SWaitUntilReadyForReading ( const int  sfd,
const int  tlen 
)

Definition at line 7 of file SWait.c.

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 */
#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
#define FD_ZERO(set)
Definition: winsock.h:96
#define FD_SET(fd, set)
Definition: winsock.h:89

Referenced by GetResponse().

◆ SWaitUntilReadyForWriting()

int SWaitUntilReadyForWriting ( const int  sfd,
const int  tlen 
)

Definition at line 62 of file SWait.c.

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 */