ReactOS 0.4.15-dev-7918-g2a2556c
SSendto.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
11SSendto(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);
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;
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
67int
68SSendto(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) {
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 */
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
126int
127Sendto(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 */
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 Sendto(int sfd, const char *const buf, size_t size, const struct sockaddr_in *const toAddr)
Definition: SSendto.c:127
#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 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
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
__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