+
+/* return 0 on timeout, 1 on writer ready
+ * -1 on general error
+ */
+int
+slapd_wait_writer( ber_socket_t sd )
+{
+#ifdef HAVE_WINSOCK
+ fd_set writefds;
+ struct timeval tv, *tvp;
+
+ FD_ZERO( &writefds );
+ FD_SET( slapd_ws_sockets[sd], &writefds );
+ if ( global_writetimeout ) {
+ tv.tv_sec = global_writetimeout;
+ tv.tv_usec = 0;
+ tvp = &tv;
+ } else {
+ tvp = NULL;
+ }
+ return select( 0, NULL, &writefds, NULL, tvp );
+#else
+ struct pollfd fds;
+ int timeout = global_writetimeout ? global_writetimeout * 1000 : -1;
+
+ fds.fd = sd;
+ fds.events = POLLOUT;
+
+ return poll( &fds, 1, timeout );
+#endif
+}