Skip to content

Commit 322d505

Browse files
committed
Simplified _recv_msg()
1 parent a9bdcb3 commit 322d505

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

rtsp.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ def __init__(self, url, dest_ip='', callback=None, socks=None):
6161
self._parsed_url.path
6262
self._session_id = ''
6363
self._sock = None
64-
self._socks = socks
64+
self._socks = socks
6565
self.cur_range = 'npt=end-'
6666
self.cur_scale = 1
6767
self.location = ''
@@ -153,6 +153,9 @@ def _connect_server(self):
153153
try:
154154
self._sock = self._socks or socket.socket(socket.AF_INET, socket.SOCK_STREAM)
155155
self._sock.connect((self._parsed_url.hostname, self._server_port))
156+
# Turning off blocking here, as the socket is currently monitored
157+
# in its own thread.
158+
self._sock.setblocking(0)
156159
except socket.error as e:
157160
raise RTSPNetError('socket error: %s [%s:%d]' %
158161
(e, self._parsed_url.hostname, self._server_port))
@@ -176,12 +179,8 @@ def _recv_msg(self):
176179
'''Continously check for new data and put it in
177180
cache.'''
178181
try:
179-
self._sock.setblocking(0) #Turn off blocking for the socket
180-
while not (not self.running):
181-
more = self._sock.recv(2048)
182-
if not more:
183-
break
184-
self.cache(more.decode())
182+
more = self._sock.recv(2048)
183+
self.cache(more.decode())
185184
except socket.error as e:
186185
RTSPNetError('Receive data error: %s' % e)
187186

0 commit comments

Comments
 (0)