Commit cb034f5f authored by olivier R-D's avatar olivier R-D

Revert "Prevent the UASocketClient from hanging (#316)"

This reverts commit 3f750a92.
parent 77ec2c1a
...@@ -79,7 +79,7 @@ class Client(object): ...@@ -79,7 +79,7 @@ class Client(object):
which offers the raw OPC-UA services interface. which offers the raw OPC-UA services interface.
""" """
def __init__(self, url, timeout=4, socket_timeout=10): def __init__(self, url, timeout=4):
""" """
:param url: url of the server. :param url: url of the server.
...@@ -101,7 +101,7 @@ class Client(object): ...@@ -101,7 +101,7 @@ class Client(object):
self.secure_channel_timeout = 3600000 # 1 hour self.secure_channel_timeout = 3600000 # 1 hour
self.session_timeout = 3600000 # 1 hour self.session_timeout = 3600000 # 1 hour
self._policy_ids = [] self._policy_ids = []
self.uaclient = UaClient(timeout, socket_timeout) self.uaclient = UaClient(timeout)
self.user_certificate = None self.user_certificate = None
self.user_private_key = None self.user_private_key = None
self._session_counter = 1 self._session_counter = 1
......
...@@ -18,12 +18,11 @@ class UASocketClient(object): ...@@ -18,12 +18,11 @@ class UASocketClient(object):
handle socket connection and send ua messages handle socket connection and send ua messages
timeout is the timeout used while waiting for an ua answer from server timeout is the timeout used while waiting for an ua answer from server
""" """
def __init__(self, timeout=1, security_policy=ua.SecurityPolicy(), socket_timeout=10): def __init__(self, timeout=1, security_policy=ua.SecurityPolicy()):
self.logger = logging.getLogger(__name__ + ".Socket") self.logger = logging.getLogger(__name__ + ".Socket")
self._thread = None self._thread = None
self._lock = Lock() self._lock = Lock()
self.timeout = timeout self.timeout = timeout
self.socket_timeout = socket_timeout
self._socket = None self._socket = None
self._do_stop = False self._do_stop = False
self.authentication_token = ua.NodeId() self.authentication_token = ua.NodeId()
...@@ -133,7 +132,7 @@ class UASocketClient(object): ...@@ -133,7 +132,7 @@ class UASocketClient(object):
connect to server socket and start receiving thread connect to server socket and start receiving thread
""" """
self.logger.info("opening connection") self.logger.info("opening connection")
sock = socket.create_connection((host, port), timeout=self.socket_timeout) sock = socket.create_connection((host, port))
sock.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1) # nodelay ncessary to avoid packing in one frame, some servers do not like it sock.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1) # nodelay ncessary to avoid packing in one frame, some servers do not like it
self._socket = utils.SocketWrapper(sock) self._socket = utils.SocketWrapper(sock)
self.start() self.start()
...@@ -195,12 +194,11 @@ class UaClient(object): ...@@ -195,12 +194,11 @@ class UaClient(object):
uaprotocol_auto.py and uaprotocol_hand.py available under opcua.ua uaprotocol_auto.py and uaprotocol_hand.py available under opcua.ua
""" """
def __init__(self, timeout=1, socket_timeout=10): def __init__(self, timeout=1):
self.logger = logging.getLogger(__name__) self.logger = logging.getLogger(__name__)
# _publishcallbacks should be accessed in recv thread only # _publishcallbacks should be accessed in recv thread only
self._publishcallbacks = {} self._publishcallbacks = {}
self._timeout = timeout self._timeout = timeout
self._socket_timeout = socket_timeout
self._uasocket = None self._uasocket = None
self._security_policy = ua.SecurityPolicy() self._security_policy = ua.SecurityPolicy()
...@@ -211,7 +209,7 @@ class UaClient(object): ...@@ -211,7 +209,7 @@ class UaClient(object):
""" """
connect to server socket and start receiving thread connect to server socket and start receiving thread
""" """
self._uasocket = UASocketClient(self._timeout, security_policy=self._security_policy, socket_timeout=self._socket_timeout) self._uasocket = UASocketClient(self._timeout, security_policy=self._security_policy)
return self._uasocket.connect_socket(host, port) return self._uasocket.connect_socket(host, port)
def disconnect_socket(self): def disconnect_socket(self):
......
...@@ -4,7 +4,6 @@ from concurrent.futures import Future ...@@ -4,7 +4,6 @@ from concurrent.futures import Future
import functools import functools
import threading import threading
from socket import error as SocketError from socket import error as SocketError
from socket import timeout as SocketTimeout
try: try:
# we prefer to use bundles asyncio version, otherwise fallback to trollius # we prefer to use bundles asyncio version, otherwise fallback to trollius
...@@ -30,10 +29,6 @@ class SocketClosedException(UaError): ...@@ -30,10 +29,6 @@ class SocketClosedException(UaError):
pass pass
class SocketTimeoutException(UaError):
pass
class Buffer(object): class Buffer(object):
""" """
...@@ -107,8 +102,6 @@ class SocketWrapper(object): ...@@ -107,8 +102,6 @@ class SocketWrapper(object):
while size > 0: while size > 0:
try: try:
chunk = self.socket.recv(size) chunk = self.socket.recv(size)
except SocketTimeout as ex:
raise SocketTimeoutException("Server socket has timed out")
except (OSError, SocketError) as ex: except (OSError, SocketError) as ex:
raise SocketClosedException("Server socket has closed", ex) raise SocketClosedException("Server socket has closed", ex)
if not chunk: if not chunk:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment