Skip to content

Instantly share code, notes, and snippets.

@ironpythonbot
Created September 28, 2013 06:59
Show Gist options
  • Save ironpythonbot/6739336 to your computer and use it in GitHub Desktop.
Save ironpythonbot/6739336 to your computer and use it in GitHub Desktop.
CodePlex Issue #33312 Plain Text Attachments
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);
}
}
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