ReactOS 0.4.15-dev-7942-gd23573b
SWrite.c File Reference
#include "syshdrs.h"
Include dependency graph for SWrite.c:

Go to the source code of this file.

Functions

int SWrite (int sfd, const char *const buf0, size_t size, int tlen, int swopts)
 

Function Documentation

◆ SWrite()

int SWrite ( int  sfd,
const char *const  buf0,
size_t  size,
int  tlen,
int  swopts 
)

Definition at line 90 of file SWrite.c.

91{
92 int nleft;
93 const char *buf = buf0;
94 int nwrote, tleft;
95 time_t done, now;
96 fd_set ss;
97 struct timeval tv;
98 int result, firstWrite;
99
100 nleft = (int) size;
101 time(&now);
102 done = now + tlen;
103 firstWrite = 1;
104
105 forever {
106 tleft = (int) (done - now);
107 if (tleft < 1) {
108 nwrote = size - nleft;
109 if (nwrote == 0) {
110 nwrote = kTimeoutErr;
113 }
114 goto done;
115 }
116
117
118 /* Unfortunately this doesn't help when the
119 * send buffer fills during the time we're
120 * writing to it, so you could still be
121 * blocked after breaking this loop and starting
122 * the write.
123 */
124 if (!firstWrite || ((swopts & kNoFirstSelect) == 0)) {
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 nwrote = size - nleft;
138 if (nwrote > 0)
139 return (nwrote);
142 return (kTimeoutErr);
143 } else if (errno != EINTR) {
144 return (-1);
145 }
146 }
147 firstWrite = 0;
148 }
149
150#if defined(WIN32) || defined(_WINDOWS)
151 nwrote = send(sfd, buf, size, 0);
152#else
153 nwrote = write(sfd, buf, size);
154#endif
155
156 if (nwrote < 0) {
157 if (errno != EINTR) {
158 nwrote = size - nleft;
159 if (nwrote == 0)
160 nwrote = -1;
161 goto done;
162 } else {
163 errno = 0;
164 nwrote = 0;
165 /* Try again. */
166 }
167 }
168 nleft -= nwrote;
169 if (nleft <= 0)
170 break;
171 buf += nwrote;
172 time(&now);
173 }
174 nwrote = size - nleft;
175
176done:
177 return (nwrote);
178} /* SWrite */
#define EINTR
Definition: acclib.h:80
#define write
Definition: acwin.h:97
#define NULL
Definition: types.h:112
unsigned int(__cdecl typeof(jpeg_read_scanlines))(struct jpeg_decompress_struct *
Definition: typeof.h:31
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
INT WSAAPI send(IN SOCKET s, IN CONST CHAR FAR *buf, IN INT len, IN INT flags)
Definition: send.c:23
#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 SETWSATIMEOUTERR
Definition: sio.h:120
#define kNoFirstSelect
Definition: sio.h:52
#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 FTPPutOneF(), SendCommand(), and ServeOneClient().