- i_val = accept( i_fd, NULL, 0 );
- if( i_val < 0 )
- msg_Err( p_this, "accept failed (%s)",
- net_strerror( net_errno ) );
- else
- {
- const int yes = 1;
- setsockopt( i_fd, SOL_SOCKET, SO_REUSEADDR, &yes, sizeof( yes ));
-#if defined (WIN32) || defined (UNDER_CE)
- ioctlsocket (i_fd, FIONBIO, &(unsigned long){ 1 });
-#else
- fcntl (i_fd, F_SETFD, FD_CLOEXEC);
- fcntl (i_fd, F_SETFL, fcntl (i_fd, F_GETFL, 0) | O_NONBLOCK);
-#endif
- /*
- * This round-robin trick ensures that the first sockets in
- * pi_fd won't prevent the last ones from getting accept'ed.
- */
- --pi_end;
- memmove( pi, pi + 1, pi_end - pi );
- *pi_end = i_fd;
- return i_val;
- }
+ /*
+ * Move listening socket to the end to let the others in the
+ * set a chance next time.
+ */
+ memmove (pi_fd + i, pi_fd + i + 1, n - (i + 1));
+ pi_fd[n - 1] = sfd;
+ return fd;