set_buffer_mode
"Stephen R. van den Berg" <[email protected]>
| Newsgroups | gmane.comp.lang.pike.user |
|---|---|
| Message-ID | <[email protected]> |
Does anybody have a working example that actually uses the new
set_buffer_mode with in input buffer or an output buffer (and for
extra bonus points: and a read or a write callback)?
I tried to get it to work in a sample program, but I'm now wondering if
I misunderstood the way it's supposed to be used, or if the code is buggy
in the Stdio lib.
I'm currently using the test program below. The read_cb doesn't seem
to be called ever, if I read from "in" instead of "i" then it actually
reads from the file, but the buffer is never used (neither is the read_cb).
---------------------------------cut here------------------
#!/usr/local/bin/pike
object in;
object out;
Stdio.Buffer i;
Stdio.Buffer o;
void tim()
{ werror("help\n");
write("direct\n");
werror("reading\n");
string a = i->read(20);
werror("got %O\ni:%O\n",a,(string)i);
call_out(tim,2);
}
int read_cb(mixed id,Stdio.Buffer d)
{ werror("read_cb %O\n",(string)d);
return 0;
}
int write_cb(mixed id,Stdio.Buffer d)
{ werror("write_cb %O\n",(string)d);
return 0;
}
int main(int argc, array(string) argv)
{ i=Stdio.Buffer();
o=Stdio.Buffer();
in=Stdio.File();
out=Stdio.File();
//in->assign(Stdio.stdin);
in=Stdio.File("/etc/group");
out->assign(Stdio.stdout);
in->set_buffer_mode(i);
in->set_nonblocking(read_cb);
out->set_buffer_mode(UNDEFINED,o);
out->set_nonblocking(UNDEFINED,write_cb);
call_out(tim,1);
return -1;
}
---------------------------------cut here------------------
--
Stephen.