Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Duh, make the socket non-blocking

  • Loading branch information...
commit 6c0d415d07260b5ced1c99b6fdca6c1b2d783ce7 1 parent bf78d00
@adamdeprince adamdeprince authored
Showing with 15 additions and 5 deletions.
  1. +15 −5 oblb/__init__.py
View
20 oblb/__init__.py
@@ -1,6 +1,5 @@
import collections
import socket
-from select import select
# composabable (layers of heirarchy)
# readable by people and programs
@@ -37,7 +36,6 @@ class TransportSocket(Socket):
buffer = None
def read_ready(self):
- print "TransportationSocket.read_Ready"
if not self.peer.socket:
return self.exception_ready()
try:
@@ -51,11 +49,11 @@ def read_ready(self):
def write_ready(self):
if self.buffer:
+ "Ready to accept from a ", len(self.buffer), " item buffer"
try:
amount = self.socket.send(self.buffer)
except socket.error:
return self.exception_ready()
-
self.buffer = self.buffer[amount:]
elif not self.peer.socket:
self.exception_ready()
@@ -90,7 +88,12 @@ def __init__(self, peer, target, items):
socket.AF_INET, socket.SOCK_STREAM)
self.host, self.port = self.target.split(':')
self.port = int(self.port)
- self.socket.connect((self.host, self.port))
+ target = (self.host, self.port)
+ self.socket.setblocking(False)
+ try:
+ self.socket.connect(target)
+ except socket.error:
+ pass # This is acutally fine
self.buffer = ""
@@ -148,7 +151,9 @@ def __init__(self, address, items, targets):
def read_ready(self):
self.counter += 1
- self.items.append(Local(self.counter, self.items, self.targets, *self.socket.accept()))
+ acceptance = self.socket.accept()
+ acceptance[0].setblocking(False)
+ self.items.append(Local(self.counter, self.items, self.targets, *acceptance))
def exception_ready(self):
sys.exit(1)
@@ -162,6 +167,11 @@ def wants_write(self):
def wants_exception(self):
return True
+def select(*args):
+ import select
+ retval = select.select(*args)
+ return retval
+
def main(argv):
"""Usage: oblb source_host:source_port target_host:target_port ...
Please sign in to comment.
Something went wrong with that request. Please try again.