Exception response in recv na close
This commit is contained in:
@@ -194,16 +194,19 @@ send a sip command to the server
|
|||||||
|
|
||||||
recieve a answer from the sip server
|
recieve a answer from the sip server
|
||||||
"""
|
"""
|
||||||
|
c = 0
|
||||||
bytebuf=b''
|
bytebuf=b''
|
||||||
stringbuf=""
|
stringbuf=""
|
||||||
while (self._socket != None) and (stringbuf.find("\r") == -1):
|
while (self._socket != None) and (stringbuf.find("\r") == -1) and (c < 3):
|
||||||
try:
|
try:
|
||||||
self.log.debug("LmwSip.recv: %s: Waiting for data" % self.cleartelnet);
|
self.log.debug("LmwSip.recv: %s: Waiting for data" % self.cleartelnet);
|
||||||
bytebuf = self._socket.recv(4096)
|
bytebuf = self._socket.recv(4096)
|
||||||
self.log.debug("recv: bytebuf: %s" % bytebuf)
|
if (len(bytebuf) == 0):
|
||||||
if self.cleartelnet:
|
c+=1
|
||||||
if bytebuf[0] == 255:
|
self.log.debug("recv: bytebuf: %s" % bytebuf)
|
||||||
bytebuf = b''
|
if self.cleartelnet:
|
||||||
|
if bytebuf[0] == 255:
|
||||||
|
bytebuf = b''
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
self.log.error("SipLmw.recv: socket timeout: %s", e)
|
self.log.error("SipLmw.recv: socket timeout: %s", e)
|
||||||
self.closesocket()
|
self.closesocket()
|
||||||
@@ -215,7 +218,11 @@ recieve a answer from the sip server
|
|||||||
self.log.error("SipLmw.recv: decode error: %s", e)
|
self.log.error("SipLmw.recv: decode error: %s", e)
|
||||||
self.closesocket()
|
self.closesocket()
|
||||||
raise LmwSipDecodeError("LmwSip.recv: decode error", bytebuf)
|
raise LmwSipDecodeError("LmwSip.recv: decode error", bytebuf)
|
||||||
if self._socket == None:
|
if (c>=3) and (len(stringbuf) == 0):
|
||||||
|
self.log.warning("LmwSip.recv: No data recieved")
|
||||||
|
self.closesocket()
|
||||||
|
raise LmwSipConnectError("LmwSip.recv: socket close")
|
||||||
|
elif self._socket == None:
|
||||||
self.log.warning("LmwSip.recv: No connection")
|
self.log.warning("LmwSip.recv: No connection")
|
||||||
elif len(stringbuf) == 0:
|
elif len(stringbuf) == 0:
|
||||||
self.log.warning("LmwSip.recv: No data")
|
self.log.warning("LmwSip.recv: No data")
|
||||||
|
@@ -75,6 +75,12 @@ class lmwsipTest(unittest.TestCase):
|
|||||||
self.assertEqual(self.sip._roundtime_(t1, "D10"), t1)
|
self.assertEqual(self.sip._roundtime_(t1, "D10"), t1)
|
||||||
self.assertEqual(self.sip._roundtime_(t2, "D10"), t1)
|
self.assertEqual(self.sip._roundtime_(t2, "D10"), t1)
|
||||||
|
|
||||||
|
def test_closerecv(self):
|
||||||
|
self.login()
|
||||||
|
self.sip.send("CLOSE")
|
||||||
|
with self.assertRaises(lmwsip.LmwSipConnectError):
|
||||||
|
self.sip.recv()
|
||||||
|
|
||||||
def test_run(self):
|
def test_run(self):
|
||||||
capturedOutput = io.StringIO()
|
capturedOutput = io.StringIO()
|
||||||
sys.stdout = capturedOutput
|
sys.stdout = capturedOutput
|
||||||
|
Reference in New Issue
Block a user