Created
September 28, 2013 06:59
-
-
Save ironpythonbot/6739336 to your computer and use it in GitHub Desktop.
CodePlex Issue #33312 Plain Text Attachments
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
Index: IronPython.Modules/socket.cs | |
=================================================================== | |
--- IronPython.Modules/socket.cs (revision 22123) | |
+++ IronPython.Modules/socket.cs (working copy) | |
@@ -250,13 +250,13 @@ | |
} | |
[Documentation("close() -> None\n\nClose the socket. It cannot be used after being closed.")] | |
- public void close() { | |
+ public void close() { | |
+ var refs = System.Threading.Interlocked.Decrement(ref _referenceCount); | |
+ | |
// Don't actually close the socket if other file objects are | |
- // still referring to this socket. | |
- if (_referenceCount < 1) { | |
+ // still referring to this socket. | |
+ if (refs < 1) { | |
_close(); | |
- } else { | |
- var refs = System.Threading.Interlocked.Decrement(ref _referenceCount); | |
} | |
} | |
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
import threading | |
import socket | |
import sys | |
HOST='127.0.0.1' | |
PORT = 8888 | |
m = threading.RLock() | |
def threadLog(msg): | |
with m: | |
sys.stdout.write(msg + '\n') | |
def serverThread(): | |
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) | |
s.bind((HOST, PORT)) | |
s.listen(4) | |
threadLog('Listening activated, now starting to accept') | |
conn, addr = s.accept() | |
threadLog('Client connection accepted, sending data') | |
conn.send('Kamusta') | |
threadLog('Data sent, now closing') | |
#conn.shutdown(socket.SHUT_WR) | |
conn.close() | |
threadLog('Connection closed') | |
def clientThread(): | |
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) | |
threadLog('Client connecting') | |
s.connect((HOST , PORT)) | |
threadLog('Connection formed, now starting recv') | |
while len(s.recv(1)) > 0: | |
threadLog('Byte received') | |
pass | |
threadLog('Client closing') | |
s.close() | |
threadLog('Client closed') | |
t = threading.Thread(target = serverThread) | |
t.start() | |
import time | |
time.sleep(1) | |
t2 = threading.Thread(target = clientThread) | |
t2.start() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment