ReactOS 0.4.16-dev-329-g9223134
SRecv.c File Reference
#include "syshdrs.h"
Include dependency graph for SRecv.c:

Go to the source code of this file.

Functions

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

Function Documentation

◆ SRecv()

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

Definition at line 97 of file SRecv.c.

98{
99 int nread;
100 int nleft;
101 char *buf = buf0;
102 int tleft;
103 time_t done, now;
104 fd_set ss;
105 struct timeval tv;
106 int result;
107
108 errno = 0;
109
110 nleft = (int) size;
111 time(&now);
112 done = now + tlen;
113 forever {
114 tleft = (int) (done - now);
115 if (tleft < 1) {
116 nread = size - nleft;
117 if ((nread == 0) || (retry == kFullBufferRequired)) {
118 nread = kTimeoutErr;
121 }
122 goto done;
123 }
124
125 forever {
126 errno = 0;
127 FD_ZERO(&ss);
128 FD_SET(sfd, &ss);
129 tv.tv_sec = tlen;
130 tv.tv_usec = 0;
132 if (result == 1) {
133 /* ready */
134 break;
135 } else if (result == 0) {
136 /* timeout */
137 nread = size - nleft;
138 if ((nread > 0) && (retry == kFullBufferNotRequired))
139 return (nread);
142 return (kTimeoutErr);
143 } else if (errno != EINTR) {
144 return (-1);
145 }
146 }
147
148#if defined(WIN32) || defined(_WINDOWS)
149 nread = recv(sfd, (char *) buf, nleft, fl);
150#else
151 nread = recv(sfd, (char *) buf, nleft, fl);
152#endif
153
154 if (nread <= 0) {
155 if (nread == 0) {
156 /* EOF */
158 nread = size - nleft;
159 goto done;
160 } else if (errno != EINTR) {
161 nread = size - nleft;
162 if (nread == 0)
163 nread = -1;
164 goto done;
165 } else {
166 errno = 0;
167 nread = 0;
168 /* Try again. */
169 }
170 }
171 nleft -= nread;
172 if ((nleft <= 0) || ((retry == 0) && (nleft != (int) size)))
173 break;
174 buf += nread;
175 time(&now);
176 }
177 nread = size - nleft;
178
179done:
180 return (nread);
181} /* SRecv */
#define EINTR
Definition: acclib.h:80
#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
#define kFullBufferRequired
Definition: sio.h:50
#define SETWSATIMEOUTERR
Definition: sio.h:120
#define kFullBufferRequiredExceptLast
Definition: sio.h:51
#define kFullBufferNotRequired
Definition: sio.h:49
#define kTimeoutErr
Definition: sio.h:58
#define forever
Definition: ncftp.h:73
#define errno
Definition: errno.h:18
Definition: winsock.h:66
_In_ FLONG fl
Definition: winddi.h:1279
#define FD_ZERO(set)
Definition: winsock.h:96
#define FD_SET(fd, set)
Definition: winsock.h:89