4 extern volatile Sjmp_buf gNetTimeoutJmp
;
5 extern volatile Sjmp_buf gPipeJmp
;
11 SWrite(int sfd
, const char *const buf0
, size_t size
, int tlen
, int swopts
)
14 const char *volatile buf
= buf0
;
16 vsio_sigproc_t sigalrm
, sigpipe
;
19 if (SSetjmp(gNetTimeoutJmp
) != 0) {
21 (void) SSignal(SIGALRM
, (sio_sigproc_t
) sigalrm
);
22 (void) SSignal(SIGPIPE
, (sio_sigproc_t
) sigpipe
);
23 nwrote
= size
- nleft
;
30 if (SSetjmp(gPipeJmp
) != 0) {
32 (void) SSignal(SIGALRM
, (sio_sigproc_t
) sigalrm
);
33 (void) SSignal(SIGPIPE
, (sio_sigproc_t
) sigpipe
);
34 nwrote
= size
- nleft
;
38 return (kBrokenPipeErr
);
41 sigalrm
= (vsio_sigproc_t
) SSignal(SIGALRM
, SIOHandler
);
42 sigpipe
= (vsio_sigproc_t
) SSignal(SIGPIPE
, SIOHandler
);
48 tleft
= (int) (done
- now
);
50 nwrote
= size
- nleft
;
57 (void) alarm((unsigned int) tleft
);
58 nwrote
= write(sfd
, buf
, nleft
);
62 nwrote
= size
- nleft
;
78 nwrote
= size
- nleft
;
81 (void) SSignal(SIGALRM
, (sio_sigproc_t
) sigalrm
);
82 (void) SSignal(SIGPIPE
, (sio_sigproc_t
) sigpipe
);
90 SWrite(int sfd
, const char *const buf0
, size_t size
, int tlen
, int swopts
)
93 const char *buf
= buf0
;
98 int result
, firstWrite
;
106 tleft
= (int) (done
- now
);
108 nwrote
= size
- nleft
;
110 nwrote
= kTimeoutErr
;
118 /* Unfortunately this doesn't help when the
119 * send buffer fills during the time we're
120 * writing to it, so you could still be
121 * blocked after breaking this loop and starting
124 if (!firstWrite
|| ((swopts
& kNoFirstSelect
) == 0)) {
131 result
= select(sfd
+ 1, NULL
, SELECT_TYPE_ARG234
&ss
, NULL
, SELECT_TYPE_ARG5
&tv
);
135 } else if (result
== 0) {
137 nwrote
= size
- nleft
;
142 return (kTimeoutErr
);
143 } else if (errno
!= EINTR
) {
150 #if defined(WIN32) || defined(_WINDOWS)
151 nwrote
= send(sfd
, buf
, size
, 0);
153 nwrote
= write(sfd
, buf
, size
);
157 if (errno
!= EINTR
) {
158 nwrote
= size
- nleft
;
174 nwrote
= size
- nleft
;