4 extern volatile Sjmp_buf gNetTimeoutJmp
;
5 extern volatile Sjmp_buf gPipeJmp
;
9 SClose(int sfd
, int tlen
)
12 vsio_sigproc_t sigalrm
, sigpipe
;
20 /* Don't time it, shut it down now. */
21 if (SetSocketLinger(sfd
, 0, 0) == 0) {
22 /* Linger disabled, so close()
25 return (closesocket(sfd
));
27 /* This will result in a fd leak,
28 * but it's either that or hang forever.
30 return (shutdown(sfd
, 2));
34 if (SSetjmp(gNetTimeoutJmp
) != 0) {
36 (void) SSignal(SIGALRM
, (sio_sigproc_t
) sigalrm
);
37 (void) SSignal(SIGPIPE
, (sio_sigproc_t
) sigpipe
);
38 if (SetSocketLinger(sfd
, 0, 0) == 0) {
39 /* Linger disabled, so close()
42 return closesocket(sfd
);
44 /* This will result in a fd leak,
45 * but it's either that or hang forever.
47 (void) shutdown(sfd
, 2);
52 sigalrm
= (vsio_sigproc_t
) SSignal(SIGALRM
, SIOHandler
);
53 sigpipe
= (vsio_sigproc_t
) SSignal(SIGPIPE
, SIG_IGN
);
55 alarm((unsigned int) tlen
);
57 if (closesocket(sfd
) == 0) {
65 (void) SSignal(SIGALRM
, (sio_sigproc_t
) sigalrm
);
67 if ((errno
!= 0) && (errno
!= EBADF
)) {
68 if (SetSocketLinger(sfd
, 0, 0) == 0) {
69 /* Linger disabled, so close()
72 (void) closesocket(sfd
);
74 /* This will result in a fd leak,
75 * but it's either that or hang forever.
77 (void) shutdown(sfd
, 2);
80 (void) SSignal(SIGPIPE
, (sio_sigproc_t
) sigpipe
);
82 return ((errno
== 0) ? 0 : (-1));
95 /* Don't time it, shut it down now. */
96 if (SetSocketLinger(sfd
, 0, 0) == 0) {
97 /* Linger disabled, so close()
100 return (closesocket(sfd
));
102 /* This will result in a fd leak,
103 * but it's either that or hang forever.
105 return (shutdown(sfd
, 2));
109 /* Wait until the socket is ready for writing (usually easy). */
117 if (SetSocketLinger(sfd
, 0, 0) == 0) {
118 /* Linger disabled, so close()
121 (void) closesocket(sfd
);
123 /* This will result in a fd leak,
124 * but it's either that or hang forever.
126 (void) shutdown(sfd
, 2);
129 return (kTimeoutErr
);
137 result
= select(sfd
+ 1, NULL
, SELECT_TYPE_ARG234
&ss
, NULL
, SELECT_TYPE_ARG5
&tv
);
141 } else if (result
== 0) {
143 if (SetSocketLinger(sfd
, 0, 0) == 0) {
144 /* Linger disabled, so close()
147 (void) closesocket(sfd
);
149 /* This will result in a fd leak,
150 * but it's either that or hang forever.
152 (void) shutdown(sfd
, 2);
155 return (kTimeoutErr
);
156 } else if (errno
!= EINTR
) {
157 /* Error, done. This end may have been shutdown. */
163 /* Wait until the socket is ready for reading. */
168 if (SetSocketLinger(sfd
, 0, 0) == 0) {
169 /* Linger disabled, so close()
172 (void) closesocket(sfd
);
174 /* This will result in a fd leak,
175 * but it's either that or hang forever.
177 (void) shutdown(sfd
, 2);
180 return (kTimeoutErr
);
188 result
= select(sfd
+ 1, SELECT_TYPE_ARG234
&ss
, NULL
, NULL
, SELECT_TYPE_ARG5
&tv
);
192 } else if (result
== 0) {
194 if (SetSocketLinger(sfd
, 0, 0) == 0) {
195 /* Linger disabled, so close()
198 (void) closesocket(sfd
);
200 /* This will result in a fd leak,
201 * but it's either that or hang forever.
203 (void) shutdown(sfd
, 2);
206 return (kTimeoutErr
);
207 } else if (errno
!= EINTR
) {
208 /* Error, done. This end may have been shutdown. */
214 /* If we get here, close() won't block. */
215 return closesocket(sfd
);