+* "fgets" to read directly from socket *
+*************************************************/
+
+/* Added by PH after a suggestion by Steve Usher because the previous use of
+C-style buffered I/O gave trouble. */
+
+static uschar *
+dc_gets(uschar *s, int n, int fd)
+{
+int p = 0;
+int count = 0;
+
+for (;;)
+ {
+ if (sbp == 0)
+ {
+ sbp = read(fd, sbuffer, sizeof(sbuffer));
+ if (sbp == 0) { if (count == 0) return NULL; else break; }
+ p = 0;
+ }
+
+ while (p < sbp)
+ {
+ if (count >= n - 1) break;
+ s[count++] = sbuffer[p];
+ if (sbuffer[p++] == '\n') break;
+ }
+
+ memmove(sbuffer, sbuffer + p, sbp - p);
+ sbp -= p;
+
+ if (s[count-1] == '\n' || count >= n - 1) break;
+ }
+
+s[count] = 0;
+return s;
+}
+
+
+
+
+/*************************************************
+* Server entry point *
+*************************************************/