ReactOS  0.4.14-dev-77-gd9e7c48
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;
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 */
Definition: winsock.h:66
#define SELECT_TYPE_ARG234
Definition: wincfg.h:4
#define EINTR
Definition: acclib.h:80
int errno
__u16 time
Definition: mkdosfs.c:366
#define FD_ZERO(set)
Definition: winsock.h:96
#define FD_SET(fd, set)
Definition: winsock.h:89
Definition: arc.h:36
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
time_t now
Definition: finger.c:65
smooth NULL
Definition: ftsmooth.c:416
#define forever
Definition: ncftp.h:73
__kernel_time_t time_t
Definition: linux.h:252
#define ETIMEDOUT
Definition: errno.h:121
#define ss
Definition: i386-dis.c:432
GLuint64EXT * result
Definition: glext.h:11304
unsigned int(__cdecl typeof(jpeg_read_scanlines))(struct jpeg_decompress_struct *
Definition: typeof.h:31

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;
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 */
Definition: winsock.h:66
#define SELECT_TYPE_ARG234
Definition: wincfg.h:4
#define EINTR
Definition: acclib.h:80
int errno
__u16 time
Definition: mkdosfs.c:366
#define FD_ZERO(set)
Definition: winsock.h:96
#define FD_SET(fd, set)
Definition: winsock.h:89
Definition: arc.h:36
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
time_t now
Definition: finger.c:65
smooth NULL
Definition: ftsmooth.c:416
#define forever
Definition: ncftp.h:73
__kernel_time_t time_t
Definition: linux.h:252
#define ETIMEDOUT
Definition: errno.h:121
#define ss
Definition: i386-dis.c:432
GLuint64EXT * result
Definition: glext.h:11304
unsigned int(__cdecl typeof(jpeg_read_scanlines))(struct jpeg_decompress_struct *
Definition: typeof.h:31