--- src/smtpd/smtpd_check.c.orig	2012-01-15 09:43:58.000000000 +0900
+++ src/smtpd/smtpd_check.c	2012-02-17 15:17:44.886466989 +0900
@@ -204,6 +204,7 @@
 #include <myaddrinfo.h>
 #include <inet_proto.h>
 #include <ip_match.h>
+#include <iostuff.h>
 
 /* DNS library. */
 
@@ -3612,6 +3613,7 @@
     ARGV   *list;
     int     found;
     int     saved_recursion = state->recursion++;
+	VSTRING *buf;
 
     if (msg_verbose)
 	msg_info(">>> START %s RESTRICTIONS <<<", reply_class);
@@ -3698,8 +3700,35 @@
 	    if (cpp[1] == 0 || alldig(cpp[1]) == 0) {
 		msg_warn("restriction %s must be followed by number", SLEEP);
 		reject_server_error(state);
-	    } else
-		sleep(atoi(*++cpp));
+	    } else {
+		  /* sleep(atoi(*++cpp)); */
+		  int sleep_time = atoi(*++cpp);
+		  int i;
+		  for ( i = 0; i < sleep_time; i++ ) {
+			/* sleep( 1 ); */
+			if ( ! read_wait(state->client->fd, 1) ) { /* read enabled */
+			  int ch = VSTREAM_GETC(state->client);
+			  if (vstream_feof(state->client) || vstream_ferror(state->client)) { /* lost connection */
+				vstream_ungetc(state->client, ch);
+				buf = vstring_alloc(100);
+				vstring_sprintf(buf, "lost connection after %d sec", i);
+				log_whatsup(state, "sleep", STR(buf));
+				vstring_free(buf);
+				status = SMTPD_CHECK_REJECT; /* finish immediately if lost connection */
+				break;
+			  }
+			  else { /* pipelining */
+				vstream_ungetc(state->client, ch);
+				buf = vstring_alloc(100);
+				vstring_sprintf(buf, "pipelining after %d sec", i);
+				log_whatsup(state, "sleep", STR(buf));
+				vstring_free(buf);
+				sleep( sleep_time - i );
+				break;
+			  }
+			}
+		  }
+		}
 	} else if (strcasecmp(name, REJECT_PLAINTEXT_SESSION) == 0) {
 	    status = reject_plaintext_session(state);
 	}
