home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ftp.ncftp.com
/
ftp.ncftp.com.zip
/
ftp.ncftp.com
/
libncftp
/
older_versions
/
libncftp-3.1.5-src.tar.gz
/
libncftp-3.1.5-src.tar
/
libncftp-3.1.5
/
sio
/
USendto.c
< prev
next >
Wrap
C/C++ Source or Header
|
2001-11-19
|
3KB
|
131 lines
#include "syshdrs.h"
#ifdef PRAGMA_HDRSTOP
# pragma hdrstop
#endif
#ifndef NO_SIGNALS
extern Sjmp_buf gNetTimeoutJmp;
extern Sjmp_buf gPipeJmp;
int
USendto(int sfd, const char *const buf, size_t size, int fl, const struct sockaddr_un *const toAddr, int ualen, int tlen)
{
send_return_t nwrote;
alarm_time_t tleft;
vsio_sigproc_t sigalrm, sigpipe;
time_t done, now;
if (SSetjmp(gNetTimeoutJmp) != 0) {
alarm(0);
(void) SSignal(SIGALRM, (sio_sigproc_t) sigalrm);
(void) SSignal(SIGPIPE, (sio_sigproc_t) sigpipe);
errno = ETIMEDOUT;
return (kTimeoutErr);
}
if (SSetjmp(gPipeJmp) != 0) {
alarm(0);
(void) SSignal(SIGALRM, (sio_sigproc_t) sigalrm);
(void) SSignal(SIGPIPE, (sio_sigproc_t) sigpipe);
errno = EPIPE;
return (kBrokenPipeErr);
}
sigalrm = (vsio_sigproc_t) SSignal(SIGALRM, SIOHandler);
sigpipe = (vsio_sigproc_t) SSignal(SIGPIPE, SIOHandler);
time(&now);
done = now + tlen;
tleft = (done < now) ? ((alarm_time_t) (done - now)) : 0;
forever {
if (tleft < 1) {
nwrote = kTimeoutErr;
errno = ETIMEDOUT;
break;
}
(void) alarm(tleft);
nwrote = sendto(sfd, buf, (send_size_t) size, fl,
(const struct sockaddr *) toAddr, (sockaddr_size_t) ualen);
(void) alarm(0);
if (nwrote >= 0)
break;
if (errno != EINTR)
break; /* Fatal error. */
errno = 0;
time(&now);
tleft = (done < now) ? ((alarm_time_t) (done - now)) : 0;
}
(void) SSignal(SIGALRM, (sio_sigproc_t) sigalrm);
(void) SSignal(SIGPIPE, (sio_sigproc_t) sigpipe);
return ((int) nwrote);
} /* USendto */
#else
int
USendto(int sfd, const char *const buf, size_t size, int fl, const struct sockaddr_un *const toAddr, int ualen, int tlen)
{
send_return_t nwrote;
int tleft;
time_t done, now;
fd_set ss;
struct timeval tv;
int result;
time(&now);
done = now + tlen;
nwrote = 0;
forever {
forever {
if (now >= done) {
errno = ETIMEDOUT;
SETWSATIMEOUTERR
return (kTimeoutErr);
}
tleft = (int) (done - now);
errno = 0;
MY_FD_ZERO(&ss);
#if defined(__DECC) || defined(__DECCXX)
#pragma message save
#pragma message disable trunclongint
#endif
MY_FD_SET(sfd, &ss);
#if defined(__DECC) || defined(__DECCXX)
#pragma message restore
#endif
tv.tv_sec = (tv_sec_t) tleft;
tv.tv_usec = 0;
result = select(sfd + 1, NULL, SELECT_TYPE_ARG234 &ss, NULL, SELECT_TYPE_ARG5 &tv);
if (result == 1) {
/* ready */
break;
} else if (result == 0) {
/* timeout */
errno = ETIMEDOUT;
SETWSATIMEOUTERR
return (kTimeoutErr);
} else if (errno != EINTR) {
return (-1);
}
time(&now);
}
nwrote = sendto(sfd, buf, (send_size_t) size, fl,
(const struct sockaddr *) toAddr,
(sockaddr_size_t) ualen);
if (nwrote >= 0)
break;
if (errno != EINTR)
break; /* Fatal error. */
}
return ((int) nwrote);
} /* USendto */
#endif