mirror of
https://github.com/reactos/reactos.git
synced 2025-08-02 06:15:52 +00:00
Added ncftp to rosapps
svn path=/trunk/; revision=2453
This commit is contained in:
parent
289a784eef
commit
86bda6b3d9
118 changed files with 38524 additions and 0 deletions
108
rosapps/net/ncftp/sio/SWait.c
Normal file
108
rosapps/net/ncftp/sio/SWait.c
Normal file
|
@ -0,0 +1,108 @@
|
|||
#include "syshdrs.h"
|
||||
|
||||
/*
|
||||
* Return zero if the operation timed-out or erred-out, otherwise non-zero.
|
||||
*/
|
||||
int
|
||||
SWaitUntilReadyForReading(const int sfd, const int tlen)
|
||||
{
|
||||
fd_set ss, ss2;
|
||||
struct timeval tv;
|
||||
int result;
|
||||
int tleft;
|
||||
time_t now, done;
|
||||
|
||||
if (sfd < 0) {
|
||||
errno = EBADF;
|
||||
return (0);
|
||||
}
|
||||
|
||||
time(&now);
|
||||
done = now + tlen;
|
||||
tleft = tlen;
|
||||
|
||||
forever {
|
||||
FD_ZERO(&ss);
|
||||
FD_SET(sfd, &ss);
|
||||
ss2 = ss;
|
||||
tv.tv_sec = tleft;
|
||||
tv.tv_usec = 0;
|
||||
result = select(sfd + 1, SELECT_TYPE_ARG234 &ss, NULL, SELECT_TYPE_ARG234 &ss2, &tv);
|
||||
if (result == 1) {
|
||||
/* ready */
|
||||
return (1);
|
||||
} else if (result < 0) {
|
||||
if (errno != EINTR) {
|
||||
/* error */
|
||||
return (0);
|
||||
}
|
||||
/* try again */
|
||||
time(&now);
|
||||
if (now > done) {
|
||||
/* timed-out */
|
||||
errno = ETIMEDOUT;
|
||||
return (0);
|
||||
}
|
||||
tleft = (int) (done - now);
|
||||
} else {
|
||||
/* timed-out */
|
||||
errno = ETIMEDOUT;
|
||||
return (0);
|
||||
}
|
||||
}
|
||||
} /* SWaitUntilReadyForReading */
|
||||
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* Return zero if the operation timed-out or erred-out, otherwise non-zero.
|
||||
*/
|
||||
int
|
||||
SWaitUntilReadyForWriting(const int sfd, const int tlen)
|
||||
{
|
||||
fd_set ss, ss2;
|
||||
struct timeval tv;
|
||||
int result;
|
||||
int tleft;
|
||||
time_t now, done;
|
||||
|
||||
if (sfd < 0) {
|
||||
errno = EBADF;
|
||||
return (0);
|
||||
}
|
||||
|
||||
time(&now);
|
||||
done = now + tlen;
|
||||
tleft = tlen;
|
||||
|
||||
forever {
|
||||
FD_ZERO(&ss);
|
||||
FD_SET(sfd, &ss);
|
||||
ss2 = ss;
|
||||
tv.tv_sec = tleft;
|
||||
tv.tv_usec = 0;
|
||||
result = select(sfd + 1, NULL, SELECT_TYPE_ARG234 &ss, SELECT_TYPE_ARG234 &ss2, &tv);
|
||||
if (result == 1) {
|
||||
/* ready */
|
||||
return (1);
|
||||
} else if (result < 0) {
|
||||
if (errno != EINTR) {
|
||||
/* error */
|
||||
return (0);
|
||||
}
|
||||
/* try again */
|
||||
time(&now);
|
||||
if (now > done) {
|
||||
/* timed-out */
|
||||
errno = ETIMEDOUT;
|
||||
return (0);
|
||||
}
|
||||
tleft = (int) (done - now);
|
||||
} else {
|
||||
/* timed-out */
|
||||
errno = ETIMEDOUT;
|
||||
return (0);
|
||||
}
|
||||
}
|
||||
} /* SWaitUntilReadyForWriting */
|
Loading…
Add table
Add a link
Reference in a new issue