Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 19 Aug 2007 11:18:18 GMT
From:      Andrew Turner <andrew@FreeBSD.org>
To:        Perforce Change Reviews <perforce@freebsd.org>
Subject:   PERFORCE change 125342 for review
Message-ID:  <200708191118.l7JBIIf4010913@repoman.freebsd.org>

next in thread | raw e-mail | index | archive | help
http://perforce.freebsd.org/chv.cgi?CH=125342

Change 125342 by andrew@andrew_hermies on 2007/08/19 11:17:39

	Add isOpen to a connection to check if the conenction is live and use if when connecting

Affected files ...

.. //depot/projects/soc2007/andrew-update/frontend/facund/computer.py#13 edit
.. //depot/projects/soc2007/andrew-update/frontend/facund/network/__init__.py#13 edit

Differences ...

==== //depot/projects/soc2007/andrew-update/frontend/facund/computer.py#13 (text+ko) ====

@@ -64,7 +64,8 @@
 
 	def getConnectionStatus(self):
 		'''Returns the connection state'''
-		return self.__connection is not None
+		return self.__connection is not None and \
+		    self.__connection.isOpen()
 
 	def getDirs(self):
 		'''Returns the computer's directories to update'''
@@ -160,7 +161,12 @@
 
 		try:
 			self.__connection = \
-			    facund.network.Connection(self.__host, self.__socket)
+			    facund.network.Connection(self.__host,self.__socket)
+			if not self.__connection.isOpen():
+				print "Couldn't connect to %s " % (self.__host or self.__socket)
+				del self.__connection
+				self.__connection = None
+				return
 
 			# Start the communication thread
 			self.start()

==== //depot/projects/soc2007/andrew-update/frontend/facund/network/__init__.py#13 (text+ko) ====

@@ -36,12 +36,16 @@
 	def __init__(self, server, socket):
 		self.popen = subprocess.Popen(["/usr/bin/ssh", server, "/usr/bin/nc -oU %s" % socket], stdin=subprocess.PIPE, stdout=subprocess.PIPE)
 		self.stdout = self.popen.stdout.fileno()
-		print poll()
+
+	def isOpen(self):
+		return self.popen.poll() is None
 
 	def read(self, len):
+		assert self.isOpen()
 		return os.read(self.stdout, len)
 
 	def write(self, buf):
+		assert self.isOpen()
 		self.popen.stdin.write(buf)
 
 class SocketComms:
@@ -49,6 +53,9 @@
 		self.socket = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
 		self.socket.connect(server)
 
+	def isOpen(self):
+		return true
+
 	def read(self, len):
 		return self.socket.recv(len)
 
@@ -83,6 +90,9 @@
 		# Mark the class as ready and able to disconnect
 		self.isReady = True
 
+	def isOpen(self):
+		return self.__connection.isOpen()
+
 	def disconnect(self):
 		if self.isReady:
 			self.isReady = False



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200708191118.l7JBIIf4010913>