On Unix, you can happily select() on any file descriptors, including stdin and sockets. On Windows, that doesn't appear to be the case. Here's a simple form of netcat:
object sock; void sockread(mixed id, string data) { //Restrict to ASCII printables for simplicity write(filter(data, lambda(int c) {return has_value("\t\r\n", c) || (c >= 32 && c < 128);})); } void console(mixed id, string data) {sock->write(data);} int main() { sock = Stdio.File(); sock->connect("minstrelhall.com", 221); sock->set_read_callback(sockread); Stdio.stdin->set_read_callback(console); return -1; }
The important aspects of this are read callbacks on both a socket and Stdio.stdin, and returning -1 from main. Comment out the stdin callback and all is well. Keep it in, and the program runs fine on Unix, but on Windows, bombs out:
/home/zino/hack/pike8-rel/pike/src/backend.cmod:5496: Fatal error: Filedescriptor 0 (IS CONSOLE) caused fatal error 10038 in backend. Backtrace at time of fatal: -:1: Pike.Backend(0)->`()(3600.0)
This happens with both 7.8 and 8.0 stables on Windows 7, though I doubt it'll be any different on other Pikes or Windowses.
Is there any good way to respond to console and sockets? For now, I think I'll just write this off as "Windows sucks" and disable the console (it's only a debug/emergency feature anyway).
ChrisA
pike-devel@lists.lysator.liu.se