// sock_gets() -- reads one line of text from a socket
//
function sock_gets($sock) {
+ socket_clear_error($msgsock);
$buf = socket_read($sock, 4096, PHP_NORMAL_READ);
- if ($buf == false) return false;
+ if (socket_last_error($buf)) return false;
if (preg_match("'\n$'s", $buf)) {
$buf = substr($buf, 0, strpos($buf, "\n"));
}
socket_write($msgsock, $talkback, strlen($talkback));
+ // LISTING_FOLLOWS mode
if (substr($talkback, 0, 1) == "1") do {
$buf = fgets($ctdlsock, 4096);
if (!$buf) {
}
} while ($buf != "000\n");
+ // SEND_LISTING mode
+ if (substr($talkback, 0, 1) == "4") do {
+ socket_clear_error($msgsock);
+ $buf = sock_gets($msgsock);
+ if (socket_last_error($msgsock)) {
+ $buf = "000" ;
+ }
+ if (!fwrite($ctdlsock, $buf . "\n")) {
+ fclose($ctdlsock);
+ socket_close($sock);
+ system("/bin/rm -f " . $sockname);
+ exit(11);
+ }
+ } while ($buf != "000");
+
}
} while($buf !== false);