ReactOS  0.4.13-dev-645-g69454b4
URecvfrom.c
Go to the documentation of this file.
1 #include "syshdrs.h"
2 
3 #if !defined(NO_UNIX_DOMAIN_SOCKETS) && !defined(NO_SIGNALS)
4 
5 extern volatile Sjmp_buf gNetTimeoutJmp;
6 extern volatile Sjmp_buf gPipeJmp;
7 
8 int
9 URecvfrom(int sfd, char *const buf, size_t size, int fl, struct sockaddr_un *const fromAddr, int *ualen, int tlen)
10 {
11  int nread, tleft;
12  vsio_sigproc_t sigalrm, sigpipe;
13  time_t done, now;
14 
15  if (SSetjmp(gNetTimeoutJmp) != 0) {
16  alarm(0);
17  (void) SSignal(SIGALRM, (sio_sigproc_t) sigalrm);
18  (void) SSignal(SIGPIPE, (sio_sigproc_t) sigpipe);
19  errno = ETIMEDOUT;
20  return (kTimeoutErr);
21  }
22 
23  if (SSetjmp(gPipeJmp) != 0) {
24  alarm(0);
25  (void) SSignal(SIGALRM, (sio_sigproc_t) sigalrm);
26  (void) SSignal(SIGPIPE, (sio_sigproc_t) sigpipe);
27  errno = EPIPE;
28  return (kBrokenPipeErr);
29  }
30 
31  sigalrm = (vsio_sigproc_t) SSignal(SIGALRM, SIOHandler);
33 
34  time(&now);
35  done = now + tlen;
36  tleft = (int) (done - now);
37  forever {
38  *ualen = sizeof(struct sockaddr_un);
39  (void) alarm((unsigned int) tleft);
40  nread = recvfrom(sfd, buf, size, fl,
41  (struct sockaddr *) fromAddr, ualen);
42  (void) alarm(0);
43  if (nread >= 0)
44  break;
45  if (errno != EINTR)
46  break; /* Fatal error. */
47  errno = 0;
48  time(&now);
49  tleft = (int) (done - now);
50  if (tleft < 1) {
51  nread = kTimeoutErr;
52  errno = ETIMEDOUT;
53  break;
54  }
55  }
56 
57  (void) SSignal(SIGALRM, (sio_sigproc_t) sigalrm);
58  (void) SSignal(SIGPIPE, (sio_sigproc_t) sigpipe);
59 
60  return (nread);
61 } /* URecvfrom */
62 
63 #endif
#define EPIPE
Definition: acclib.h:91
INT WSAAPI recvfrom(IN SOCKET s, OUT CHAR FAR *buf, IN INT len, IN INT flags, OUT LPSOCKADDR from, IN OUT INT FAR *fromlen)
Definition: recv.c:87
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
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
#define EINTR
Definition: acclib.h:80
int errno
__u16 time
Definition: mkdosfs.c:366
#define Sjmp_buf
Definition: sio.h:41
_In_ FLONG fl
Definition: winddi.h:1279
time_t now
Definition: finger.c:65
#define kTimeoutErr
Definition: sio.h:58
GLsizeiptr size
Definition: glext.h:5919
#define SIGPIPE
Definition: signal.h:35
#define SSetjmp(a)
Definition: sio.h:39
#define forever
Definition: ncftp.h:73
#define kBrokenPipeErr
Definition: sio.h:59
int URecvfrom(int, char *const, size_t, int, struct sockaddr_un *const, int *, int)
__kernel_time_t time_t
Definition: linux.h:252
void(*)(int) SSignal(int signum, void(*handler)(int))
Definition: sio.h:237
#define ETIMEDOUT
Definition: errno.h:121
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