Ich nicht, wenn ich das Client-Socket-Handle (conn) wie "conn.close()" schließen muss?Wird TCP Socket Server-Client-Verbindung FD Speicherverlust verursachen?
Wenn ich Multithread ausführen, um den Client-Socket fd (Conn) zu behandeln. Führt es zu einem Speicherverlust, wenn der Server zu lange läuft?
Schließt der Server den Client-Socket fd nicht, wenn Client conn.close() nicht aufruft?
Im Anschluss an meinem tcp-Socket-Server-Code:
# coding: utf-8
import socket
import os, os.path
import time
sockfile = "./communicate.sock"
if os.path.exists(sockfile):
os.remove(sockfile)
print "Opening socket..."
server = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
server.bind(sockfile)
server.listen(5)
print "Listening..."
while True:
conn, addr = server.accept()
print 'accepted connection'
while True:
data = conn.recv(1024)
if not data:
break
else:
print "-" * 20
print data
print "DONE" == data
if "DONE" == data:
# If I need to invoke conn.close() here?
break
print "-" * 20
print "Shutting down..."
server.close()
os.remove(sockfile)
print "Done"
Wenn meine Sprache nicht Python ist, wie C++, weil es keine GC gibt. Muss ich die Cliven-Buchse fd schließen? – scott1028