Rename self.client to self.request, since this is what standard
SocketServer request handlers are using.
This commit is contained in:
Peter Åstrand (astrand) 2013-03-14 15:23:44 +01:00
parent b2fe57c950
commit b9e1295f7a
2 changed files with 12 additions and 12 deletions

View File

@ -424,7 +424,7 @@ Sec-WebSocket-Accept: %s\r
while self.send_parts: while self.send_parts:
# Send pending frames # Send pending frames
buf = self.send_parts.pop(0) buf = self.send_parts.pop(0)
sent = self.client.send(buf) sent = self.request.send(buf)
if sent == len(buf): if sent == len(buf):
self.traffic("<") self.traffic("<")
@ -446,7 +446,7 @@ Sec-WebSocket-Accept: %s\r
bufs = [] bufs = []
tdelta = int(time.time()*1000) - self.start_time tdelta = int(time.time()*1000) - self.start_time
buf = self.client.recv(self.buffer_size) buf = self.request.recv(self.buffer_size)
if len(buf) == 0: if len(buf) == 0:
closed = {'code': 1000, 'reason': "Client closed abruptly"} closed = {'code': 1000, 'reason': "Client closed abruptly"}
return bufs, closed return bufs, closed
@ -501,7 +501,7 @@ Sec-WebSocket-Accept: %s\r
msg = pack(">H%ds" % len(reason), code, reason) msg = pack(">H%ds" % len(reason), code, reason)
buf, h, t = self.encode_hybi(msg, opcode=0x08, base64=False) buf, h, t = self.encode_hybi(msg, opcode=0x08, base64=False)
self.client.send(buf) self.request.send(buf)
def do_websocket_handshake(self, headers, path): def do_websocket_handshake(self, headers, path):
h = self.headers = headers h = self.headers = headers
@ -689,7 +689,7 @@ Sec-WebSocket-Accept: %s\r
# handler process # handler process
try: try:
try: try:
self.client = self.do_handshake(startsock, address) self.request = self.do_handshake(startsock, address)
if self.record: if self.record:
# Record raw frame data as JavaScript array # Record raw frame data as JavaScript array
@ -708,7 +708,7 @@ Sec-WebSocket-Accept: %s\r
except self.CClose: except self.CClose:
# Close the client # Close the client
_, exc, _ = sys.exc_info() _, exc, _ = sys.exc_info()
if self.client: if self.request:
self.send_close(exc.args[0], exc.args[1]) self.send_close(exc.args[0], exc.args[1])
except self.EClose: except self.EClose:
_, exc, _ = sys.exc_info() _, exc, _ = sys.exc_info()
@ -725,10 +725,10 @@ Sec-WebSocket-Accept: %s\r
self.rec.write("'EOF'];\n") self.rec.write("'EOF'];\n")
self.rec.close() self.rec.close()
if self.client and self.client != startsock: if self.request and self.request != startsock:
# Close the SSL wrapped socket # Close the SSL wrapped socket
# Original socket closed by caller # Original socket closed by caller
self.client.close() self.request.close()
def new_client(self): def new_client(self):
""" Do something with a WebSockets client connection. """ """ Do something with a WebSockets client connection. """
@ -758,7 +758,7 @@ Sec-WebSocket-Accept: %s\r
while True: while True:
try: try:
try: try:
self.client = None self.request = None
startsock = None startsock = None
pid = err = 0 pid = err = 0
child_count = 0 child_count = 0

View File

@ -242,23 +242,23 @@ Traffic Legend:
cqueue = [] cqueue = []
c_pend = 0 c_pend = 0
tqueue = [] tqueue = []
rlist = [self.client, target] rlist = [self.request, target]
while True: while True:
wlist = [] wlist = []
if tqueue: wlist.append(target) if tqueue: wlist.append(target)
if cqueue or c_pend: wlist.append(self.client) if cqueue or c_pend: wlist.append(self.request)
ins, outs, excepts = select(rlist, wlist, [], 1) ins, outs, excepts = select(rlist, wlist, [], 1)
if excepts: raise Exception("Socket exception") if excepts: raise Exception("Socket exception")
if self.client in outs: if self.request in outs:
# Send queued target data to the client # Send queued target data to the client
c_pend = self.send_frames(cqueue) c_pend = self.send_frames(cqueue)
cqueue = [] cqueue = []
if self.client in ins: if self.request in ins:
# Receive client data, decode it, and queue for target # Receive client data, decode it, and queue for target
bufs, closed = self.recv_frames() bufs, closed = self.recv_frames()
tqueue.extend(bufs) tqueue.extend(bufs)