Exception response in recv na close
This commit is contained in:
@@ -194,12 +194,15 @@ send a sip command to the server
|
||||
|
||||
recieve a answer from the sip server
|
||||
"""
|
||||
c = 0
|
||||
bytebuf=b''
|
||||
stringbuf=""
|
||||
while (self._socket != None) and (stringbuf.find("\r") == -1):
|
||||
while (self._socket != None) and (stringbuf.find("\r") == -1) and (c < 3):
|
||||
try:
|
||||
self.log.debug("LmwSip.recv: %s: Waiting for data" % self.cleartelnet);
|
||||
bytebuf = self._socket.recv(4096)
|
||||
if (len(bytebuf) == 0):
|
||||
c+=1
|
||||
self.log.debug("recv: bytebuf: %s" % bytebuf)
|
||||
if self.cleartelnet:
|
||||
if bytebuf[0] == 255:
|
||||
@@ -215,7 +218,11 @@ recieve a answer from the sip server
|
||||
self.log.error("SipLmw.recv: decode error: %s", e)
|
||||
self.closesocket()
|
||||
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")
|
||||
elif len(stringbuf) == 0:
|
||||
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_(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):
|
||||
capturedOutput = io.StringIO()
|
||||
sys.stdout = capturedOutput
|
||||
|
Reference in New Issue
Block a user