浏览代码

preserve flags across connect() and bind() for ipv6 (#7989)

close #7978
Craig Robinson 6 年之前
父节点
当前提交
2f9b1c6564
共有 1 个文件被更改,包括 16 次插入0 次删除
  1. 16 0
      std/cpp/_std/sys/net/Socket.hx

+ 16 - 0
std/cpp/_std/sys/net/Socket.hx

@@ -117,6 +117,14 @@ private class SocketOutput extends haxe.io.Output {
 class Socket {
 class Socket {
 
 
    private var __s : Dynamic;
    private var __s : Dynamic;
+
+   // We need to keep these values so that we can restore
+   // them if we re-create the socket for ipv6 as in 
+   // connect() and bind() below.
+   private var __timeout:Float = 0.0;
+   private var __blocking:Bool = true;
+   private var __fastSend:Bool = false;
+
    public var input(default,null) : haxe.io.Input;
    public var input(default,null) : haxe.io.Input;
    public var output(default,null) : haxe.io.Output;
    public var output(default,null) : haxe.io.Output;
    public var custom : Dynamic;
    public var custom : Dynamic;
@@ -127,6 +135,11 @@ class Socket {
 
 
    private function init() : Void {
    private function init() : Void {
       if( __s == null )__s = NativeSocket.socket_new(false);
       if( __s == null )__s = NativeSocket.socket_new(false);
+      // Restore these values if they changed. This can happen
+      // in connect() and bind() if using an ipv6 address.
+      setTimeout(__timeout);
+      setBlocking(__blocking);
+      setFastSend(__fastSend);
       input = new SocketInput(__s);
       input = new SocketInput(__s);
       output = new SocketOutput(__s);
       output = new SocketOutput(__s);
    }
    }
@@ -239,6 +252,7 @@ class Socket {
    }
    }
 
 
    public function setTimeout( timeout : Float ) : Void {
    public function setTimeout( timeout : Float ) : Void {
+      __timeout = timeout;
       NativeSocket.socket_set_timeout(__s, timeout);
       NativeSocket.socket_set_timeout(__s, timeout);
    }
    }
 
 
@@ -247,10 +261,12 @@ class Socket {
    }
    }
 
 
    public function setBlocking( b : Bool ) : Void {
    public function setBlocking( b : Bool ) : Void {
+      __blocking = b;
       NativeSocket.socket_set_blocking(__s,b);
       NativeSocket.socket_set_blocking(__s,b);
    }
    }
 
 
    public function setFastSend( b : Bool ) : Void {
    public function setFastSend( b : Bool ) : Void {
+      __fastSend = b;
       NativeSocket.socket_set_fast_send(__s,b);
       NativeSocket.socket_set_fast_send(__s,b);
    }
    }