Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Untitled #3

Open
wants to merge 2 commits into from

1 participant

Jonty Wareing
Jonty Wareing

THE LAST OF THE BUGS. It's been running stably since I did this.

You'll have to nuke local mods on turing before pulling, as I was testing this there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Dec 22, 2010
  1. Jonty Wareing

    Add timeouts to source and client connections, avoids permanent hangs

    Jonty authored
    when the connection stops working.
Commits on Jan 8, 2011
  1. Jonty Wareing
This page is out of date. Refresh to see the latest.
Showing with 14 additions and 3 deletions.
  1. +14 −3 mjpegproxy.py
17 mjpegproxy.py
View
@@ -48,7 +48,11 @@ def proxy(self):
self.sem.release()
- data = self.connection.recv(1024)
+ data = ''
+ try:
+ data = self.connection.recv(1024)
+ except:
+ self.log.info("Timed out reading data from source.")
if (len(data) == 0):
self.log.info("No data recieved from source, forcing reconnect.");
@@ -60,9 +64,11 @@ def proxy(self):
client.send(data)
except socket.error, err:
self.clients.remove(client)
+ client.close()
self.log.info("Client %s disconnected: %s [clients: %s]", client, err, len(self.clients))
def add_client(self, client, address):
+ client.settimeout(5)
self.sem.acquire()
try:
data = ''
@@ -79,10 +85,12 @@ def add_client(self, client, address):
def disconnect(self):
self.log.info("Disconnecting from source")
- self.connection.close()
- self.connection = None
self.header = None
+ if self.connection:
+ self.connection.close()
+ self.connection = None
+
def connect(self):
self.log.info("Connecting to source %s", self.connect_address)
data = ''
@@ -90,6 +98,8 @@ def connect(self):
try:
self.connection = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
self.connection.connect(self.connect_address)
+ self.connection.settimeout(5)
+
data = self.connection.recv(1024)
header, data = data.split("\r\n\r\n")[0:2]
self.header = header
@@ -97,6 +107,7 @@ def connect(self):
except:
self.log.info("Failed connecting to source %s", self.connect_address)
+ self.disconnect()
for client in self.clients:
self.log.info("Client %s disconnected due to source failure", client)
Something went wrong with that request. Please try again.