-
-
Notifications
You must be signed in to change notification settings - Fork 646
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[python] Fixed python.net.SslSocket when python-version >= 3.4 (#8401) (
#11050) * [python] Fixed python.net.SslSocket when python-version >= 3.4 (#8401) The issue where SslSocket throws an exception is due to hostName being null in wrap_socket. This fix delays wrap_socket until after connect is called, so we can pass a host in. * added compilation flag to only run this for python * removed sys.net.Host import; it was unused, and it caused issues on non-sys targets * fixed test to work across platforms (see comment in code) fixed copy/paste error in code comments * added gettimeout, getblocking, and getsockopt to python.lib.socket.Socket (also added overload of setsockopt to take an Int value) updated Issue8401 to remove casts * replaced eq with feq in test for settimeout values
- Loading branch information
Showing
6 changed files
with
118 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,12 @@ | ||
compile-each.hxml | ||
|
||
--each | ||
|
||
--main unit.TestMain | ||
-python bin/unit.py | ||
-python bin/unit.py | ||
|
||
--next | ||
|
||
-D python-version=3.4 | ||
--main unit.TestMain | ||
-python bin/unit34.py |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package unit.issues; | ||
|
||
class Issue8401 extends unit.Test { | ||
#if python | ||
function testNew() { | ||
var sock = new python.net.SslSocket(); | ||
// With Issue8401, construction fails immediately; if we get this far, it's a pass | ||
utest.Assert.pass(); | ||
} | ||
|
||
@:access(python.net.SslSocket.__s) | ||
@:access(python.net.SslSocket.wrapSocketWithSslContext) | ||
function testTimeout() { | ||
var sock = new python.net.SslSocket(); | ||
eq(null, sock.__s.gettimeout()); | ||
sock.setTimeout(500); | ||
feq(500, sock.__s.gettimeout()); | ||
// This will change __s. Make sure we set the timeout properly. | ||
sock.wrapSocketWithSslContext("127.0.0.1"); | ||
feq(500, sock.__s.gettimeout()); | ||
} | ||
|
||
#if (python_verion >= 3.7) | ||
@:access(python.net.SslSocket.__s) | ||
@:access(python.net.SslSocket.wrapSocketWithSslContext) | ||
function testBlocking() { | ||
var sock = new python.net.SslSocket(); | ||
t(sock.__s.getblocking()); | ||
sock.setBlocking(false); | ||
f(sock.__s.getblocking()); | ||
// This will change __s. Make sure we set the blocking flag properly. | ||
sock.wrapSocketWithSslContext("127.0.0.1"); | ||
f(sock.__s.getblocking()); | ||
} | ||
#end | ||
|
||
@:access(python.net.SslSocket.__s) | ||
@:access(python.net.SslSocket.wrapSocketWithSslContext) | ||
function testFastSend() { | ||
var sock = new python.net.SslSocket(); | ||
eq(0, sock.__s.getsockopt(python.lib.Socket.SOL_TCP, python.lib.Socket.TCP_NODELAY)); | ||
sock.setFastSend(true); | ||
// NOTE: this number can vary per platform; non-zero means true/enabled | ||
utest.Assert.notEquals(0, sock.__s.getsockopt(python.lib.Socket.SOL_TCP, python.lib.Socket.TCP_NODELAY)); | ||
// This will change __s. Make sure we set the sock opt properly. | ||
sock.wrapSocketWithSslContext("127.0.0.1"); | ||
utest.Assert.notEquals(0, sock.__s.getsockopt(python.lib.Socket.SOL_TCP, python.lib.Socket.TCP_NODELAY)); | ||
} | ||
#end | ||
} |