resurrect Kgio.autopush support in pure Ruby
[kgio.git] / lib / kgio / autopush / sock_rw.rb
blob52f7a45fcef49ddf6865f2948eefb2677198625d
1 # Copyright (C) 2015 all contributors <kgio-public@bogomips.org>
2 # License: LGPLv2.1 or later (https://www.gnu.org/licenses/lgpl-2.1.txt)
4 # using this code is not recommended, for backwards compatibility only
5 module Kgio::Autopush::SockRW # :nodoc:
6   include Kgio::Autopush
8   def kgio_read(*) # :nodoc:
9     kgio_push_pending_data
10     super
11   end
13   def kgio_read!(*) # :nodoc:
14     kgio_push_pending_data
15     super
16   end
18   def kgio_tryread(*) # :nodoc:
19     kgio_push_pending_data
20     super
21   end
23   def kgio_trypeek(*) # :nodoc:
24     kgio_push_pending_data
25     super
26   end
28   def kgio_peek(*) # :nodoc:
29     kgio_push_pending_data
30     super
31   end
33   def kgio_syssend(*) # :nodoc:
34     kgio_push_pending_data(super)
35   end if Kgio::SocketMethods.method_defined?(:kgio_syssend)
37   def kgio_trysend(*) # :nodoc:
38     kgio_ap_wrap_writer(super)
39   end
41   def kgio_trywrite(*) # :nodoc:
42     kgio_ap_wrap_writer(super)
43   end
45   def kgio_trywritev(*) # :nodoc:
46     kgio_ap_wrap_writer(super)
47   end
49   def kgio_write(*) # :nodoc:
50     kgio_ap_wrap_writer(super)
51   end
53   def kgio_writev(*) # :nodoc:
54     kgio_ap_wrap_writer(super)
55   end
57 private
59   def kgio_ap_wrap_writer(rv) # :nodoc:
60     case rv
61     when :wait_readable, :wait_writable
62       kgio_push_pending_data
63     else
64       kgio_push_pending
65     end
66     rv
67   end
68 end