ReactOS 0.4.15-dev-8236-g99f0937
SRecvfrom.c
Go to the documentation of this file.
1#include "syshdrs.h"
2
3#ifndef NO_SIGNALS
4extern volatile Sjmp_buf gNetTimeoutJmp;
5extern volatile Sjmp_buf gPipeJmp;
6#endif
7
8#ifndef NO_SIGNALS
9
10int
11SRecvfrom(int sfd, char *const buf, size_t size, int fl, struct sockaddr_in *const fromAddr, int tlen)
12{
13 int nread, tleft;
14 vsio_sigproc_t sigalrm, sigpipe;
15 time_t done, now;
16 int alen;
17
18 if (SSetjmp(gNetTimeoutJmp) != 0) {
19 alarm(0);
20 (void) SSignal(SIGALRM, (sio_sigproc_t) sigalrm);
21 (void) SSignal(SIGPIPE, (sio_sigproc_t) sigpipe);
23 return (kTimeoutErr);
24 }
25
26 if (SSetjmp(gPipeJmp) != 0) {
27 alarm(0);
28 (void) SSignal(SIGALRM, (sio_sigproc_t) sigalrm);
29 (void) SSignal(SIGPIPE, (sio_sigproc_t) sigpipe);
30 errno = EPIPE;
31 return (kBrokenPipeErr);
32 }
33
34 sigalrm = (vsio_sigproc_t) SSignal(SIGALRM, SIOHandler);
36
37 time(&now);
38 done = now + tlen;
39 tleft = (int) (done - now);
40 forever {
41 alen = sizeof(struct sockaddr_in);
42 (void) alarm((unsigned int) tleft);
43 nread = recvfrom(sfd, buf, size, fl,
44 (struct sockaddr *) fromAddr, &alen);
45 (void) alarm(0);
46 if (nread >= 0)
47 break;
48 if (errno != EINTR)
49 break; /* Fatal error. */
50 errno = 0;
51 time(&now);
52 tleft = (int) (done - now);
53 if (tleft < 1) {
54 nread = kTimeoutErr;
56 break;
57 }
58 }
59
60 (void) SSignal(SIGALRM, (sio_sigproc_t) sigalrm);
61 (void) SSignal(SIGPIPE, (sio_sigproc_t) sigpipe);
62
63 return (nread);
64} /* SRecvfrom */
65
66#else
67
68int
69SRecvfrom(int sfd, char *const buf, size_t size, int fl, struct sockaddr_in *const fromAddr, int tlen)
70{
71 int nread, tleft;
72 fd_set ss;
73 struct timeval tv;
74 int result;
75 time_t done, now;
76 int alen;
77
78 time(&now);
79 done = now + tlen;
80 tleft = (int) (done - now);
81 nread = 0;
82 forever {
83 alen = sizeof(struct sockaddr_in);
84
85 forever {
86 errno = 0;
87 FD_ZERO(&ss);
88 FD_SET(sfd, &ss);
89 tv.tv_sec = tleft;
90 tv.tv_usec = 0;
92 if (result == 1) {
93 /* ready */
94 break;
95 } else if (result == 0) {
96 /* timeout */
99 return (kTimeoutErr);
100 } else if (errno != EINTR) {
101 return (-1);
102 }
103 }
104
105 nread = recvfrom(sfd, buf, size, fl,
106 (struct sockaddr *) fromAddr, &alen);
107
108 if (nread >= 0)
109 break;
110 if (errno != EINTR)
111 break; /* Fatal error. */
112 errno = 0;
113 time(&now);
114 tleft = (int) (done - now);
115 if (tleft < 1) {
116 nread = kTimeoutErr;
119 break;
120 }
121 }
122
123 return (nread);
124} /* SRecvfrom */
125
126#endif
127
int SRecvfrom(int sfd, char *const buf, size_t size, int fl, struct sockaddr_in *const fromAddr, int tlen)
Definition: SRecvfrom.c:69
#define EINTR
Definition: acclib.h:80
#define EPIPE
Definition: acclib.h:91
#define SIGPIPE
Definition: signal.h:35
#define NULL
Definition: types.h:112
unsigned int(__cdecl typeof(jpeg_read_scanlines))(struct jpeg_decompress_struct *
Definition: typeof.h:31
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
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
GLsizeiptr size
Definition: glext.h:5919
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
GLuint64EXT * result
Definition: glext.h:11304
#define ss
Definition: i386-dis.c:441
#define SELECT_TYPE_ARG234
Definition: wincfg.h:4
#define SELECT_TYPE_ARG5
Definition: wincfg.h:7
__u16 time
Definition: mkdosfs.c:8
#define kBrokenPipeErr
Definition: sio.h:59
void SIOHandler(int)
#define SETWSATIMEOUTERR
Definition: sio.h:120
#define SSetjmp(a)
Definition: sio.h:39
volatile sio_sigproc_t vsio_sigproc_t
Definition: sio.h:124
void(*)(int) SSignal(int signum, void(*handler)(int))
Definition: sio.h:237
#define Sjmp_buf
Definition: sio.h:41
#define kTimeoutErr
Definition: sio.h:58
void(* sio_sigproc_t)(int)
Definition: sio.h:123
#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
_In_ FLONG fl
Definition: winddi.h:1279
#define FD_ZERO(set)
Definition: winsock.h:96
#define FD_SET(fd, set)
Definition: winsock.h:89