ReactOS 0.4.15-dev-7931-gfd331f1
SSend.c File Reference
#include "syshdrs.h"
Include dependency graph for SSend.c:

Go to the source code of this file.

Functions

int SSend (int sfd, char *buf0, size_t size, int fl, int tlen)
 

Function Documentation

◆ SSend()

int SSend ( int  sfd,
char buf0,
size_t  size,
int  fl,
int  tlen 
)

Definition at line 90 of file SSend.c.

91{
92 int nleft;
93 char *buf = buf0;
94 int nwrote, tleft;
95 time_t done, now;
96 fd_set ss;
97 struct timeval tv;
98 int result;
99
100 nleft = (int) size;
101 time(&now);
102 done = now + tlen;
103 forever {
104 tleft = (int) (done - now);
105 if (tleft < 1) {
106 nwrote = size - nleft;
107 if (nwrote == 0) {
108 nwrote = kTimeoutErr;
111 }
112 goto done;
113 }
114
115
116 /* Unfortunately this doesn't help when the
117 * send buffer fills during the time we're
118 * writing to it, so you could still be
119 * blocked after breaking this loop and starting
120 * the write.
121 */
122
123 forever {
124 errno = 0;
125 FD_ZERO(&ss);
126 FD_SET(sfd, &ss);
127 tv.tv_sec = tlen;
128 tv.tv_usec = 0;
130 if (result == 1) {
131 /* ready */
132 break;
133 } else if (result == 0) {
134 /* timeout */
135 nwrote = size - nleft;
136 if (nwrote > 0)
137 return (nwrote);
140 return (kTimeoutErr);
141 } else if (errno != EINTR) {
142 return (-1);
143 }
144 }
145
146 nwrote = send(sfd, buf, size, fl);
147
148 if (nwrote < 0) {
149 if (errno != EINTR) {
150 nwrote = size - nleft;
151 if (nwrote == 0)
152 nwrote = -1;
153 goto done;
154 } else {
155 errno = 0;
156 nwrote = 0;
157 /* Try again. */
158 }
159 }
160 nleft -= nwrote;
161 if (nleft <= 0)
162 break;
163 buf += nwrote;
164 time(&now);
165 }
166 nwrote = size - nleft;
167
168done:
169 return (nwrote);
170} /* SSend */
#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 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 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