ReactOS  0.4.14-dev-52-g6116262
SBind.c
Go to the documentation of this file.
1 #include "syshdrs.h"
2 
3 int
4 SBind(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 
59 int
60 SListen(int sfd, int backlog)
61 {
62  return (listen(sfd, (unsigned int) backlog));
63 } /* SListen */
int SListen(int sfd, int backlog)
Definition: SBind.c:60
#define kReUseAddrNo
Definition: sio.h:46
#define sleep
Definition: syshdrs.h:37
struct png_info_def **typedef void(__cdecl typeof(png_destroy_read_struct))(struct png_struct_def **
Definition: typeof.h:49
u_short sin_port
Definition: winsock.h:511
#define htonl(x)
Definition: module.h:212
INT WSAAPI bind(IN SOCKET s, IN CONST struct sockaddr *name, IN INT namelen)
Definition: socklife.c:36
#define INADDR_ANY
Definition: StrAddr.c:4
#define SOL_SOCKET
Definition: winsock.h:398
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
INT WSAAPI setsockopt(IN SOCKET s, IN INT level, IN INT optname, IN CONST CHAR FAR *optval, IN INT optlen)
Definition: sockctrl.c:421
#define SO_REUSEADDR
Definition: winsock.h:180
struct in_addr sin_addr
Definition: winsock.h:512
INT WSAAPI listen(IN SOCKET s, IN INT backlog)
Definition: sockctrl.c:123
#define AF_INET
Definition: tcpip.h:117
int SBind(int sockfd, const int port, const int nTries, const int reuseFlag)
Definition: SBind.c:4
#define htons(x)
Definition: module.h:213
USHORT port
Definition: uri.c:227
short sin_family
Definition: winsock.h:510
unsigned int(__cdecl typeof(jpeg_read_scanlines))(struct jpeg_decompress_struct *
Definition: typeof.h:31