Python socket.close() Examples

The following are code examples for showing how to use socket.close(). They are extracted from open source Python projects. You can vote up the examples you like or vote down the ones you don't like. You can also save this page to your account.

Example 1
Project: enteletaor   Author: cr0hn   File: authers.py    (license) View Source Project 10 votes vote down vote up
def brute_zmq(host, port=5555, user=None, password=None, db=0):

    context = zmq.Context()

    # Configure
    socket = context.socket(zmq.SUB)
    socket.setsockopt(zmq.SUBSCRIBE, b"")  # All topics
    socket.setsockopt(zmq.LINGER, 0)  # All topics
    socket.RCVTIMEO = 1000  # timeout: 1 sec

    # Connect
    socket.connect("tcp://%s:%s" % (host, port))

    # Try to receive
    try:
        socket.recv()

        return True
    except Exception:
        return False
    finally:
        socket.close() 
Example 2
Project: honeypot   Author: fabio-d   File: main.py    (license) View Source Project 7 votes vote down vote up
def handle_tcp_default(sk, dstport):
	# Attempt to guess protocol according to what the client sends
	data = ''
	try:
		rlist, _, _ = select.select([sk], [], [], 30)
		if len(rlist) != 0:
			data = sk.recv(20, socket.MSG_PEEK)
	except Exception as err:
		#print(traceback.format_exc())
		pass

	if data[:3] in SSL_CLIENT_HELLO_SIGNATURES:
		print colored("Guessing this is a SSL/TLS connection, attempting to handshake.", 'red', attrs=['bold'])
		handle_tcp_hexdump_ssl(sk, dstport)
	elif data.startswith("GET "):
		handle_tcp_http(sk, dstport)
	elif data.startswith("CONNECT "):
		handle_tcp_httpproxy(sk, dstport)
	else:
		handle_tcp_hexdump(sk, dstport)
	sk.close()

# UDP DISPATCHER 
Example 3
Project: kinect-2-libras   Author: inessadl   File: SocketServer.py    (Apache License 2.0) View Source Project 6 votes vote down vote up
def shutdown_request(self, request):
        """Called to shutdown and close an individual request."""
        try:
            #explicitly shutdown.  socket.close() merely releases
            #the socket and waits for GC to perform the actual close.
            request.shutdown(socket.SHUT_WR)
        except socket.error:
            pass #some platforms may raise ENOTCONN here
        self.close_request(request) 
Example 4
Project: aqara-mqtt   Author: monster1025   File: xiaomihub.py    (license) View Source Project 6 votes vote down vote up
def _send_socket(self, cmd, rtnCmd, ip, port):
        socket = self._socket
        try:
            _LOGGER.debug('Sending to GW {0}'.format(cmd))
            self._read_unwanted_data()

            socket.settimeout(30.0)
            socket.sendto(cmd.encode(), (ip, port))
            socket.settimeout(30.0)
            data, addr = socket.recvfrom(1024)
            if len(data) is not None:
                resp = json.loads(data.decode())
                _LOGGER.debug('Recieved from GW {0}'.format(resp))
                if resp["cmd"] == rtnCmd:
                    return resp
                else:
                    _LOGGER.error("Response from {0} does not match return cmd".format(ip))
                    _LOGGER.error(data)
            else:
                _LOGGER.error("No response from Gateway")
        except socket.timeout:
            _LOGGER.error("Cannot connect to Gateway")
            socket.close() 
Example 5
Project: SalesforceXyTools   Author: exiahuang   File: wsgiserver2.py    (license) View Source Project 6 votes vote down vote up
def close(self):
        """Close the socket underlying this connection."""
        self.rfile.close()

        if not self.linger:
            # Python's socket module does NOT call close on the kernel socket
            # when you call socket.close(). We do so manually here because we
            # want this server to send a FIN TCP segment immediately. Note this
            # must be called *before* calling socket.close(), because the latter
            # drops its reference to the kernel socket.
            if hasattr(self.socket, '_sock'):
                self.socket._sock.close()
            self.socket.close()
        else:
            # On the other hand, sometimes we want to hang around for a bit
            # to make sure the client has a chance to read our entire
            # response. Skipping the close() calls here delays the FIN
            # packet until the socket object is garbage-collected later.
            # Someday, perhaps, we'll do the full lingering_close that
            # Apache does, but not today.
            pass 
Example 6
Project: SalesforceXyTools   Author: exiahuang   File: wsgiserver2.py    (license) View Source Project 6 votes vote down vote up
def respond(self):
        """Process the current request."""
        response = self.req.server.wsgi_app(self.env, self.start_response)
        try:
            for chunk in response:
                # "The start_response callable must not actually transmit
                # the response headers. Instead, it must store them for the
                # server or gateway to transmit only after the first
                # iteration of the application return value that yields
                # a NON-EMPTY string, or upon the application's first
                # invocation of the write() callable." (PEP 333)
                if chunk:
                    if isinstance(chunk, unicodestr):
                        chunk = chunk.encode('ISO-8859-1')
                    self.write(chunk)
        finally:
            if hasattr(response, "close"):
                response.close() 
Example 7
Project: SalesforceXyTools   Author: exiahuang   File: wsgiserver3.py    (license) View Source Project 6 votes vote down vote up
def close(self):
        """Close the socket underlying this connection."""
        self.rfile.close()

        if not self.linger:
            # Python's socket module does NOT call close on the kernel socket
            # when you call socket.close(). We do so manually here because we
            # want this server to send a FIN TCP segment immediately. Note this
            # must be called *before* calling socket.close(), because the latter
            # drops its reference to the kernel socket.
            # Python 3 *probably* fixed this with socket._real_close; hard to tell.
##            self.socket._sock.close()
            self.socket.close()
        else:
            # On the other hand, sometimes we want to hang around for a bit
            # to make sure the client has a chance to read our entire
            # response. Skipping the close() calls here delays the FIN
            # packet until the socket object is garbage-collected later.
            # Someday, perhaps, we'll do the full lingering_close that
            # Apache does, but not today.
            pass 
Example 8
Project: bokken   Author: thestr4ng3r   File: __init__.py    (license) View Source Project 6 votes vote down vote up
def close(self):
        """Close the socket underlying this connection."""
        self.rfile.close()
        
        if not self.linger:
            # Python's socket module does NOT call close on the kernel socket
            # when you call socket.close(). We do so manually here because we
            # want this server to send a FIN TCP segment immediately. Note this
            # must be called *before* calling socket.close(), because the latter
            # drops its reference to the kernel socket.
            if hasattr(self.socket, '_sock'):
                self.socket._sock.close()
            self.socket.close()
        else:
            # On the other hand, sometimes we want to hang around for a bit
            # to make sure the client has a chance to read our entire
            # response. Skipping the close() calls here delays the FIN
            # packet until the socket object is garbage-collected later.
            # Someday, perhaps, we'll do the full lingering_close that
            # Apache does, but not today.
            pass 
Example 9
Project: bokken   Author: thestr4ng3r   File: __init__.py    (license) View Source Project 6 votes vote down vote up
def respond(self):
        response = self.req.server.wsgi_app(self.env, self.start_response)
        try:
            for chunk in response:
                # "The start_response callable must not actually transmit
                # the response headers. Instead, it must store them for the
                # server or gateway to transmit only after the first
                # iteration of the application return value that yields
                # a NON-EMPTY string, or upon the application's first
                # invocation of the write() callable." (PEP 333)
                if chunk:
                    if isinstance(chunk, unicode):
                        chunk = chunk.encode('ISO-8859-1')
                    self.write(chunk)
        finally:
            if hasattr(response, "close"):
                response.close() 
Example 10
Project: download-manager   Author: thispc   File: __init__.py    (license) View Source Project 6 votes vote down vote up
def simple_response(self, status, msg=""):
        """Write a simple response back to the client."""
        status = str(status)
        buf = ["%s %s\r\n" % (self.environ['ACTUAL_SERVER_PROTOCOL'], status),
               "Content-Length: %s\r\n" % len(msg),
               "Content-Type: text/plain\r\n"]
        
        if status[:3] == "413" and self.response_protocol == 'HTTP/1.1':
            # Request Entity Too Large
            self.close_connection = True
            buf.append("Connection: close\r\n")
        
        buf.append("\r\n")
        if msg:
            buf.append(msg)
        
        try:
            self.wfile.sendall("".join(buf))
        except socket.error, x:
            if x.args[0] not in socket_errors_to_ignore:
                raise 
Example 11
Project: download-manager   Author: thispc   File: __init__.py    (license) View Source Project 6 votes vote down vote up
def close(self):
        """Close the socket underlying this connection."""
        self.rfile.close()
        
        if not self.linger:
            # Python's socket module does NOT call close on the kernel socket
            # when you call socket.close(). We do so manually here because we
            # want this server to send a FIN TCP segment immediately. Note this
            # must be called *before* calling socket.close(), because the latter
            # drops its reference to the kernel socket.
            self.socket._sock.close()
            self.socket.close()
        else:
            # On the other hand, sometimes we want to hang around for a bit
            # to make sure the client has a chance to read our entire
            # response. Skipping the close() calls here delays the FIN
            # packet until the socket object is garbage-collected later.
            # Someday, perhaps, we'll do the full lingering_close that
            # Apache does, but not today.
            pass 
Example 12
Project: download-manager   Author: thispc   File: __init__.py    (license) View Source Project 6 votes vote down vote up
def run(self):
        try:
            self.ready = True
            while True:
                conn = self.server.requests.get()
                if conn is _SHUTDOWNREQUEST:
                    return
                
                self.conn = conn
                try:
                    conn.communicate()
                finally:
                    conn.close()
                    self.conn = None
        except (KeyboardInterrupt, SystemExit), exc:
            self.server.interrupt = exc 
Example 13
Project: LMDocker-project   Author: xiaozhazi   File: client.py    (license) View Source Project 6 votes vote down vote up
def tar_file():
#create file path.
	file_path = '/tmp/' + image_name

	if False == os.path.exists(file_path):
		print 'Error, file dir %s not exist'% file_path
	
	full_name = '/tmp/'+image_name+'.tar'
	tar_file = tarfile.open(full_name,'w')
	for root,dirs,files in os.walk(file_path):
		for file in files:
			fullpath = os.path.join(root,file)
			tar_file.add(fullpath,arcname = file)
	
	tar_file.close()
	

	if False == os.path.isfile(full_name):
		print 'Error, tar failed' 
Example 14
Project: wsgiserver   Author: fgallaire   File: wsgiserver.py    (license) View Source Project 6 votes vote down vote up
def respond(self):
        """Process the current request."""
        response = self.req.server.wsgi_app(self.env, self.start_response)
        try:
            for chunk in response:
                # "The start_response callable must not actually transmit
                # the response headers. Instead, it must store them for the
                # server or gateway to transmit only after the first
                # iteration of the application return value that yields
                # a NON-EMPTY string, or upon the application's first
                # invocation of the write() callable." (PEP 333)
                if chunk:
                    if not isinstance(chunk, binary_type):
                        raise ValueError("WSGI Applications must yield bytes")
                    self.write(chunk)
        finally:
            if hasattr(response, "close"):
                response.close() 
Example 15
Project: autosub-bootstrapbill   Author: BenjV   File: __init__.py    (license) View Source Project 6 votes vote down vote up
def respond(self):
        """Process the current request."""

        """
        From PEP 333:

            The start_response callable must not actually transmit
            the response headers. Instead, it must store them for the
            server or gateway to transmit only after the first
            iteration of the application return value that yields
            a NON-EMPTY string, or upon the application's first
            invocation of the write() callable.
        """

        response = self.req.server.wsgi_app(self.env, self.start_response)
        try:
            for chunk in filter(None, response):
                if not isinstance(chunk, six.binary_type):
                    raise ValueError('WSGI Applications must yield bytes')
                self.write(chunk)
        finally:
            if hasattr(response, 'close'):
                response.close() 
Example 16
Project: CloudPrint   Author: William-An   File: wsgiserver2.py    (license) View Source Project 6 votes vote down vote up
def close(self):
        """Close the socket underlying this connection."""
        self.rfile.close()

        if not self.linger:
            # Python's socket module does NOT call close on the kernel
            # socket when you call socket.close(). We do so manually here
            # because we want this server to send a FIN TCP segment
            # immediately. Note this must be called *before* calling
            # socket.close(), because the latter drops its reference to
            # the kernel socket.
            if hasattr(self.socket, '_sock'):
                self.socket._sock.close()
            self.socket.close()
        else:
            # On the other hand, sometimes we want to hang around for a bit
            # to make sure the client has a chance to read our entire
            # response. Skipping the close() calls here delays the FIN
            # packet until the socket object is garbage-collected later.
            # Someday, perhaps, we'll do the full lingering_close that
            # Apache does, but not today.
            pass 
Example 17
Project: CloudPrint   Author: William-An   File: wsgiserver2.py    (license) View Source Project 6 votes vote down vote up
def respond(self):
        """Process the current request."""
        response = self.req.server.wsgi_app(self.env, self.start_response)
        try:
            for chunk in response:
                # "The start_response callable must not actually transmit
                # the response headers. Instead, it must store them for the
                # server or gateway to transmit only after the first
                # iteration of the application return value that yields
                # a NON-EMPTY string, or upon the application's first
                # invocation of the write() callable." (PEP 333)
                if chunk:
                    if isinstance(chunk, unicodestr):
                        chunk = chunk.encode('ISO-8859-1')
                    self.write(chunk)
        finally:
            if hasattr(response, "close"):
                response.close() 
Example 18
Project: CloudPrint   Author: William-An   File: wsgiserver3.py    (license) View Source Project 6 votes vote down vote up
def close(self):
        """Close the socket underlying this connection."""
        self.rfile.close()

        if not self.linger:
            # Python's socket module does NOT call close on the kernel
            # socket when you call socket.close(). We do so manually here
            # because we want this server to send a FIN TCP segment
            # immediately. Note this must be called *before* calling
            # socket.close(), because the latter drops its reference to
            # the kernel socket.
            # Python 3 *probably* fixed this with socket._real_close;
            # hard to tell.
# self.socket._sock.close()
            self.socket.close()
        else:
            # On the other hand, sometimes we want to hang around for a bit
            # to make sure the client has a chance to read our entire
            # response. Skipping the close() calls here delays the FIN
            # packet until the socket object is garbage-collected later.
            # Someday, perhaps, we'll do the full lingering_close that
            # Apache does, but not today.
            pass 
Example 19
Project: CloudPrint   Author: William-An   File: wsgiserver3.py    (license) View Source Project 6 votes vote down vote up
def respond(self):
        """Process the current request."""
        response = self.req.server.wsgi_app(self.env, self.start_response)
        try:
            for chunk in response:
                # "The start_response callable must not actually transmit
                # the response headers. Instead, it must store them for the
                # server or gateway to transmit only after the first
                # iteration of the application return value that yields
                # a NON-EMPTY string, or upon the application's first
                # invocation of the write() callable." (PEP 333)
                if chunk:
                    if isinstance(chunk, unicodestr):
                        chunk = chunk.encode('ISO-8859-1')
                    self.write(chunk)
        finally:
            if hasattr(response, "close"):
                response.close() 
Example 20
Project: py-script   Author: xiaoxiamin   File: __init__.py    (license) View Source Project 6 votes vote down vote up
def close(self):
        """Close the socket underlying this connection."""
        self.rfile.close()
        
        if not self.linger:
            # Python's socket module does NOT call close on the kernel socket
            # when you call socket.close(). We do so manually here because we
            # want this server to send a FIN TCP segment immediately. Note this
            # must be called *before* calling socket.close(), because the latter
            # drops its reference to the kernel socket.
            if hasattr(self.socket, '_sock'):
                self.socket._sock.close()
            self.socket.close()
        else:
            # On the other hand, sometimes we want to hang around for a bit
            # to make sure the client has a chance to read our entire
            # response. Skipping the close() calls here delays the FIN
            # packet until the socket object is garbage-collected later.
            # Someday, perhaps, we'll do the full lingering_close that
            # Apache does, but not today.
            pass 
Example 21
Project: kinect-2-libras   Author: inessadl   File: SocketServer.py    (Apache License 2.0) View Source Project 5 votes vote down vote up
def shutdown_request(self, request):
        """Called to shutdown and close an individual request."""
        self.close_request(request) 
Example 22
Project: kinect-2-libras   Author: inessadl   File: SocketServer.py    (Apache License 2.0) View Source Project 5 votes vote down vote up
def server_close(self):
        """Called to clean-up the server.

        May be overridden.

        """
        self.socket.close() 
Example 23
Project: kinect-2-libras   Author: inessadl   File: SocketServer.py    (Apache License 2.0) View Source Project 5 votes vote down vote up
def close_request(self, request):
        """Called to clean up an individual request."""
        request.close() 
Example 24
Project: kinect-2-libras   Author: inessadl   File: SocketServer.py    (Apache License 2.0) View Source Project 5 votes vote down vote up
def close_request(self, request):
        # No need to close anything.
        pass 
Example 25
Project: kinect-2-libras   Author: inessadl   File: SocketServer.py    (Apache License 2.0) View Source Project 5 votes vote down vote up
def finish(self):
        if not self.wfile.closed:
            self.wfile.flush()
        self.wfile.close()
        self.rfile.close() 
Example 26
Project: noc-orchestrator   Author: DirceuSilvaLabs   File: netutil_test.py    (MIT License) View Source Project 5 votes vote down vote up
def tearDown(self):
        self.resolver.close()
        super(ThreadedResolverTest, self).tearDown() 
Example 27
Project: noc-orchestrator   Author: DirceuSilvaLabs   File: netutil_test.py    (MIT License) View Source Project 5 votes vote down vote up
def test_same_port_allocation(self):
        if 'TRAVIS' in os.environ:
            self.skipTest("dual-stack servers often have port conflicts on travis")
        sockets = bind_sockets(None, 'localhost')
        try:
            port = sockets[0].getsockname()[1]
            self.assertTrue(all(s.getsockname()[1] == port
                                for s in sockets[1:]))
        finally:
            for sock in sockets:
                sock.close() 
Example 28
Project: noc-orchestrator   Author: DirceuSilvaLabs   File: netutil_test.py    (MIT License) View Source Project 5 votes vote down vote up
def test_reuse_port(self):
        socket, port = bind_unused_port(reuse_port=True)
        try:
            sockets = bind_sockets(port, 'localhost', reuse_port=True)
            self.assertTrue(all(s.getsockname()[1] == port for s in sockets))
        finally:
            socket.close()
            for sock in sockets:
                sock.close() 
Example 29
Project: noc-orchestrator   Author: DirceuSilvaLabs   File: netutil_test.py    (MIT License) View Source Project 5 votes vote down vote up
def tearDown(self):
        self.resolver.close()
        super(ThreadedResolverTest, self).tearDown() 
Example 30
Project: noc-orchestrator   Author: DirceuSilvaLabs   File: netutil_test.py    (MIT License) View Source Project 5 votes vote down vote up
def test_same_port_allocation(self):
        if 'TRAVIS' in os.environ:
            self.skipTest("dual-stack servers often have port conflicts on travis")
        sockets = bind_sockets(None, 'localhost')
        try:
            port = sockets[0].getsockname()[1]
            self.assertTrue(all(s.getsockname()[1] == port
                                for s in sockets[1:]))
        finally:
            for sock in sockets:
                sock.close() 
Example 31
Project: noc-orchestrator   Author: DirceuSilvaLabs   File: netutil_test.py    (MIT License) View Source Project 5 votes vote down vote up
def tearDown(self):
        self.resolver.close()
        super(ThreadedResolverTest, self).tearDown() 
Example 32
Project: noc-orchestrator   Author: DirceuSilvaLabs   File: netutil_test.py    (MIT License) View Source Project 5 votes vote down vote up
def test_same_port_allocation(self):
        if 'TRAVIS' in os.environ:
            self.skipTest("dual-stack servers often have port conflicts on travis")
        sockets = bind_sockets(None, 'localhost')
        try:
            port = sockets[0].getsockname()[1]
            self.assertTrue(all(s.getsockname()[1] == port
                                for s in sockets[1:]))
        finally:
            for sock in sockets:
                sock.close() 
Example 33
Project: noc-orchestrator   Author: DirceuSilvaLabs   File: netutil_test.py    (MIT License) View Source Project 5 votes vote down vote up
def test_reuse_port(self):
        socket, port = bind_unused_port(reuse_port=True)
        try:
            sockets = bind_sockets(port, 'localhost', reuse_port=True)
            self.assertTrue(all(s.getsockname()[1] == port for s in sockets))
        finally:
            socket.close()
            for sock in sockets:
                sock.close() 
Example 34
Project: hostapd-mana   Author: adde88   File: SocketServer.py    (license) View Source Project 5 votes vote down vote up
def shutdown_request(self, request):
        """Called to shutdown and close an individual request."""
        self.close_request(request) 
Example 35
Project: hostapd-mana   Author: adde88   File: SocketServer.py    (license) View Source Project 5 votes vote down vote up
def server_close(self):
        """Called to clean-up the server.

        May be overridden.

        """
        self.socket.close() 
Example 36
Project: hostapd-mana   Author: adde88   File: SocketServer.py    (license) View Source Project 5 votes vote down vote up
def shutdown_request(self, request):
        """Called to shutdown and close an individual request."""
        try:
            #explicitly shutdown.  socket.close() merely releases
            #the socket and waits for GC to perform the actual close.
            request.shutdown(socket.SHUT_WR)
        except socket.error:
            pass #some platforms may raise ENOTCONN here
        self.close_request(request) 
Example 37
Project: hostapd-mana   Author: adde88   File: SocketServer.py    (license) View Source Project 5 votes vote down vote up
def close_request(self, request):
        """Called to clean up an individual request."""
        request.close() 
Example 38
Project: hostapd-mana   Author: adde88   File: SocketServer.py    (license) View Source Project 5 votes vote down vote up
def close_request(self, request):
        # No need to close anything.
        pass 
Example 39
Project: hostapd-mana   Author: adde88   File: SocketServer.py    (license) View Source Project 5 votes vote down vote up
def finish(self):
        if not self.wfile.closed:
            try:
                self.wfile.flush()
            except socket.error:
                # An final socket error may have occurred here, such as
                # the local error ECONNABORTED.
                pass
        self.wfile.close()
        self.rfile.close() 
Example 40
Project: hostapd-mana   Author: adde88   File: tcp.py    (license) View Source Project 5 votes vote down vote up
def _closeSocket(self):
        # socket.close() doesn't *really* close if there's another reference
        # to it in the TCP/IP stack, e.g. if it was was inherited by a
        # subprocess. And we really do want to close the connection. So we
        # use shutdown() instead, and then close() in order to release the
        # filedescriptor.
        skt = self.socket
        try:
            getattr(skt, self._socketShutdownMethod)(2)
        except socket.error:
            pass
        try:
            skt.close()
        except socket.error:
            pass 
Example 41
Project: honeypot   Author: fabio-d   File: tcp_http_https.py    (license) View Source Project 5 votes vote down vote up
def handle_tcp_https(socket, dstport):
	plaintext_socket = switchtossl(socket)
	if plaintext_socket:
		handle_tcp_http(plaintext_socket, dstport)
	else:
		socket.close() 
Example 42
Project: honeypot   Author: fabio-d   File: main.py    (license) View Source Project 5 votes vote down vote up
def handle_tcp(socket, dstport):
	handler = tcp_handlers.get(dstport, handle_tcp_default)
	try:
		handler(socket, dstport)
	except Exception as err:
		print(traceback.format_exc())
	socket.close() 
Example 43
Project: neuron   Author: susmithHCK   File: server.py    (license) View Source Project 5 votes vote down vote up
def broadcast (server_socket, sock, message):
    for socket in SOCKET_LIST:

        if socket != server_socket and socket != sock :
            try :
                socket.send(message)
            except :

                socket.close()

                if socket in SOCKET_LIST:
                    SOCKET_LIST.remove(socket) 
Example 44
Project: Auspex   Author: BBN-Q   File: alazar.py    (license) View Source Project 5 votes vote down vote up
def disconnect(self):
        self._lib.disconnect()
        for socket in self._chan_to_rsocket.values():
            socket.close()
        for socket in self._chan_to_wsocket.values():
            socket.close()
        self._chan_to_rsocket.clear()
        self._chan_to_wsocket.clear()
        self._lib.unregister_sockets() 
Example 45
Project: Intranet-Penetration   Author: yuxiaokui   File: SocketServer.py    (license) View Source Project 5 votes vote down vote up
def shutdown_request(self, request):
        """Called to shutdown and close an individual request."""
        self.close_request(request) 
Example 46
Project: Intranet-Penetration   Author: yuxiaokui   File: SocketServer.py    (license) View Source Project 5 votes vote down vote up
def server_close(self):
        """Called to clean-up the server.

        May be overridden.

        """
        self.socket.close() 
Example 47
Project: Intranet-Penetration   Author: yuxiaokui   File: SocketServer.py    (license) View Source Project 5 votes vote down vote up
def shutdown_request(self, request):
        """Called to shutdown and close an individual request."""
        try:
            #explicitly shutdown.  socket.close() merely releases
            #the socket and waits for GC to perform the actual close.
            request.shutdown(socket.SHUT_WR)
        except socket.error:
            pass #some platforms may raise ENOTCONN here
        self.close_request(request) 
Example 48
Project: Intranet-Penetration   Author: yuxiaokui   File: SocketServer.py    (license) View Source Project 5 votes vote down vote up
def close_request(self, request):
        """Called to clean up an individual request."""
        request.close() 
Example 49
Project: Intranet-Penetration   Author: yuxiaokui   File: SocketServer.py    (license) View Source Project 5 votes vote down vote up
def close_request(self, request):
        # No need to close anything.
        pass 
Example 50
Project: Intranet-Penetration   Author: yuxiaokui   File: SocketServer.py    (license) View Source Project 5 votes vote down vote up
def finish(self):
        if not self.wfile.closed:
            try:
                self.wfile.flush()
            except socket.error:
                # An final socket error may have occurred here, such as
                # the local error ECONNABORTED.
                pass
        self.wfile.close()
        self.rfile.close()