ReactOS 0.4.15-dev-8145-ga541a46
SBind.c
Go to the documentation of this file.
1#include "syshdrs.h"
2
3int
4SBind(int sockfd, const int port, const int nTries, const int reuseFlag)
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 */
55
56
57
58
59int
60SListen(int sfd, int backlog)
61{
62 return (listen(sfd, (unsigned int) backlog));
63} /* SListen */
int SListen(int sfd, int backlog)
Definition: SBind.c:60
int SBind(int sockfd, const int port, const int nTries, const int reuseFlag)
Definition: SBind.c:4
USHORT port
Definition: uri.c:228
unsigned int(__cdecl typeof(jpeg_read_scanlines))(struct jpeg_decompress_struct *
Definition: typeof.h:31
#define AF_INET
Definition: tcpip.h:117
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 INADDR_ANY
Definition: inet.h:53
#define sleep
Definition: syshdrs.h:37
#define htons(x)
Definition: module.h:215
#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 listen(IN SOCKET s, IN INT backlog)
Definition: sockctrl.c:123
INT WSAAPI bind(IN SOCKET s, IN CONST struct sockaddr *name, IN INT namelen)
Definition: socklife.c:36
struct in_addr sin_addr
Definition: winsock.h:512
short sin_family
Definition: winsock.h:510
u_short sin_port
Definition: winsock.h:511
#define SO_REUSEADDR
Definition: winsock.h:180
#define SOL_SOCKET
Definition: winsock.h:398