ReactOS 0.4.16-dev-250-g3ecd236
sio.h File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  SelectSet
 
struct  SReadlineInfo
 

Macros

#define _SReadlineInfo_   1
 
#define forever   for ( ; ; )
 
#define SSetjmp(a)   setjmp(a)
 
#define SLongjmp(a, b)   longjmp(a, b)
 
#define Sjmp_buf   jmp_buf
 
#define kReUseAddrYes   1
 
#define kReUseAddrNo   0
 
#define kFullBufferNotRequired   00000
 
#define kFullBufferRequired   00001
 
#define kFullBufferRequiredExceptLast   00002
 
#define kNoFirstSelect   00010
 
#define kUseDNSYes   1
 
#define kUseDNSNo   0
 
#define kTimeoutErr   (-2)
 
#define kBrokenPipeErr   (-3)
 
#define kAddrStrToAddrMiscErr   (-4)
 
#define kAddrStrToAddrBadHost   (-5)
 
#define kSNewFailed   (-6)
 
#define kSBindFailed   (-7)
 
#define kSListenFailed   (-8)
 
#define kSrlBufSize   2048
 
#define kNoTimeLimit   0
 
#define NO_SIGNALS   1
 
#define SAccept   SAcceptS
 
#define closesocket   close
 
#define ioctlsocket   ioctl
 
#define SETERRNO
 
#define SETWSATIMEOUTERR
 
#define LIBSIO_USE_VAR(a)   gLibSio_Uses_Me_To_Quiet_Variable_Unused_Warnings = (a == 0)
 
#define UNUSED(a)   a
 

Typedefs

typedef struct SelectSet SelectSet
 
typedef struct SelectSetSelectSetPtr
 
typedef struct SReadlineInfo SReadlineInfo
 
typedef void(* sio_sigproc_t) (int)
 
typedef volatile sio_sigproc_t vsio_sigproc_t
 

Functions

int PRead (int, char *const, size_t, int)
 
int PWrite (int, const char *const, size_t)
 
int SAcceptA (int, struct sockaddr_in *const, int)
 
int SAcceptS (int, struct sockaddr_in *const, int)
 
int SBind (int, const int, const int, const int)
 
int SListen (int, int)
 
int SClose (int, int)
 
int SConnect (int, const struct sockaddr_in *const, int)
 
int SConnectByName (int, const char *const, const int)
 
int SNewStreamClient (void)
 
int SNewDatagramClient (void)
 
int SNewStreamServer (const int, const int, const int, int)
 
int SNewDatagramServer (const int, const int, const int)
 
int SRead (int, char *const, size_t, int, int)
 
void FlushSReadlineInfo (SReadlineInfo *)
 
int InitSReadlineInfo (SReadlineInfo *, int, char *, size_t, int, int)
 
void DisposeSReadlineInfo (SReadlineInfo *)
 
int SReadline (SReadlineInfo *, char *const, size_t)
 
int SRecv (int, char *const, size_t, int, int, int)
 
int SRecvfrom (int, char *const, size_t, int, struct sockaddr_in *const, int)
 
int SRecvmsg (int, void *const, int, int)
 
void SelectSetInit (SelectSetPtr const, const double)
 
void SelectSetAdd (SelectSetPtr const, const int)
 
void SelectSetRemove (SelectSetPtr const, const int)
 
int SelectW (SelectSetPtr, SelectSetPtr)
 
int SelectR (SelectSetPtr, SelectSetPtr)
 
int SSend (int, char *, size_t, int, int)
 
int SSendto (int, const char *const, size_t, int, const struct sockaddr_in *const, int)
 
int Sendto (int, const char *const, size_t, const struct sockaddr_in *const)
 
int SSendtoByName (int, const char *const, size_t, int, const char *const, int)
 
int SendtoByName (int, const char *const, size_t, const char *const)
 
int SWaitUntilReadyForReading (const int sfd, const int tlen)
 
int SWaitUntilReadyForWriting (const int sfd, const int tlen)
 
int SWrite (int, const char *const, size_t, int, int)
 
int GetSocketBufSize (int, size_t *const, size_t *const)
 
int SetSocketBufSize (int, size_t, size_t)
 
int GetSocketNagleAlgorithm (const int)
 
int SetSocketNagleAlgorithm (const int, const int)
 
int GetSocketLinger (const int, int *const)
 
int SetSocketLinger (const int, const int, const int)
 
int AddrStrToAddr (const char *const, struct sockaddr_in *const, const int)
 
charAddrToAddrStr (char *const dst, size_t dsize, struct sockaddr_in *const saddrp, int dns, const char *fmt)
 
const charSError (int e)
 
void SIOHandler (int)
 

Variables

int gLibSio_Uses_Me_To_Quiet_Variable_Unused_Warnings
 
void(*)(intSSignal (int signum, void(*handler)(int))
 

Macro Definition Documentation

◆ _SReadlineInfo_

#define _SReadlineInfo_   1

Definition at line 15 of file sio.h.

◆ closesocket

#define closesocket   close

Definition at line 108 of file sio.h.

◆ forever

#define forever   for ( ; ; )

Definition at line 30 of file sio.h.

◆ ioctlsocket

#define ioctlsocket   ioctl

Definition at line 112 of file sio.h.

◆ kAddrStrToAddrBadHost

#define kAddrStrToAddrBadHost   (-5)

Definition at line 62 of file sio.h.

◆ kAddrStrToAddrMiscErr

#define kAddrStrToAddrMiscErr   (-4)

Definition at line 61 of file sio.h.

◆ kBrokenPipeErr

#define kBrokenPipeErr   (-3)

Definition at line 59 of file sio.h.

◆ kFullBufferNotRequired

#define kFullBufferNotRequired   00000

Definition at line 49 of file sio.h.

◆ kFullBufferRequired

#define kFullBufferRequired   00001

Definition at line 50 of file sio.h.

◆ kFullBufferRequiredExceptLast

#define kFullBufferRequiredExceptLast   00002

Definition at line 51 of file sio.h.

◆ kNoFirstSelect

#define kNoFirstSelect   00010

Definition at line 52 of file sio.h.

◆ kNoTimeLimit

#define kNoTimeLimit   0

Definition at line 70 of file sio.h.

◆ kReUseAddrNo

#define kReUseAddrNo   0

Definition at line 46 of file sio.h.

◆ kReUseAddrYes

#define kReUseAddrYes   1

Definition at line 45 of file sio.h.

◆ kSBindFailed

#define kSBindFailed   (-7)

Definition at line 65 of file sio.h.

◆ kSListenFailed

#define kSListenFailed   (-8)

Definition at line 66 of file sio.h.

◆ kSNewFailed

#define kSNewFailed   (-6)

Definition at line 64 of file sio.h.

◆ kSrlBufSize

#define kSrlBufSize   2048

Definition at line 68 of file sio.h.

◆ kTimeoutErr

#define kTimeoutErr   (-2)

Definition at line 58 of file sio.h.

◆ kUseDNSNo

#define kUseDNSNo   0

Definition at line 56 of file sio.h.

◆ kUseDNSYes

#define kUseDNSYes   1

Definition at line 55 of file sio.h.

◆ LIBSIO_USE_VAR

#define LIBSIO_USE_VAR (   a)    gLibSio_Uses_Me_To_Quiet_Variable_Unused_Warnings = (a == 0)

Definition at line 140 of file sio.h.

◆ NO_SIGNALS

#define NO_SIGNALS   1

Definition at line 74 of file sio.h.

◆ SAccept

#define SAccept   SAcceptS

Definition at line 81 of file sio.h.

◆ SETERRNO

#define SETERRNO

Definition at line 119 of file sio.h.

◆ SETWSATIMEOUTERR

#define SETWSATIMEOUTERR

Definition at line 120 of file sio.h.

◆ Sjmp_buf

#define Sjmp_buf   jmp_buf

Definition at line 41 of file sio.h.

◆ SLongjmp

#define SLongjmp (   a,
  b 
)    longjmp(a, b)

Definition at line 40 of file sio.h.

◆ SSetjmp

#define SSetjmp (   a)    setjmp(a)

Definition at line 39 of file sio.h.

◆ UNUSED

#define UNUSED (   a)    a

Definition at line 142 of file sio.h.

Typedef Documentation

◆ SelectSet

◆ SelectSetPtr

◆ sio_sigproc_t

typedef void(* sio_sigproc_t) (int)

Definition at line 123 of file sio.h.

◆ SReadlineInfo

◆ vsio_sigproc_t

Definition at line 124 of file sio.h.

Function Documentation

◆ AddrStrToAddr()

int AddrStrToAddr ( const char * const  s,
struct sockaddr_in * const  sa,
const int  defaultport 
)

Definition at line 54 of file StrAddr.c.

55{
56 char portstr[128];
57 unsigned long ipnum;
58 unsigned int port;
59 struct hostent *hp;
60 char *hostcp, *atsign, *colon, *cp, *p2;
61
62 memset(sa, 0, sizeof(struct sockaddr_in));
63 strncpy(portstr, s, sizeof(portstr));
64 portstr[sizeof(portstr) - 1] = '\0';
65
66 if ((colon = strchr(portstr, ':')) != NULL) {
67 /* Does it look like a URL? http://host ? */
68 if ((colon[1] == '/') && (colon[2] == '/')) {
69 *colon = '\0';
70 port = 0;
71 hostcp = colon + 3;
72 for (cp = hostcp; *cp != '\0'; cp++) {
73 if ((!ISALNUM(*cp)) && (*cp != '.')) {
74 /* http://host:port */
75 if ((*cp == ':') && (isdigit(cp[1]))) {
76 *cp++ = '\0';
77 p2 = cp;
78 while (isdigit(*cp))
79 cp++;
80 *cp = '\0';
81 port = atoi(p2);
82 }
83 *cp = '\0';
84 break;
85 }
86 }
87 if (port == 0)
89 } else {
90 /* Look for host.name.domain:port */
91 *colon = '\0';
92 hostcp = portstr;
93 port = (unsigned int) atoi(colon + 1);
94 }
95 } else if ((atsign = strchr(portstr, '@')) != NULL) {
96 /* Look for port@host.name.domain */
97 *atsign = '\0';
98 hostcp = atsign + 1;
99 port = (unsigned int) atoi(portstr);
100 } else if (defaultport > 0) {
101 /* Have just host.name.domain, use that w/ default port. */
102 port = (unsigned int) defaultport;
103 hostcp = portstr;
104 } else {
105 /* If defaultport <= 0, they must supply a port number
106 * in the host/port string.
107 */
109 return (kAddrStrToAddrMiscErr);
110 }
111
112 sa->sin_port = htons((short) port);
113
114 ipnum = inet_addr(hostcp);
115 if (ipnum != INADDR_NONE) {
116 sa->sin_family = AF_INET;
117 sa->sin_addr.s_addr = ipnum;
118 } else {
119 errno = 0;
120 hp = gethostbyname(hostcp);
121 if (hp == NULL) {
122 if (errno == 0)
123 errno = ENOENT;
124 return (kAddrStrToAddrBadHost);
125 }
126 sa->sin_family = hp->h_addrtype;
127 memcpy(&sa->sin_addr.s_addr, hp->h_addr_list[0],
128 (size_t) hp->h_length);
129 }
130 return (0);
131} /* AddrStrToAddr */
#define INADDR_NONE
Definition: StrAddr.c:8
#define ISALNUM(c)
Definition: StrAddr.c:12
static unsigned int ServiceNameToPortNumber(const char *const s)
Definition: StrAddr.c:15
#define ENOENT
Definition: acclib.h:79
#define isdigit(c)
Definition: acclib.h:68
char * strncpy(char *DstString, const char *SrcString, ACPI_SIZE Count)
Definition: utclib.c:427
char * strchr(const char *String, int ch)
Definition: utclib.c:501
ULONG WSAAPI inet_addr(IN CONST CHAR FAR *cp)
Definition: addrconv.c:71
static struct sockaddr_in sa
Definition: adnsresfilter.c:69
#define NULL
Definition: types.h:112
USHORT port
Definition: uri.c:228
unsigned int(__cdecl typeof(jpeg_read_scanlines))(struct jpeg_decompress_struct *
Definition: typeof.h:31
#define EADDRNOTAVAIL
Definition: errno.h:110
#define AF_INET
Definition: tcpip.h:117
PHOSTENT WSAAPI gethostbyname(IN const char FAR *name)
Definition: getxbyxx.c:221
GLdouble s
Definition: gl.h:2039
_Check_return_ int __cdecl atoi(_In_z_ const char *_Str)
POINT cp
Definition: magnifier.c:59
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
#define htons(x)
Definition: module.h:215
#define kAddrStrToAddrBadHost
Definition: sio.h:62
#define kAddrStrToAddrMiscErr
Definition: sio.h:61
#define errno
Definition: errno.h:18
#define memset(x, y, z)
Definition: compat.h:39
short h_length
Definition: winsock.h:137
short h_addrtype
Definition: winsock.h:136
char ** h_addr_list
Definition: winsock.h:138

Referenced by SConnectByName(), SendtoByName(), and SSendtoByName().

◆ AddrToAddrStr()

char * AddrToAddrStr ( char *const  dst,
size_t  dsize,
struct sockaddr_in *const  saddrp,
int  dns,
const char fmt 
)

Definition at line 136 of file StrAddr.c.

137{
138 const char *addrNamePtr;
139 struct hostent *hp;
140 char str[128];
141 char *dlim, *dp;
142 const char *cp;
143 struct servent *pp;
144
145 if (dns == 0) {
146 addrNamePtr = inet_ntoa(saddrp->sin_addr);
147 } else {
148 hp = gethostbyaddr((char *) &saddrp->sin_addr, (int) sizeof(struct in_addr), AF_INET);
149 if ((hp != NULL) && (hp->h_name != NULL) && (hp->h_name[0] != '\0')) {
150 addrNamePtr = hp->h_name;
151 } else {
152 addrNamePtr = inet_ntoa(saddrp->sin_addr);
153 }
154 }
155 if (fmt == NULL)
156 fmt = "%h:%p";
157 for (dp = dst, dlim = dp + dsize - 1; ; fmt++) {
158 if (*fmt == '\0') {
159 break; /* done */
160 } else if (*fmt == '%') {
161 fmt++;
162 if (*fmt == '%') {
163 if (dp < dlim)
164 *dp++ = '%';
165 } else if (*fmt == 'p') {
166 sprintf(str, "%u", (unsigned int) ntohs(saddrp->sin_port));
167 for (cp = str; *cp != '\0'; cp++)
168 if (dp < dlim)
169 *dp++ = *cp;
170 *dp = '\0';
171 } else if (*fmt == 'h') {
172 if (addrNamePtr != NULL) {
173 cp = addrNamePtr;
174 } else {
175 cp = "unknown";
176 }
177 for ( ; *cp != '\0'; cp++)
178 if (dp < dlim)
179 *dp++ = *cp;
180 *dp = '\0';
181 } else if (*fmt == 's') {
182 pp = getservbyport((int) (saddrp->sin_port), "tcp");
183 if (pp == NULL)
184 pp = getservbyport((int) (saddrp->sin_port), "udp");
185 if (pp == NULL) {
186 sprintf(str, "%u", (unsigned int) ntohs(saddrp->sin_port));
187 cp = str;
188 } else {
189 cp = pp->s_name;
190 }
191 for ( ; *cp != '\0'; cp++)
192 if (dp < dlim)
193 *dp++ = *cp;
194 /* endservent(); */
195 *dp = '\0';
196 } else if ((*fmt == 't') || (*fmt == 'u')) {
197 pp = getservbyport((int) (saddrp->sin_port), (*fmt == 'u') ? "udp" : "tcp");
198 if (pp == NULL) {
199 sprintf(str, "%u", (unsigned int) ntohs(saddrp->sin_port));
200 cp = str;
201 } else {
202 cp = pp->s_name;
203 }
204 for ( ; *cp != '\0'; cp++)
205 if (dp < dlim)
206 *dp++ = *cp;
207 /* endservent(); */
208 *dp = '\0';
209 } else if (*fmt == '\0') {
210 break;
211 } else {
212 if (dp < dlim)
213 *dp++ = *fmt;
214 }
215 } else if (dp < dlim) {
216 *dp++ = *fmt;
217 }
218 }
219 *dp = '\0';
220 return (dst);
221} /* AddrToAddrStr */
CHAR FAR *WSAAPI inet_ntoa(IN IN_ADDR in)
Definition: addrconv.c:160
PSERVENT WSAAPI getservbyport(IN int port, IN const char FAR *proto)
Definition: getxbyxx.c:431
PHOSTENT WSAAPI gethostbyaddr(IN const char FAR *addr, IN int len, IN int type)
Definition: getxbyxx.c:309
GLenum GLenum dst
Definition: glext.h:6340
#define ntohs(x)
Definition: module.h:210
#define sprintf(buf, format,...)
Definition: sprintf.c:55
const WCHAR * str
Definition: dsound.c:943
char * h_name
Definition: winsock.h:134
Definition: tcpip.h:126
char * s_name
Definition: winsock.h:159
struct in_addr sin_addr
Definition: winsock.h:512
u_short sin_port
Definition: winsock.h:511

Referenced by ServeOneClient().

◆ DisposeSReadlineInfo()

void DisposeSReadlineInfo ( SReadlineInfo srl)

Definition at line 57 of file SReadline.c.

58{
59 memset(srl->buf, 0, srl->bufSizeMax);
60 if (srl->malloc != 0)
61 free(srl->buf);
62 memset(srl, 0, sizeof(SReadlineInfo));
63
64 /* Note: it does not close(srl->fd). */
65} /* DisposeSReadlineInfo */
#define free
Definition: debug_ros.c:5
size_t bufSizeMax
Definition: ncftp.h:105
char * buf
Definition: ncftp.h:101
int malloc
Definition: ncftp.h:106

Referenced by CloseControlConnection(), FTPDeallocateHost(), FTPList(), and FTPListToMemory2().

◆ FlushSReadlineInfo()

void FlushSReadlineInfo ( SReadlineInfo srl)

Definition at line 4 of file SReadline.c.

5{
6 /* Discards any input left in the current buffer,
7 * and resets the buffer and its pointer.
8 */
9 srl->bufSize = srl->bufSizeMax;
10 memset(srl->buf, 0, srl->bufSize);
11 srl->bufLim = srl->buf + srl->bufSizeMax;
12
13 /* This line sets the buffer pointer
14 * so that the first thing to do is reset and fill the buffer
15 * using real I/O.
16 */
17 srl->bufPtr = srl->bufLim;
18} /* FlushSReadlineInfo */
char * bufLim
Definition: ncftp.h:103
char * bufPtr
Definition: ncftp.h:102
size_t bufSize
Definition: ncftp.h:104

◆ GetSocketBufSize()

int GetSocketBufSize ( int  ,
size_t * const  ,
size_t * const   
)

◆ GetSocketLinger()

int GetSocketLinger ( const int  ,
int * const   
)

◆ GetSocketNagleAlgorithm()

int GetSocketNagleAlgorithm ( const int  )

◆ InitSReadlineInfo()

int InitSReadlineInfo ( SReadlineInfo srl,
int  fd,
char buf,
size_t  bsize,
int  tlen,
int  requireEOLN 
)

Definition at line 24 of file SReadline.c.

25{
26 if (buf == NULL) {
27 if (bsize < 512)
28 bsize = 512; /* Pointless, otherwise. */
29 buf = (char *) malloc(bsize);
30 if (buf == NULL)
31 return (-1);
32 srl->malloc = 1;
33 } else {
34 srl->malloc = 0;
35 }
36 memset(buf, 0, bsize);
37 srl->buf = buf;
38 srl->bufSize = bsize;
39 srl->bufSizeMax = bsize;
40 srl->bufLim = srl->buf + bsize;
41 srl->fd = fd;
42 srl->timeoutLen = tlen;
43 srl->requireEOLN = requireEOLN;
44
45 /* This line sets the buffer pointer
46 * so that the first thing to do is reset and fill the buffer
47 * using real I/O.
48 */
49 srl->bufPtr = srl->bufLim;
50 return (0);
51} /* InitSReadlineInfo */
#define malloc
Definition: debug_ros.c:4
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
static int fd
Definition: io.c:51
int timeoutLen
Definition: ncftp.h:108
int requireEOLN
Definition: ncftp.h:109

Referenced by FTPList(), FTPListToMemory2(), FTPRebuildConnectionInfo(), OpenControlConnection(), and ServeOneClient().

◆ PRead()

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

Definition at line 19 of file PRead.c.

20{
21 int nread;
22 volatile int nleft;
23 char *volatile buf = buf0;
24#if !defined(NO_SIGNALS) && defined(SIGPIPE)
25 vsio_sigproc_t sigpipe;
26
27 if (SSetjmp(gPipeJmp) != 0) {
28 (void) SSignal(SIGPIPE, (sio_sigproc_t) sigpipe);
29 nread = size - nleft;
30 if (nread > 0)
31 return (nread);
32 errno = EPIPE;
33 return (kBrokenPipeErr);
34 }
35
37#endif
38 errno = 0;
39
40 nleft = (int) size;
41 forever {
42 nread = read(sfd, buf, nleft);
43 if (nread <= 0) {
44 if (nread == 0) {
45 /* EOF */
46 nread = size - nleft;
47 goto done;
48 } else if (errno != EINTR) {
49 nread = size - nleft;
50 if (nread == 0)
51 nread = -1;
52 goto done;
53 } else {
54 errno = 0;
55 nread = 0;
56 /* Try again. */
57 }
58 }
59 nleft -= nread;
60 if ((nleft <= 0) || (retry == 0))
61 break;
62 buf += nread;
63 }
64 nread = size - nleft;
65
66done:
67#if !defined(NO_SIGNALS) && defined(SIGPIPE)
68 (void) SSignal(SIGPIPE, (sio_sigproc_t) sigpipe);
69#endif
70 return (nread);
71} /* PRead */
#define EINTR
Definition: acclib.h:80
#define EPIPE
Definition: acclib.h:91
#define read
Definition: acwin.h:96
#define SIGPIPE
Definition: signal.h:35
GLsizeiptr size
Definition: glext.h:5919
#define kBrokenPipeErr
Definition: sio.h:59
void SIOHandler(int)
#define SSetjmp(a)
Definition: sio.h:39
volatile sio_sigproc_t vsio_sigproc_t
Definition: sio.h:124
void(*)(int) SSignal(int signum, void(*handler)(int))
Definition: sio.h:237
void(* sio_sigproc_t)(int)
Definition: sio.h:123
#define forever
Definition: ncftp.h:73

◆ PWrite()

int PWrite ( int  sfd,
const char * const  buf0,
size_t  size 
)

Definition at line 7 of file PWrite.c.

8{
9 volatile int nleft;
10 const char *volatile buf = buf0;
11 int nwrote;
12#if !defined(NO_SIGNALS) && defined(SIGPIPE)
13 vsio_sigproc_t sigpipe;
14
15 if (SSetjmp(gPipeJmp) != 0) {
16 (void) SSignal(SIGPIPE, (sio_sigproc_t) sigpipe);
17 nwrote = size - nleft;
18 if (nwrote > 0)
19 return (nwrote);
20 errno = EPIPE;
21 return (kBrokenPipeErr);
22 }
23
25#endif
26
27 nleft = (int) size;
28 forever {
29 nwrote = write(sfd, buf, nleft);
30 if (nwrote < 0) {
31 if (errno != EINTR) {
32 nwrote = size - nleft;
33 if (nwrote == 0)
34 nwrote = -1;
35 goto done;
36 } else {
37 errno = 0;
38 nwrote = 0;
39 /* Try again. */
40 }
41 }
42 nleft -= nwrote;
43 if (nleft <= 0)
44 break;
45 buf += nwrote;
46 }
47 nwrote = size - nleft;
48
49done:
50#if !defined(NO_SIGNALS) && defined(SIGPIPE)
51 (void) SSignal(SIGPIPE, (sio_sigproc_t) sigpipe);
52#endif
53
54 return (nwrote);
55} /* PWrite */
#define write
Definition: acwin.h:97

◆ SAcceptA()

int SAcceptA ( int  sfd,
struct sockaddr_in * const  addr,
int  tlen 
)

Definition at line 9 of file SAcceptA.c.

10{
11 int result;
12#ifndef NO_SIGNALS
13 vsio_sigproc_t sigalrm, sigpipe;
14#endif
15 size_t size;
16
17 if (tlen < 0) {
18 errno = 0;
19 for (;;) {
20 size = sizeof(struct sockaddr_in);
21 result = accept(sfd, (struct sockaddr *) addr, (int *) &size);
22 if ((result >= 0) || (errno != EINTR))
23 return (result);
24 }
25 }
26#ifndef NO_SIGNALS
27 if (SSetjmp(gNetTimeoutJmp) != 0) {
28 alarm(0);
29 (void) SSignal(SIGALRM, (sio_sigproc_t) sigalrm);
30 (void) SSignal(SIGPIPE, (sio_sigproc_t) sigpipe);
32 return (kTimeoutErr);
33 }
34
35 sigalrm = (vsio_sigproc_t) SSignal(SIGALRM, SIOHandler);
37 alarm((unsigned int) tlen);
38
39 errno = 0;
40 do {
41 size = sizeof(struct sockaddr_in);
42 result = accept(sfd, (struct sockaddr *) addr, (int *) &size);
43 } while ((result < 0) && (errno == EINTR));
44
45 alarm(0);
46 (void) SSignal(SIGALRM, (sio_sigproc_t) sigalrm);
47 (void) SSignal(SIGPIPE, (sio_sigproc_t) sigpipe);
48 return (result);
49#else
50 return (-1);
51#endif
52} /* SAcceptA */
#define SIG_IGN
Definition: signal.h:48
#define ETIMEDOUT
Definition: errno.h:121
GLenum const GLvoid * addr
Definition: glext.h:9621
GLuint64EXT * result
Definition: glext.h:11304
#define kTimeoutErr
Definition: sio.h:58
SOCKET WSAAPI accept(IN SOCKET s, OUT LPSOCKADDR addr, OUT INT FAR *addrlen)
Definition: socklife.c:23

◆ SAcceptS()

int SAcceptS ( int  sfd,
struct sockaddr_in * const  addr,
int  tlen 
)

Definition at line 4 of file SAcceptS.c.

5{
6 int result;
8 struct timeval tv;
9 size_t size;
10
11 if (tlen <= 0) {
12 errno = 0;
13 for (;;) {
14 size = sizeof(struct sockaddr_in);
15 result = accept(sfd, (struct sockaddr *) addr, (int *) &size);
16 if ((result >= 0) || (errno != EINTR))
17 return (result);
18 }
19 }
20
21 forever {
22 errno = 0;
23 FD_ZERO(&ss);
24 FD_SET(sfd, &ss);
25 tv.tv_sec = tlen;
26 tv.tv_usec = 0;
28 if (result == 1) {
29 /* ready */
30 break;
31 } else if (result == 0) {
32 /* timeout */
35 return (kTimeoutErr);
36 } else if (errno != EINTR) {
37 return (-1);
38 }
39 }
40
41 do {
42 size = sizeof(struct sockaddr_in);
43 result = accept(sfd, (struct sockaddr *) addr, (int *) &size);
44 } while ((result < 0) && (errno == EINTR));
45
46 return (result);
47} /* SAcceptS */
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 ss
Definition: i386-dis.c:441
#define SELECT_TYPE_ARG234
Definition: wincfg.h:4
#define SELECT_TYPE_ARG5
Definition: wincfg.h:7
#define SETWSATIMEOUTERR
Definition: sio.h:120
Definition: winsock.h:66
#define FD_ZERO(set)
Definition: winsock.h:96
#define FD_SET(fd, set)
Definition: winsock.h:89

◆ SBind()

int SBind ( int  sockfd,
const int  port,
const int  nTries,
const int  reuseFlag 
)

Definition at line 4 of file SBind.c.

5{
6 unsigned int i;
7 int on;
8 int onsize;
9 struct sockaddr_in localAddr;
10
11 localAddr.sin_family = AF_INET;
12 localAddr.sin_addr.s_addr = htonl(INADDR_ANY);
13 localAddr.sin_port = htons((unsigned short) port);
14
15 if (reuseFlag != kReUseAddrNo) {
16 /* This is mostly so you can quit the server and re-run it
17 * again right away. If you don't do this, the OS may complain
18 * that the address is still in use.
19 */
20 on = 1;
21 onsize = (int) sizeof(on);
23 (char *) &on, onsize);
24
25#ifdef SO_REUSEPORT
26 /* Tells kernel that it's okay to have more
27 * than one process originating from this
28 * local port.
29 */
30 on = 1;
31 onsize = (int) sizeof(on);
32 (void) setsockopt(sockfd, SOL_SOCKET, SO_REUSEPORT,
33 (char *) &on, onsize);
34#endif /* SO_REUSEPORT */
35 }
36
37 for (i=1; ; i++) {
38 /* Try binding a few times, in case we get Address in Use
39 * errors.
40 */
41 if (bind(sockfd, (struct sockaddr *) &localAddr, sizeof(struct sockaddr_in)) == 0) {
42 break;
43 }
44 if ((int) i == nTries) {
45 return (-1);
46 }
47 /* Give the OS time to clean up the old socket,
48 * and then try again.
49 */
50 sleep(i * 3);
51 }
52
53 return (0);
54} /* SBind */
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
#define sleep
Definition: syshdrs.h:37
#define INADDR_ANY
Definition: inet.h:80
#define htonl(x)
Definition: module.h:214
#define kReUseAddrNo
Definition: sio.h:46
INT WSAAPI setsockopt(IN SOCKET s, IN INT level, IN INT optname, IN CONST CHAR FAR *optval, IN INT optlen)
Definition: sockctrl.c:421
INT WSAAPI bind(IN SOCKET s, IN CONST struct sockaddr *name, IN INT namelen)
Definition: socklife.c:36
short sin_family
Definition: winsock.h:510
#define SO_REUSEADDR
Definition: winsock.h:180
#define SOL_SOCKET
Definition: winsock.h:398

Referenced by SNewDatagramServer(), and SNewStreamServer().

◆ SClose()

int SClose ( int  sfd,
int  tlen 
)

Definition at line 9 of file SClose.c.

10{
11#ifndef NO_SIGNALS
12 vsio_sigproc_t sigalrm, sigpipe;
13
14 if (sfd < 0) {
15 errno = EBADF;
16 return (-1);
17 }
18
19 if (tlen < 1) {
20 /* Don't time it, shut it down now. */
21 if (SetSocketLinger(sfd, 0, 0) == 0) {
22 /* Linger disabled, so close()
23 * should not block.
24 */
25 return (closesocket(sfd));
26 } else {
27 /* This will result in a fd leak,
28 * but it's either that or hang forever.
29 */
30 return (shutdown(sfd, 2));
31 }
32 }
33
34 if (SSetjmp(gNetTimeoutJmp) != 0) {
35 alarm(0);
36 (void) SSignal(SIGALRM, (sio_sigproc_t) sigalrm);
37 (void) SSignal(SIGPIPE, (sio_sigproc_t) sigpipe);
38 if (SetSocketLinger(sfd, 0, 0) == 0) {
39 /* Linger disabled, so close()
40 * should not block.
41 */
42 return closesocket(sfd);
43 } else {
44 /* This will result in a fd leak,
45 * but it's either that or hang forever.
46 */
47 (void) shutdown(sfd, 2);
48 }
49 return (-1);
50 }
51
52 sigalrm = (vsio_sigproc_t) SSignal(SIGALRM, SIOHandler);
54
55 alarm((unsigned int) tlen);
56 for (;;) {
57 if (closesocket(sfd) == 0) {
58 errno = 0;
59 break;
60 }
61 if (errno != EINTR)
62 break;
63 }
64 alarm(0);
65 (void) SSignal(SIGALRM, (sio_sigproc_t) sigalrm);
66
67 if ((errno != 0) && (errno != EBADF)) {
68 if (SetSocketLinger(sfd, 0, 0) == 0) {
69 /* Linger disabled, so close()
70 * should not block.
71 */
72 (void) closesocket(sfd);
73 } else {
74 /* This will result in a fd leak,
75 * but it's either that or hang forever.
76 */
77 (void) shutdown(sfd, 2);
78 }
79 }
80 (void) SSignal(SIGPIPE, (sio_sigproc_t) sigpipe);
81
82 return ((errno == 0) ? 0 : (-1));
83#else
84 struct timeval tv;
85 int result;
86 time_t done, now;
87 fd_set ss;
88
89 if (sfd < 0) {
90 errno = EBADF;
91 return (-1);
92 }
93
94 if (tlen < 1) {
95 /* Don't time it, shut it down now. */
96 if (SetSocketLinger(sfd, 0, 0) == 0) {
97 /* Linger disabled, so close()
98 * should not block.
99 */
100 return (closesocket(sfd));
101 } else {
102 /* This will result in a fd leak,
103 * but it's either that or hang forever.
104 */
105 return (shutdown(sfd, 2));
106 }
107 }
108
109 /* Wait until the socket is ready for writing (usually easy). */
110 time(&now);
111 done = now + tlen;
112
113 forever {
114 tlen = done - now;
115 if (tlen <= 0) {
116 /* timeout */
117 if (SetSocketLinger(sfd, 0, 0) == 0) {
118 /* Linger disabled, so close()
119 * should not block.
120 */
121 (void) closesocket(sfd);
122 } else {
123 /* This will result in a fd leak,
124 * but it's either that or hang forever.
125 */
126 (void) shutdown(sfd, 2);
127 }
129 return (kTimeoutErr);
130 }
131
132 errno = 0;
133 FD_ZERO(&ss);
134 FD_SET(sfd, &ss);
135 tv.tv_sec = tlen;
136 tv.tv_usec = 0;
138 if (result == 1) {
139 /* ready */
140 break;
141 } else if (result == 0) {
142 /* timeout */
143 if (SetSocketLinger(sfd, 0, 0) == 0) {
144 /* Linger disabled, so close()
145 * should not block.
146 */
147 (void) closesocket(sfd);
148 } else {
149 /* This will result in a fd leak,
150 * but it's either that or hang forever.
151 */
152 (void) shutdown(sfd, 2);
153 }
155 return (kTimeoutErr);
156 } else if (errno != EINTR) {
157 /* Error, done. This end may have been shutdown. */
158 break;
159 }
160 time(&now);
161 }
162
163 /* Wait until the socket is ready for reading. */
164 forever {
165 tlen = done - now;
166 if (tlen <= 0) {
167 /* timeout */
168 if (SetSocketLinger(sfd, 0, 0) == 0) {
169 /* Linger disabled, so close()
170 * should not block.
171 */
172 (void) closesocket(sfd);
173 } else {
174 /* This will result in a fd leak,
175 * but it's either that or hang forever.
176 */
177 (void) shutdown(sfd, 2);
178 }
180 return (kTimeoutErr);
181 }
182
183 errno = 0;
184 FD_ZERO(&ss);
185 FD_SET(sfd, &ss);
186 tv.tv_sec = tlen;
187 tv.tv_usec = 0;
189 if (result == 1) {
190 /* ready */
191 break;
192 } else if (result == 0) {
193 /* timeout */
194 if (SetSocketLinger(sfd, 0, 0) == 0) {
195 /* Linger disabled, so close()
196 * should not block.
197 */
198 (void) closesocket(sfd);
199 } else {
200 /* This will result in a fd leak,
201 * but it's either that or hang forever.
202 */
203 (void) shutdown(sfd, 2);
204 }
206 return (kTimeoutErr);
207 } else if (errno != EINTR) {
208 /* Error, done. This end may have been shutdown. */
209 break;
210 }
211 time(&now);
212 }
213
214 /* If we get here, close() won't block. */
215 return closesocket(sfd);
216#endif
217} /* SClose */
#define EBADF
Definition: acclib.h:82
__kernel_time_t time_t
Definition: linux.h:252
time_t now
Definition: finger.c:65
__u16 time
Definition: mkdosfs.c:8
int SetSocketLinger(const int, const int, const int)
#define closesocket
Definition: ncftp.h:477
INT WSAAPI shutdown(IN SOCKET s, IN INT how)
Definition: sockctrl.c:506

Referenced by CloseControlConnection(), CloseDataConnection(), OpenControlConnection(), and ServeOneClient().

◆ SConnect()

int SConnect ( int  sfd,
const struct sockaddr_in * const  addr,
int  tlen 
)

Definition at line 9 of file SConnect.c.

10{
11#ifndef NO_SIGNALS
12 int result;
13 vsio_sigproc_t sigalrm;
14
15 if (SSetjmp(gNetTimeoutJmp) != 0) {
16 alarm(0);
17 (void) SSignal(SIGALRM, (sio_sigproc_t) sigalrm);
19 return (kTimeoutErr);
20 }
21
22 sigalrm = (vsio_sigproc_t) SSignal(SIGALRM, SIOHandler);
23 alarm((unsigned int) tlen);
24
25 errno = 0;
26 do {
27 result = connect(sfd, (struct sockaddr *) addr,
28 (int) sizeof(struct sockaddr_in));
29 } while ((result < 0) && (errno == EINTR));
30
31 alarm(0);
32 (void) SSignal(SIGALRM, (sio_sigproc_t) sigalrm);
33 return (result);
34#else /* NO_SIGNALS */
35 unsigned long opt;
36 fd_set ss, xx;
37 struct timeval tv;
38 int result;
39 int cErrno;
40#if defined(WIN32) || defined(_WINDOWS)
41 int wsaErrno;
42 int soerr, soerrsize;
43#else
44 int optval;
45 int optlen;
46#endif
47
48 errno = 0;
49 if (tlen <= 0) {
50 do {
51 result = connect(sfd, (struct sockaddr *) addr,
52 (int) sizeof(struct sockaddr_in));
54 } while ((result < 0) && (errno == EINTR));
55 return (result);
56 }
57
58#ifdef FIONBIO
59 opt = 1;
60 if (ioctlsocket(sfd, FIONBIO, &opt) != 0) {
62 return (-1);
63 }
64#else
65 if (fcntl(sfd, F_GETFL, &opt) < 0) {
67 return (-1);
68 } else if (fcntl(sfd, F_SETFL, opt | O_NONBLOCK) < 0) {
70 return (-1);
71 }
72#endif
73
74 errno = 0;
75 result = connect(sfd, (struct sockaddr *) addr,
76 (int) sizeof(struct sockaddr_in));
77 if (result == 0)
78 return 0; /* Already?!? */
79
80 if ((result < 0)
81#if defined(WIN32) || defined(_WINDOWS)
82 && ((wsaErrno = WSAGetLastError()) != WSAEWOULDBLOCK)
83 && (wsaErrno != WSAEINPROGRESS)
84#else
85 && (errno != EWOULDBLOCK) && (errno != EINPROGRESS)
86#endif
87 ) {
89 shutdown(sfd, 2);
90 return (-1);
91 }
92 cErrno = errno;
93
94 forever {
95#if defined(WIN32) || defined(_WINDOWS)
97#endif
98 FD_ZERO(&ss);
99 FD_SET(sfd, &ss);
100 xx = ss;
101 tv.tv_sec = tlen;
102 tv.tv_usec = 0;
104 if (result == 1) {
105 /* ready */
106 break;
107 } else if (result == 0) {
108 /* timeout */
111 /* Don't bother turning off FIONBIO */
112 return (kTimeoutErr);
113 } else if (errno != EINTR) {
114 /* Don't bother turning off FIONBIO */
116 return (-1);
117 }
118 }
119
120 /* Supposedly once the select() returns with a writable
121 * descriptor, it is connected and we don't need to
122 * recall connect(). When select() returns an exception,
123 * the connection failed -- we can get the connect error
124 * doing a write on the socket which will err out.
125 */
126
127 if (FD_ISSET(sfd, &xx)) {
128#if defined(WIN32) || defined(_WINDOWS)
129 errno = 0;
130 soerr = 0;
131 soerrsize = sizeof(soerr);
132 result = getsockopt(sfd, SOL_SOCKET, SO_ERROR, (char *) &soerr, &soerrsize);
133 if ((result >= 0) && (soerr != 0)) {
134 errno = soerr;
135 } else {
136 errno = 0;
137 (void) send(sfd, "\0", 1, 0);
139 }
140#else
141 errno = 0;
142 (void) send(sfd, "\0", 1, 0);
143#endif
144 result = errno;
145 shutdown(sfd, 2);
146 errno = result;
147 return (-1);
148 }
149
150#if defined(WIN32) || defined(_WINDOWS)
151#else
152 if (cErrno == EINPROGRESS) {
153 /*
154 * [from Linux connect(2) page]
155 *
156 * EINPROGRESS
157 *
158 * The socket is non-blocking and the connection can­
159 * not be completed immediately. It is possible to
160 * select(2) or poll(2) for completion by selecting
161 * the socket for writing. After select indicates
162 * writability, use getsockopt(2) to read the
163 * SO_ERROR option at level SOL_SOCKET to determine
164 * whether connect completed successfully (SO_ERROR
165 * is zero) or unsuccessfully (SO_ERROR is one of the
166 * usual error codes listed above, explaining the
167 * reason for the failure).
168 */
169 optval = 0;
170 optlen = sizeof(optval);
171 if (getsockopt(sfd, SOL_SOCKET, SO_ERROR, &optval, &optlen) == 0) {
172 errno = optval;
173 if (errno != 0)
174 return (-1);
175 }
176 }
177#endif
178
179#ifdef FIONBIO
180 opt = 0;
181 if (ioctlsocket(sfd, FIONBIO, &opt) != 0) {
183 shutdown(sfd, 2);
184 return (-1);
185 }
186#else
187 if (fcntl(sfd, F_SETFL, opt) < 0) {
189 shutdown(sfd, 2);
190 return (-1);
191 }
192#endif
193
194 return (0);
195#endif /* NO_SIGNALS */
196} /* SConnect */
VOID WSAAPI WSASetLastError(IN INT iError)
Definition: dllmain.c:123
INT WSAAPI send(IN SOCKET s, IN CONST CHAR FAR *buf, IN INT len, IN INT flags)
Definition: send.c:23
#define EWOULDBLOCK
Definition: errno.h:42
#define EINPROGRESS
Definition: errno.h:126
#define SETERRNO
Definition: sio.h:119
#define O_NONBLOCK
Definition: port.h:158
#define ioctlsocket
Definition: ncftp.h:481
int xx
Definition: npserver.c:29
INT WSAAPI getsockopt(IN SOCKET s, IN INT level, IN INT optname, OUT CHAR FAR *optval, IN OUT INT FAR *optlen)
Definition: sockctrl.c:271
#define WIN32
Definition: windef.h:30
#define WSAEWOULDBLOCK
Definition: winerror.h:1948
#define WSAEINPROGRESS
Definition: winerror.h:1949
#define SO_ERROR
Definition: winsock.h:194
#define FD_ISSET(fd, set)
Definition: winsock.h:100
int PASCAL FAR WSAGetLastError(void)
Definition: dllmain.c:112
#define FIONBIO
Definition: winsock.h:149

Referenced by OpenControlConnection(), OpenDataConnection(), and SConnectByName().

◆ SConnectByName()

int SConnectByName ( int  sfd,
const char * const  addrStr,
const int  tlen 
)

Definition at line 4 of file SConnectByName.c.

5{
6 int result;
7 struct sockaddr_in remoteAddr;
8
9 if ((result = AddrStrToAddr(addrStr, &remoteAddr, -1)) == 0) {
10 result = SConnect(sfd, &remoteAddr, tlen);
11 }
12 return (result);
13} /* SConnectByName */
int SConnect(int sfd, const struct sockaddr_in *const addr, int tlen)
Definition: SConnect.c:9
int AddrStrToAddr(const char *const, struct sockaddr_in *const, const int)
Definition: StrAddr.c:54

◆ SelectR()

int SelectR ( SelectSetPtr  ssp,
SelectSetPtr  resultssp 
)

Definition at line 65 of file SSelect.c.

66{
67 int rc;
68
69 do {
70 memcpy(resultssp, ssp, sizeof(SelectSet));
71 rc = select(resultssp->maxfd, SELECT_TYPE_ARG234 &resultssp->fds, NULL, NULL, SELECT_TYPE_ARG5 &resultssp->timeout);
72 } while ((rc < 0) && (errno == EINTR));
73 return (rc);
74} /* SelectR */
Definition: sio.h:6
struct timeval timeout
Definition: sio.h:8
int maxfd
Definition: sio.h:9
fd_set fds
Definition: sio.h:7

◆ SelectSetAdd()

void SelectSetAdd ( SelectSetPtr const  ssp,
const int  fd 
)

Definition at line 23 of file SSelect.c.

24{
25 if (fd >= 0) {
26 FD_SET(fd, &ssp->fds);
27 if (ssp->maxfd < (fd + 1))
28 ssp->maxfd = (fd + 1);
29 ++ssp->numfds;
30 }
31} /* SelectSetAdd */

◆ SelectSetInit()

void SelectSetInit ( SelectSetPtr const  ssp,
const double  timeout 
)

Definition at line 4 of file SSelect.c.

5{
6 double i;
7 long l;
8
9 /* Inititalize SelectSet, which will clear the fd_set, the
10 * timeval, and the maxfd and numfds to 0.
11 */
12 memset(ssp, 0, sizeof(SelectSet));
13 l = (long) timeout;
14 i = (double) l;
15 ssp->timeout.tv_sec = l;
16 ssp->timeout.tv_usec = (long) ((timeout - i) * 1000000.0);
17} /* SelectSetInit */
r l[0]
Definition: byte_order.h:168
static const char mbstate_t *static wchar_t const char mbstate_t *static const wchar_t int *static double
Definition: string.c:80
#define long
Definition: qsort.c:33
Definition: dhcpd.h:245

◆ SelectSetRemove()

void SelectSetRemove ( SelectSetPtr const  ssp,
const int  fd 
)

Definition at line 37 of file SSelect.c.

38{
39 if ((fd >= 0) && (FD_ISSET(fd, &ssp->fds))) {
40 FD_CLR(fd, &ssp->fds);
41 /* Note that maxfd is left alone, even if maxfd was
42 * this one. That is okay.
43 */
44 --ssp->numfds;
45 }
46} /* SelectSetRemove */
#define FD_CLR(fd, set)
Definition: winsock.h:74

◆ SelectW()

int SelectW ( SelectSetPtr  ssp,
SelectSetPtr  resultssp 
)

Definition at line 51 of file SSelect.c.

52{
53 int rc;
54
55 do {
56 memcpy(resultssp, ssp, sizeof(SelectSet));
57 rc = select(resultssp->maxfd, NULL, SELECT_TYPE_ARG234 &resultssp->fds, NULL, SELECT_TYPE_ARG5 &resultssp->timeout);
58 } while ((rc < 0) && (errno == EINTR));
59 return (rc);
60} /* SelectW */

◆ Sendto()

int Sendto ( int  sfd,
const char * const  buf,
size_t  size,
const struct sockaddr_in * const  toAddr 
)

Definition at line 127 of file SSendto.c.

128{
129 int result;
130
131 do {
132 result = sendto(sfd, buf, size, 0,
133 (struct sockaddr *) toAddr,
134 (int) sizeof(struct sockaddr_in));
135 } while ((result < 0) && (errno == EINTR));
136 return (result);
137} /* Sendto */
INT WSAAPI sendto(IN SOCKET s, IN CONST CHAR FAR *buf, IN INT len, IN INT flags, IN CONST struct sockaddr *to, IN INT tolen)
Definition: send.c:82

◆ SendtoByName()

int SendtoByName ( int  sfd,
const char * const  buf,
size_t  size,
const char * const  toAddrStr 
)

Definition at line 133 of file SSendtoByName.c.

134{
135 int result;
136 struct sockaddr_in toAddr;
137
138 if ((result = AddrStrToAddr(toAddrStr, &toAddr, -1)) < 0) {
139 return (result);
140 }
141
142 do {
143 result = sendto(sfd, buf, size, 0,
144 (struct sockaddr *) &toAddr,
145 (int) sizeof(struct sockaddr_in));
146 } while ((result < 0) && (errno == EINTR));
147
148 return (result);
149} /* SendtoByName */

◆ SError()

const char * SError ( int  e)

Definition at line 141 of file SError.c.

142{
143#if defined(WIN32) || defined(_WINDOWS)
144 const char *cp;
145 static char estr[32];
146
147 if (e == 0)
148 e = WSAGetLastError();
149
150 if ((e >= WSABASEERR) && (e < (WSABASEERR + (sizeof(wsaerrlist) / sizeof(const char *))))) {
151 return wsaerrlist[e - WSABASEERR];
152 }
153
154 cp = strerror(e);
155 if ((cp == NULL) || (cp[0] == '\0') || (strcmp(cp, "Unknown error") == 0)) {
156 wsprintf(estr, "Error #%d", e);
157 cp = estr;
158 }
159 return cp;
160#elif defined(HAVE_STRERROR)
161 if (e == 0)
162 e = errno;
163 return strerror(e);
164#else
165 static char estr[32];
166 if (e == 0)
167 e = errno;
168 sprintf(estr, "Error #%d", e);
169 return (estr);
170#endif
171} /* SError */
int strcmp(const char *String1, const char *String2)
Definition: utclib.c:469
#define e
Definition: ke_i.h:82
const char * strerror(int err)
Definition: compat_str.c:23
#define WSABASEERR
Definition: winerror.h:1941
#define wsprintf
Definition: winuser.h:5877

Referenced by UniataAhciStart(), UniataAhciStatus(), UniataAhciWaitCommandReady(), and UniataSataClearErr().

◆ SetSocketBufSize()

int SetSocketBufSize ( int  ,
size_t  ,
size_t   
)

◆ SetSocketLinger()

int SetSocketLinger ( const int  ,
const int  ,
const int   
)

Referenced by SClose().

◆ SetSocketNagleAlgorithm()

int SetSocketNagleAlgorithm ( const int  ,
const int   
)

◆ SIOHandler()

void SIOHandler ( int  )

◆ SListen()

int SListen ( int  sfd,
int  backlog 
)

Definition at line 60 of file SBind.c.

61{
62 return (listen(sfd, (unsigned int) backlog));
63} /* SListen */
INT WSAAPI listen(IN SOCKET s, IN INT backlog)
Definition: sockctrl.c:123

Referenced by SNewStreamServer().

◆ SNewDatagramClient()

int SNewDatagramClient ( void  )

Definition at line 19 of file SNew.c.

20{
21 int sfd;
22
23 sfd = socket(AF_INET, SOCK_DGRAM, 0);
24 if (sfd < 0)
25 return kSNewFailed;
26
27 return (sfd);
28} /* SNewDatagramClient */
#define kSNewFailed
Definition: sio.h:64
SOCKET WSAAPI socket(IN INT af, IN INT type, IN INT protocol)
Definition: socklife.c:143
#define SOCK_DGRAM
Definition: winsock.h:336

◆ SNewDatagramServer()

int SNewDatagramServer ( const int  port,
const int  nTries,
const int  reuseFlag 
)

Definition at line 64 of file SNew.c.

65{
66 int oerrno;
67 int sfd;
68
69 sfd = socket(AF_INET, SOCK_DGRAM, 0);
70 if (sfd < 0)
71 return kSNewFailed;
72
73 if (SBind(sfd, port, nTries, reuseFlag) < 0) {
74 oerrno = errno;
75 (void) closesocket(sfd);
76 errno = oerrno;
77 return kSBindFailed;
78 }
79
80 return (sfd);
81} /* SNewDatagramServer */
int SBind(int sockfd, const int port, const int nTries, const int reuseFlag)
Definition: SBind.c:4
#define kSBindFailed
Definition: sio.h:65

◆ SNewStreamClient()

int SNewStreamClient ( void  )

Definition at line 4 of file SNew.c.

5{
6 int sfd;
7
8 sfd = socket(AF_INET, SOCK_STREAM, 0);
9 if (sfd < 0)
10 return kSNewFailed;
11
12 return (sfd);
13} /* SNewStreamClient */
#define SOCK_STREAM
Definition: tcpip.h:118

◆ SNewStreamServer()

int SNewStreamServer ( const int  port,
const int  nTries,
const int  reuseFlag,
int  listenQueueSize 
)

Definition at line 34 of file SNew.c.

35{
36 int oerrno;
37 int sfd;
38
39 sfd = socket(AF_INET, SOCK_STREAM, 0);
40 if (sfd < 0)
41 return kSNewFailed;
42
43 if (SBind(sfd, port, nTries, reuseFlag) < 0) {
44 oerrno = errno;
45 (void) closesocket(sfd);
46 errno = oerrno;
47 return kSBindFailed;
48 }
49
50 if (SListen(sfd, listenQueueSize) < 0) {
51 oerrno = errno;
52 (void) closesocket(sfd);
53 errno = oerrno;
54 return kSListenFailed;
55 }
56
57 return (sfd);
58} /* SNewStreamServer */
int SListen(int sfd, int backlog)
Definition: SBind.c:60
#define kSListenFailed
Definition: sio.h:66

Referenced by Server().

◆ 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 */
INT WSAAPI recv(IN SOCKET s, OUT CHAR FAR *buf, IN INT len, IN INT flags)
Definition: recv.c:23
char gNoSignalsMarker[]
Definition: ftp.c:14
#define kFullBufferRequired
Definition: sio.h:50
#define kFullBufferRequiredExceptLast
Definition: sio.h:51
#define kNoFirstSelect
Definition: sio.h:52
#define LIBSIO_USE_VAR(a)
Definition: sio.h:140

Referenced by FTPGetOneF(), and SReadline().

◆ SReadline()

int SReadline ( SReadlineInfo srl,
char * const  linebuf,
size_t  linebufsize 
)

Definition at line 76 of file SReadline.c.

77{
78 int err;
79 char *src;
80 char *dst;
81 char *dstlim;
82 int len;
83 int nr;
84 int requireEOLN;
85 int illegals;
86
87 illegals = 0;
88 err = 0;
89 dst = linebuf;
90 dstlim = dst + linebufsize - 1; /* Leave room for NUL. */
91 src = srl->bufPtr;
92 requireEOLN = srl->requireEOLN;
93 if (requireEOLN)
94 dstlim--;
95 if (dstlim <= dst)
96 return (-1); /* Buffer too small. */
97
98 forever {
99 if ((requireEOLN == 0) && (dst >= dstlim))
100 break;
101 if (src >= srl->bufLim) {
102 /* Fill the buffer. */
103 if (illegals > 1) {
104 /* Probable DOS -- return now and give you an
105 * opportunity to handle bogus input.
106 */
107 goto done;
108 }
109 nr = SRead(srl->fd, srl->buf, srl->bufSizeMax, srl->timeoutLen, 0);
110 if (nr == 0) {
111 /* EOF. */
112 goto done;
113 } else if (nr < 0) {
114 /* Error. */
115 err = nr;
116 goto done;
117 }
118 srl->bufPtr = src = srl->buf;
119 srl->bufLim = srl->buf + nr;
120 }
121 if (*src == '\0') {
122 ++src;
123 illegals++;
124 } else if (*src == '\r') {
125 ++src;
126 /* If the next character is a \n that is valid,
127 * otherwise treat a stray \r as an illegal character.
128 */
129 if ((src < srl->bufLim) && (*src != '\n'))
130 illegals++;
131 } else {
132 if (*src == '\n') {
133 if (dst < dstlim)
134 *dst++ = *src++;
135 else
136 src++;
137 goto done;
138 }
139 if (dst < dstlim)
140 *dst++ = *src++;
141 else
142 src++;
143 }
144 }
145
146done:
147 srl->bufPtr = src;
148 if ((requireEOLN != 0) && (dst != linebuf) && (dst[-1] != '\n'))
149 *dst++ = '\n';
150 if ((requireEOLN != 0) && (dst == linebuf) && (illegals > 0))
151 *dst++ = '\n';
152 *dst = '\0';
153 len = (int) (dst - linebuf);
154 if (err < 0)
155 return (err);
156 return (len);
157} /* SReadline */
GLenum src
Definition: glext.h:6340
GLenum GLsizei len
Definition: glext.h:6722
int SRead(int, char *const, size_t, int, int)
Definition: SRead.c:118
ULONG nr
Definition: thread.c:7
#define err(...)

Referenced by FTPList(), FTPListToMemory2(), GetResponse(), and ServeOneClient().

◆ 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 kFullBufferNotRequired
Definition: sio.h:49
_In_ FLONG fl
Definition: winddi.h:1279

◆ SRecvfrom()

int SRecvfrom ( int  sfd,
char * const  buf,
size_t  size,
int  fl,
struct sockaddr_in * const  fromAddr,
int  tlen 
)

Definition at line 69 of file SRecvfrom.c.

70{
71 int nread, tleft;
72 fd_set ss;
73 struct timeval tv;
74 int result;
75 time_t done, now;
76 int alen;
77
78 time(&now);
79 done = now + tlen;
80 tleft = (int) (done - now);
81 nread = 0;
82 forever {
83 alen = sizeof(struct sockaddr_in);
84
85 forever {
86 errno = 0;
87 FD_ZERO(&ss);
88 FD_SET(sfd, &ss);
89 tv.tv_sec = tleft;
90 tv.tv_usec = 0;
92 if (result == 1) {
93 /* ready */
94 break;
95 } else if (result == 0) {
96 /* timeout */
99 return (kTimeoutErr);
100 } else if (errno != EINTR) {
101 return (-1);
102 }
103 }
104
105 nread = recvfrom(sfd, buf, size, fl,
106 (struct sockaddr *) fromAddr, &alen);
107
108 if (nread >= 0)
109 break;
110 if (errno != EINTR)
111 break; /* Fatal error. */
112 errno = 0;
113 time(&now);
114 tleft = (int) (done - now);
115 if (tleft < 1) {
116 nread = kTimeoutErr;
119 break;
120 }
121 }
122
123 return (nread);
124} /* SRecvfrom */
INT WSAAPI recvfrom(IN SOCKET s, OUT CHAR FAR *buf, IN INT len, IN INT flags, OUT LPSOCKADDR from, IN OUT INT FAR *fromlen)
Definition: recv.c:87

◆ SRecvmsg()

int SRecvmsg ( int  ,
void * const  ,
int  ,
int   
)

◆ 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 */

◆ SSendto()

int SSendto ( int  sfd,
const char * const  buf,
size_t  size,
int  fl,
const struct sockaddr_in * const  toAddr,
int  tlen 
)

Definition at line 68 of file SSendto.c.

69{
70 int nwrote, tleft;
71 time_t done, now;
72 fd_set ss;
73 struct timeval tv;
74 int result;
75
76 time(&now);
77 done = now + tlen;
78 nwrote = 0;
79 forever {
80 forever {
81 if (now >= done) {
84 return (kTimeoutErr);
85 }
86 tleft = (int) (done - now);
87 errno = 0;
88 FD_ZERO(&ss);
89 FD_SET(sfd, &ss);
90 tv.tv_sec = tleft;
91 tv.tv_usec = 0;
93 if (result == 1) {
94 /* ready */
95 break;
96 } else if (result == 0) {
97 /* timeout */
100 return (kTimeoutErr);
101 } else if (errno != EINTR) {
102 return (-1);
103 }
104 time(&now);
105 }
106
107 nwrote = sendto(sfd, buf, size, fl,
108 (struct sockaddr *) toAddr,
109 (int) sizeof(struct sockaddr_in));
110
111 if (nwrote >= 0)
112 break;
113 if (errno != EINTR)
114 break; /* Fatal error. */
115 }
116
117 return (nwrote);
118} /* SSendto */

◆ SSendtoByName()

int SSendtoByName ( int  sfd,
const char * const  buf,
size_t  size,
int  fl,
const char * const  toAddrStr,
int  tlen 
)

Definition at line 73 of file SSendtoByName.c.

74{
75 int nwrote, tleft;
76 time_t done, now;
77 fd_set ss;
78 struct timeval tv;
79 int result;
80 struct sockaddr_in toAddr;
81
82 if ((result = AddrStrToAddr(toAddrStr, &toAddr, -1)) < 0) {
83 return (result);
84 }
85
86 time(&now);
87 done = now + tlen;
88 nwrote = 0;
89 forever {
90 forever {
91 if (now >= done) {
93 return (kTimeoutErr);
94 }
95 tleft = (int) (done - now);
96 errno = 0;
97 FD_ZERO(&ss);
98 FD_SET(sfd, &ss);
99 tv.tv_sec = tleft;
100 tv.tv_usec = 0;
102 if (result == 1) {
103 /* ready */
104 break;
105 } else if (result == 0) {
106 /* timeout */
108 return (kTimeoutErr);
109 } else if (errno != EINTR) {
110 return (-1);
111 }
112 time(&now);
113 }
114
115 nwrote = sendto(sfd, buf, size, fl,
116 (struct sockaddr *) &toAddr,
117 (int) sizeof(struct sockaddr_in));
118
119 if (nwrote >= 0)
120 break;
121 if (errno != EINTR)
122 break; /* Fatal error. */
123 }
124
125 return (nwrote);
126} /* SSendto */

◆ SWaitUntilReadyForReading()

int SWaitUntilReadyForReading ( const int  sfd,
const int  tlen 
)

Definition at line 7 of file SWait.c.

8{
9 fd_set ss, ss2;
10 struct timeval tv;
11 int result;
12 int tleft;
13 time_t now, done;
14
15 if (sfd < 0) {
16 errno = EBADF;
17 return (0);
18 }
19
20 time(&now);
21 done = now + tlen;
22 tleft = tlen;
23
24 forever {
25 FD_ZERO(&ss);
26 FD_SET(sfd, &ss);
27 ss2 = ss;
28 tv.tv_sec = tleft;
29 tv.tv_usec = 0;
31 if (result == 1) {
32 /* ready */
33 return (1);
34 } else if (result < 0) {
35 if (errno != EINTR) {
36 /* error */
37 return (0);
38 }
39 /* try again */
40 time(&now);
41 if (now > done) {
42 /* timed-out */
44 return (0);
45 }
46 tleft = (int) (done - now);
47 } else {
48 /* timed-out */
50 return (0);
51 }
52 }
53} /* SWaitUntilReadyForReading */

Referenced by GetResponse().

◆ SWaitUntilReadyForWriting()

int SWaitUntilReadyForWriting ( const int  sfd,
const int  tlen 
)

Definition at line 62 of file SWait.c.

63{
64 fd_set ss, ss2;
65 struct timeval tv;
66 int result;
67 int tleft;
68 time_t now, done;
69
70 if (sfd < 0) {
71 errno = EBADF;
72 return (0);
73 }
74
75 time(&now);
76 done = now + tlen;
77 tleft = tlen;
78
79 forever {
80 FD_ZERO(&ss);
81 FD_SET(sfd, &ss);
82 ss2 = ss;
83 tv.tv_sec = tleft;
84 tv.tv_usec = 0;
86 if (result == 1) {
87 /* ready */
88 return (1);
89 } else if (result < 0) {
90 if (errno != EINTR) {
91 /* error */
92 return (0);
93 }
94 /* try again */
95 time(&now);
96 if (now > done) {
97 /* timed-out */
99 return (0);
100 }
101 tleft = (int) (done - now);
102 } else {
103 /* timed-out */
105 return (0);
106 }
107 }
108} /* SWaitUntilReadyForWriting */

◆ 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 */

Referenced by FTPPutOneF(), SendCommand(), and ServeOneClient().

Variable Documentation

◆ gLibSio_Uses_Me_To_Quiet_Variable_Unused_Warnings

int gLibSio_Uses_Me_To_Quiet_Variable_Unused_Warnings
extern

Definition at line 4 of file main.c.

◆ SSignal

void(*)(int) SSignal(int signum, void(*handler)(int)) ( int  signum,
void(*)(int handler 
)

Definition at line 237 of file sio.h.

Referenced by PRead(), PWrite(), SAcceptA(), SClose(), SConnect(), and UNUSED().