ReactOS  0.4.14-dev-337-gf981a68
USendtoByName.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 USendtoByName(int sfd, const char *const buf, size_t size, int fl, const char *const toAddrStr, int tlen)
10 {
11  int nwrote, tleft;
12  vsio_sigproc_t sigalrm, sigpipe;
13  time_t done, now;
14  struct sockaddr_un toAddr;
15  int ualen;
16 
17  ualen = MakeSockAddrUn(&toAddr, toAddrStr);
18 
19  if (SSetjmp(gNetTimeoutJmp) != 0) {
20  alarm(0);
21  (void) SSignal(SIGALRM, (sio_sigproc_t) sigalrm);
22  (void) SSignal(SIGPIPE, (sio_sigproc_t) sigpipe);
23  errno = ETIMEDOUT;
24  return (kTimeoutErr);
25  }
26 
27  if (SSetjmp(gPipeJmp) != 0) {
28  alarm(0);
29  (void) SSignal(SIGALRM, (sio_sigproc_t) sigalrm);
30  (void) SSignal(SIGPIPE, (sio_sigproc_t) sigpipe);
31  errno = EPIPE;
32  return (kBrokenPipeErr);
33  }
34 
35  sigalrm = (vsio_sigproc_t) SSignal(SIGALRM, SIOHandler);
37 
38  time(&now);
39  done = now + tlen;
40  tleft = (int) (done - now);
41  forever {
42  (void) alarm((unsigned int) tleft);
43  nwrote = sendto(sfd, buf, size, fl,
44  (struct sockaddr *) &toAddr, ualen);
45  (void) alarm(0);
46  if (nwrote >= 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  nwrote = kTimeoutErr;
55  errno = ETIMEDOUT;
56  break;
57  }
58  }
59 
60  (void) SSignal(SIGALRM, (sio_sigproc_t) sigalrm);
61  (void) SSignal(SIGPIPE, (sio_sigproc_t) sigpipe);
62 
63  return (nwrote);
64 } /* USendtoByName */
65 
66 #endif
#define EPIPE
Definition: acclib.h:91
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
int MakeSockAddrUn(struct sockaddr_un *, const char *const)
#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
__kernel_time_t time_t
Definition: linux.h:252
void(*)(int) SSignal(int signum, void(*handler)(int))
Definition: sio.h:237
int USendtoByName(int, const char *const, size_t, int, const char *const, int)
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
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