|
55 | 55 | import org.jruby.anno.JRubyMethod; |
56 | 56 | import org.jruby.api.Access; |
57 | 57 | import org.jruby.api.Convert; |
| 58 | +import org.jruby.api.Create; |
58 | 59 | import org.jruby.exceptions.RaiseException; |
59 | 60 | import org.jruby.runtime.Arity; |
60 | 61 | import org.jruby.runtime.Helpers; |
@@ -99,6 +100,8 @@ static RubyClass createSocket(ThreadContext context, RubyClass BasicSocket) { |
99 | 100 | RubyClass Socket = defineClass(context, "Socket", BasicSocket, RubySocket::new). |
100 | 101 | defineMethods(context, RubySocket.class); |
101 | 102 |
|
| 103 | + Socket.setInternalVariable("tcp_fast_fallback", getFastFallbackDefault(context)); |
| 104 | + |
102 | 105 | RubyModule SocketConstants = Socket.defineModuleUnder(context, "Constants"). |
103 | 106 | defineConstantsFrom(context, Sock.class). |
104 | 107 | defineConstantsFrom(context, SocketOption.class). |
@@ -679,6 +682,27 @@ public IRubyObject close(final ThreadContext context) { |
679 | 682 | return context.nil; |
680 | 683 | } |
681 | 684 |
|
| 685 | + @JRubyMethod(meta = true) |
| 686 | + public static IRubyObject tcp_fast_fallback(ThreadContext context, IRubyObject self) { |
| 687 | + return (IRubyObject) Access.getClass(context, "Socket").getInternalVariable("tcp_fast_fallback"); |
| 688 | + } |
| 689 | + |
| 690 | + @JRubyMethod(name = "tcp_fast_fallback=", meta = true) |
| 691 | + public static IRubyObject tcp_fast_fallback_set(ThreadContext context, IRubyObject self, IRubyObject value) { |
| 692 | + Access.getClass(context, "Socket").setInternalVariable("tcp_fast_fallback", value); |
| 693 | + return value; |
| 694 | + } |
| 695 | + |
| 696 | + private static RubyBoolean getFastFallbackDefault(ThreadContext context) { |
| 697 | + IRubyObject tcpNoFastFallbackConfig = context.runtime.getENV().fastARef(Create.newString(context, "RUBY_TCP_NO_FAST_FALLBACK")); |
| 698 | + if (tcpNoFastFallbackConfig == null || tcpNoFastFallbackConfig.isNil() |
| 699 | + || tcpNoFastFallbackConfig.toString().equals("0")) { |
| 700 | + return context.tru; |
| 701 | + } else { |
| 702 | + return context.fals; |
| 703 | + } |
| 704 | + } |
| 705 | + |
682 | 706 | @Override |
683 | 707 | public RubyBoolean closed_p(ThreadContext context) { |
684 | 708 | if (getOpenFile() == null) return context.fals; |
|
0 commit comments