All pastes #2104117 Raw Edit

Something

public diff v1 · immutable
#2104117 ·published 2012-01-19 17:09 UTC
rendered paste body
From 98820d8ad52780ae06206c263c34e20715db2f4b Mon Sep 17 00:00:00 2001From: Xavier Queralt <xqueralt at flumotion>Date: Thu, 19 Jan 2012 18:05:36 +0100Subject: [PATCH 2/2] Copy _SocketCloser in Twisted 11 to be compatible with older versionsThis is what happens when you override classes that are meant to be private--- flumotion/component/feed.py   |   20 +------------------- flumotion/twisted/fdserver.py |   26 ++++++++++++++++++++++++-- 2 files changed, 25 insertions(+), 21 deletions(-)diff --git a/flumotion/component/feed.py b/flumotion/component/feed.pyindex 54eebb9..171c10f 100644--- a/flumotion/component/feed.py+++ b/flumotion/component/feed.py@@ -19,7 +19,6 @@ implementation of a PB Client to interface with feedserver.py """ -import socket import os  from twisted.internet import reactor, main, defer, tcp@@ -28,6 +27,7 @@ from zope.interface import implements  from flumotion.common import log, common, interfaces from flumotion.twisted import pb as fpb+from flumotion.twisted.fdserver import _SocketMaybeCloser  __version__ = "$Rev$" @@ -35,24 +35,6 @@ __version__ = "$Rev$" # copied from fdserver.py so that it can be bundled  -class _SocketMaybeCloser(tcp._SocketCloser):-    keepSocketAlive = False--    def _closeSocket(self):-        # We override this (from tcp._SocketCloser) so that we can close-        # sockets properly in the normal case, but once we've passed our-        # socket on via the FD-channel, we just close() it (not calling-        # shutdown() which will close the TCP channel without closing-        # the FD itself)-        if self.keepSocketAlive:-            try:-                self.socket.close()-            except socket.error:-                pass-        else:-            tcp._SocketCloser._closeSocket(self)-- class PassableClientConnection(_SocketMaybeCloser, tcp.Client):     pass diff --git a/flumotion/twisted/fdserver.py b/flumotion/twisted/fdserver.pyindex 1484a16..e5537b8 100644--- a/flumotion/twisted/fdserver.py+++ b/flumotion/twisted/fdserver.py@@ -173,7 +173,29 @@ class FDPassingBroker(pb.Broker, log.Loggable): class _SocketMaybeCloser(tcp._SocketCloser):     keepSocketAlive = False -    def _closeSocket(self):+    def _closeSocketOriginal(self, orderly):+        # The call to shutdown() before close() isn't really necessary, because+        # we set FD_CLOEXEC now, which will ensure this is the only process+        # holding the FD, thus ensuring close() really will shutdown the TCP+        # socket. However, do it anyways, just to be safe.+        skt = self.socket+        try:+            if orderly:+                getattr(skt, self._socketShutdownMethod)(2)+            else:+                # Set SO_LINGER to 1,0 which, by convention, causes a+                # connection reset to be sent when close is called,+                # instead of the standard FIN shutdown sequence.+                skt.setsockopt(socket.SOL_SOCKET, socket.SO_LINGER,+                                       struct.pack("ii", 1, 0))+        except socket.error:+            pass+        try:+             skt.close()+        except socket.error:+             pass++    def _closeSocket(self, orderly=False):         # We override this (from tcp._SocketCloser) so that we can close         # sockets properly in the normal case, but once we've passed our         # socket on via the FD-channel, we just close() it (not calling@@ -185,7 +207,7 @@ class _SocketMaybeCloser(tcp._SocketCloser):             except socket.error:                 pass         else:-            tcp.Server._closeSocket(self)+            self._closeSocketOriginal(orderly)   class PassableServerConnection(_SocketMaybeCloser, tcp.Server):-- 1.7.8.3