| 1 | #!/usr/bin/perl | ||
| 2 | |||
| 3 | package X11::Protocol::Connection::FileHandle; | ||
| 4 | |||
| 5 | # Copyright (C) 1997, 2003 Stephen McCamant. All rights reserved. This | ||
| 6 | # program is free software; you can redistribute and/or modify it | ||
| 7 | # under the same terms as Perl itself. | ||
| 8 | |||
| 9 | use FileHandle; | ||
| 10 | use Carp; | ||
| 11 | use strict; | ||
| 12 | use vars '$VERSION', '@ISA'; | ||
| 13 | |||
| 14 | use X11::Protocol::Connection; | ||
| 15 | @ISA = ('X11::Protocol::Connection'); | ||
| 16 | |||
| 17 | $VERSION = 0.02; | ||
| 18 | |||
| 19 | sub give { | ||
| 20 | my($self) = shift; | ||
| 21 | my($msg) = @_; | ||
| 22 | my($fh) = $$self; | ||
| 23 | $fh->print($msg) or croak $!; | ||
| 24 | } | ||
| 25 | |||
| 26 | sub get { | ||
| 27 | my($self) = shift; | ||
| 28 | my($len) = @_; | ||
| 29 | my($x, $n, $o) = ("", 0, 0); | ||
| 30 | my($fh) = $$self; | ||
| 31 | until ($o == $len) { | ||
| 32 | $n = sysread $fh, $x, $len - $o, $o; | ||
| 33 | croak $! unless defined $n; | ||
| 34 | $o += $n; | ||
| 35 | } | ||
| 36 | return $x; | ||
| 37 | } | ||
| 38 | |||
| 39 | sub fh { | ||
| 40 | my($self) = shift; | ||
| 41 | return $$self; | ||
| 42 | } | ||
| 43 | |||
| 44 | sub flush { | ||
| 45 | my($self) = shift; | ||
| 46 | my($fh) = $$self; | ||
| 47 | } | ||
| 48 | |||
| 49 | 1; | ||
| 50 | __END__ |