ReactOS  0.4.14-dev-55-g2da92ac
SRecvmsg.c
Go to the documentation of this file.
1 #include "syshdrs.h"
2 
3 #ifndef NO_SIGNALS
4 extern volatile Sjmp_buf gNetTimeoutJmp;
5 extern volatile Sjmp_buf gPipeJmp;
6 #endif
7 
8 #ifndef NO_SIGNALS
9 
10 int
11 SRecvmsg(int sfd, void *const msg, int fl, int tlen)
12 {
13  int nread, tleft;
14  vsio_sigproc_t sigalrm, sigpipe;
15  time_t done, now;
16 
17  if (tlen < 0) {
18  errno = 0;
19  for (;;) {
20  nread = recvmsg(sfd, (struct msghdr *) msg, fl);
21  if ((nread >= 0) || (errno != EINTR))
22  return (nread);
23  }
24  }
25 
26  if (SSetjmp(gNetTimeoutJmp) != 0) {
27  alarm(0);
28  (void) SSignal(SIGALRM, (sio_sigproc_t) sigalrm);
29  (void) SSignal(SIGPIPE, (sio_sigproc_t) sigpipe);
30  errno = ETIMEDOUT;
31  return (kTimeoutErr);
32  }
33 
34  if (SSetjmp(gPipeJmp) != 0) {
35  alarm(0);
36  (void) SSignal(SIGALRM, (sio_sigproc_t) sigalrm);
37  (void) SSignal(SIGPIPE, (sio_sigproc_t) sigpipe);
38  errno = EPIPE;
39  return (kBrokenPipeErr);
40  }
41 
42  sigalrm = (vsio_sigproc_t) SSignal(SIGALRM, SIOHandler);
44 
45  time(&now);
46  done = now + tlen;
47  tleft = (int) (done - now);
48  forever {
49  (void) alarm((unsigned int) tleft);
50  nread = recvmsg(sfd, (struct msghdr *) msg, fl);
51  (void) alarm(0);
52  if (nread >= 0)
53  break;
54  if (errno != EINTR)
55  break; /* Fatal error. */
56  errno = 0;
57  time(&now);
58  tleft = (int) (done - now);
59  if (tleft < 1) {
60  nread = kTimeoutErr;
61  errno = ETIMEDOUT;
62  break;
63  }
64  }
65 
66  (void) SSignal(SIGALRM, (sio_sigproc_t) sigalrm);
67  (void) SSignal(SIGPIPE, (sio_sigproc_t) sigpipe);
68 
69  return (nread);
70 } /* SRecvmsg */
71 
72 #elif defined(HAVE_RECVMSG)
73 
74 int
75 SRecvmsg(int sfd, void *const msg, int fl, int tlen)
76 {
77  int nread, tleft;
78  time_t done, now;
79  fd_set ss;
80  struct timeval tv;
81  int result;
82 
83  if (tlen < 0) {
84  errno = 0;
85  for (;;) {
86  nread = recvmsg(sfd, (struct msghdr *) msg, fl);
87  if ((nread >= 0) || (errno != EINTR))
88  return (nread);
89  }
90  }
91 
92  time(&now);
93  done = now + tlen;
94  tleft = (int) (done - now);
95  forever {
96 
97  for (;;) {
98  errno = 0;
99  FD_ZERO(&ss);
100  FD_SET(sfd, &ss);
101  tv.tv_sec = tleft;
102  tv.tv_usec = 0;
104  if (result == 1) {
105  /* ready */
106  break;
107  } else if (result == 0) {
108  /* timeout */
109  errno = ETIMEDOUT;
111  return (kTimeoutErr);
112  } else if (errno != EINTR) {
113  return (-1);
114  }
115  }
116 
117  nread = recvmsg(sfd, (struct msghdr *) msg, fl);
118 
119  if (nread >= 0)
120  break;
121  if (errno != EINTR)
122  break; /* Fatal error. */
123  errno = 0;
124  time(&now);
125  tleft = (int) (done - now);
126  if (tleft < 1) {
127  nread = kTimeoutErr;
128  errno = ETIMEDOUT;
130  break;
131  }
132  }
133 
134  return (nread);
135 } /* SRecvmsg */
136 
137 #endif
Definition: winsock.h:66
#define EPIPE
Definition: acclib.h:91
#define SELECT_TYPE_ARG234
Definition: wincfg.h:4
struct png_info_def **typedef void(__cdecl typeof(png_destroy_read_struct))(struct png_struct_def **
Definition: typeof.h:49
volatile sio_sigproc_t vsio_sigproc_t
Definition: sio.h:124
#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
#define Sjmp_buf
Definition: sio.h:41
_In_ FLONG fl
Definition: winddi.h:1279
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 kTimeoutErr
Definition: sio.h:58
#define SIGPIPE
Definition: signal.h:35
#define SSetjmp(a)
Definition: sio.h:39
#define SELECT_TYPE_ARG5
Definition: wincfg.h:7
#define forever
Definition: ncftp.h:73
#define kBrokenPipeErr
Definition: sio.h:59
#define SETWSATIMEOUTERR
Definition: sio.h:120
__kernel_time_t time_t
Definition: linux.h:252
void(*)(int) SSignal(int signum, void(*handler)(int))
Definition: sio.h:237
#define msg(x)
Definition: auth_time.c:54
#define ETIMEDOUT
Definition: errno.h:121
#define ss
Definition: i386-dis.c:432
int SRecvmsg(int, void *const, int, int)
GLuint64EXT * result
Definition: glext.h:11304
void(* sio_sigproc_t)(int)
Definition: sio.h:123
void SIOHandler(int)
unsigned int(__cdecl typeof(jpeg_read_scanlines))(struct jpeg_decompress_struct *
Definition: typeof.h:31