ReactOS  0.4.14-dev-57-g333b8f1
SSendto.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 SSendto(int sfd, const char *const buf, size_t size, int fl, const struct sockaddr_in *const toAddr, int tlen)
12 {
13  int nwrote, tleft;
14  vsio_sigproc_t sigalrm, sigpipe;
15  time_t done, now;
16 
17  if (SSetjmp(gNetTimeoutJmp) != 0) {
18  alarm(0);
19  (void) SSignal(SIGALRM, (sio_sigproc_t) sigalrm);
20  (void) SSignal(SIGPIPE, (sio_sigproc_t) sigpipe);
21  errno = ETIMEDOUT;
22  return (kTimeoutErr);
23  }
24 
25  if (SSetjmp(gPipeJmp) != 0) {
26  alarm(0);
27  (void) SSignal(SIGALRM, (sio_sigproc_t) sigalrm);
28  (void) SSignal(SIGPIPE, (sio_sigproc_t) sigpipe);
29  errno = EPIPE;
30  return (kBrokenPipeErr);
31  }
32 
33  sigalrm = (vsio_sigproc_t) SSignal(SIGALRM, SIOHandler);
35 
36  time(&now);
37  done = now + tlen;
38  tleft = (int) (done - now);
39  forever {
40  (void) alarm((unsigned int) tleft);
41  nwrote = sendto(sfd, buf, size, fl,
42  (struct sockaddr *) toAddr,
43  (int) sizeof(struct sockaddr_in));
44  (void) alarm(0);
45  if (nwrote >= 0)
46  break;
47  if (errno != EINTR)
48  break; /* Fatal error. */
49  errno = 0;
50  time(&now);
51  tleft = (int) (done - now);
52  if (tleft < 1) {
53  nwrote = kTimeoutErr;
54  errno = ETIMEDOUT;
55  break;
56  }
57  }
58 
59  (void) SSignal(SIGALRM, (sio_sigproc_t) sigalrm);
60  (void) SSignal(SIGPIPE, (sio_sigproc_t) sigpipe);
61 
62  return (nwrote);
63 } /* SSendto */
64 
65 #else
66 
67 int
68 SSendto(int sfd, const char *const buf, size_t size, int fl, const struct sockaddr_in *const toAddr, int tlen)
69 {
70  int nwrote, tleft;
71  time_t done, now;
72  fd_set ss;
73  struct timeval tv;
74  int result;
75 
76  time(&now);
77  done = now + tlen;
78  nwrote = 0;
79  forever {
80  forever {
81  if (now >= done) {
82  errno = ETIMEDOUT;
84  return (kTimeoutErr);
85  }
86  tleft = (int) (done - now);
87  errno = 0;
88  FD_ZERO(&ss);
89  FD_SET(sfd, &ss);
90  tv.tv_sec = tleft;
91  tv.tv_usec = 0;
93  if (result == 1) {
94  /* ready */
95  break;
96  } else if (result == 0) {
97  /* timeout */
98  errno = ETIMEDOUT;
100  return (kTimeoutErr);
101  } else if (errno != EINTR) {
102  return (-1);
103  }
104  time(&now);
105  }
106 
107  nwrote = sendto(sfd, buf, size, fl,
108  (struct sockaddr *) toAddr,
109  (int) sizeof(struct sockaddr_in));
110 
111  if (nwrote >= 0)
112  break;
113  if (errno != EINTR)
114  break; /* Fatal error. */
115  }
116 
117  return (nwrote);
118 } /* SSendto */
119 
120 #endif
121 
122 
123 
124 
125 
126 int
127 Sendto(int sfd, const char *const buf, size_t size, const struct sockaddr_in *const toAddr)
128 {
129  int result;
130 
131  do {
132  result = sendto(sfd, buf, size, 0,
133  (struct sockaddr *) toAddr,
134  (int) sizeof(struct sockaddr_in));
135  } while ((result < 0) && (errno == EINTR));
136  return (result);
137 } /* Sendto */
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
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
#define EINTR
Definition: acclib.h:80
unsigned long tv_sec
Definition: linux.h:1738
int SSendto(int sfd, const char *const buf, size_t size, int fl, const struct sockaddr_in *const toAddr, int tlen)
Definition: SSendto.c:68
int errno
__u16 time
Definition: mkdosfs.c:366
#define FD_ZERO(set)
Definition: winsock.h:96
int Sendto(int sfd, const char *const buf, size_t size, const struct sockaddr_in *const toAddr)
Definition: SSendto.c:127
#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
unsigned long tv_usec
Definition: linux.h:1739
#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 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
INT WSAAPI sendto(IN SOCKET s, IN CONST CHAR FAR *buf, IN INT len, IN INT flags, IN CONST struct sockaddr *to, IN INT tolen)
Definition: send.c:82
#define ETIMEDOUT
Definition: errno.h:121
#define ss
Definition: i386-dis.c:432
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