ReactOS 0.4.16-dev-125-g798ea90
SRead.c File Reference
#include "syshdrs.h"
Include dependency graph for SRead.c:

Go to the source code of this file.

Functions

static char UNUSED (gSioVersion[])
 
static char UNUSED (gNoSignalsMarker[])
 
int SRead (int sfd, char *const buf0, size_t size, int tlen, int retry)
 

Function Documentation

◆ SRead()

int SRead ( int  sfd,
char *const  buf0,
size_t  size,
int  tlen,
int  retry 
)

Definition at line 118 of file SRead.c.

119{
120 int nread;
121 volatile int nleft;
122 char *buf = buf0;
123 int tleft;
124 time_t done, now;
125 fd_set ss;
126 struct timeval tv;
127 int result, firstRead;
128
129 errno = 0;
130
131 nleft = (int) size;
132 time(&now);
133 done = now + tlen;
134 firstRead = 1;
135
136 forever {
137 tleft = (int) (done - now);
138 if (tleft < 1) {
139 nread = size - nleft;
140 if ((nread == 0) || ((retry & (kFullBufferRequired|kFullBufferRequiredExceptLast)) != 0)) {
141 nread = kTimeoutErr;
144 }
145 goto done;
146 }
147
148 if (!firstRead || ((retry & kNoFirstSelect) == 0)) {
149 forever {
150 errno = 0;
151 FD_ZERO(&ss);
152 FD_SET(sfd, &ss);
153 tv.tv_sec = tlen;
154 tv.tv_usec = 0;
156 if (result == 1) {
157 /* ready */
158 break;
159 } else if (result == 0) {
160 /* timeout */
161 nread = size - nleft;
162 if ((nread > 0) && ((retry & (kFullBufferRequired|kFullBufferRequiredExceptLast)) == 0))
163 return (nread);
166 return (kTimeoutErr);
167 } else if (errno != EINTR) {
168 return (-1);
169 }
170 }
171 firstRead = 0;
172 }
173
174#if defined(WIN32) || defined(_WINDOWS)
175 nread = recv(sfd, (char *) buf, nleft, 0);
176#else
177 nread = read(sfd, (char *) buf, nleft);
178#endif
179
180 if (nread <= 0) {
181 if (nread == 0) {
182 /* EOF */
183 if (retry == ((retry & (kFullBufferRequiredExceptLast)) != 0))
184 nread = size - nleft;
185 goto done;
186 } else if (errno != EINTR) {
187 nread = size - nleft;
188 if (nread == 0)
189 nread = -1;
190 goto done;
191 } else {
192 errno = 0;
193 nread = 0;
194 /* Try again. */
195
196 /* Ignore these two lines */
197 LIBSIO_USE_VAR(gSioVersion);
199 }
200 }
201 nleft -= nread;
202 if ((nleft <= 0) || (((retry & (kFullBufferRequired|kFullBufferRequiredExceptLast)) == 0) && (nleft != (int) size)))
203 break;
204 buf += nread;
205 time(&now);
206 }
207 nread = size - nleft;
208
209done:
210 return (nread);
211} /* SRead */
#define EINTR
Definition: acclib.h:80
#define read
Definition: acwin.h:96
#define NULL
Definition: types.h:112
unsigned int(__cdecl typeof(jpeg_read_scanlines))(struct jpeg_decompress_struct *
Definition: typeof.h:31
INT WSAAPI recv(IN SOCKET s, OUT CHAR FAR *buf, IN INT len, IN INT flags)
Definition: recv.c:23
INT WSAAPI select(IN INT s, IN OUT LPFD_SET readfds, IN OUT LPFD_SET writefds, IN OUT LPFD_SET exceptfds, IN CONST struct timeval *timeout)
Definition: select.c:41
#define ETIMEDOUT
Definition: errno.h:121
__kernel_time_t time_t
Definition: linux.h:252
time_t now
Definition: finger.c:65
GLsizeiptr size
Definition: glext.h:5919
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
GLuint64EXT * result
Definition: glext.h:11304
#define ss
Definition: i386-dis.c:441
#define SELECT_TYPE_ARG234
Definition: wincfg.h:4
#define SELECT_TYPE_ARG5
Definition: wincfg.h:7
__u16 time
Definition: mkdosfs.c:8
char gNoSignalsMarker[]
Definition: ftp.c:14
#define kFullBufferRequired
Definition: sio.h:50
#define SETWSATIMEOUTERR
Definition: sio.h:120
#define kFullBufferRequiredExceptLast
Definition: sio.h:51
#define kNoFirstSelect
Definition: sio.h:52
#define LIBSIO_USE_VAR(a)
Definition: sio.h:140
#define kTimeoutErr
Definition: sio.h:58
#define forever
Definition: ncftp.h:73
#define errno
Definition: errno.h:18
Definition: winsock.h:66
#define FD_ZERO(set)
Definition: winsock.h:96
#define FD_SET(fd, set)
Definition: winsock.h:89

Referenced by FTPGetOneF(), and SReadline().

◆ UNUSED() [1/2]

static char UNUSED ( gNoSignalsMarker  [])
static

◆ UNUSED() [2/2]

static char UNUSED ( gSioVersion  [])
static