Skip to content

Commit

Permalink
python-bareos: use socket.create_connection()
Browse files Browse the repository at this point in the history
- remove hard-coded AF_INET in socket creation.
- replace socket.connect() by a higher-level function
  socket.create_connection() allowing AF_INET6 familly connection.
- set a default of 30 to self.timeout, simplify code to remove
  `if self.timeout ...`

Signed-off-by: Bruno Friedmann <bruno.friedmann@bareos.com>
  • Loading branch information
bruno-at-bareos committed Jan 4, 2024
1 parent 57b632d commit 7c36267
Showing 1 changed file with 2 additions and 5 deletions.
7 changes: 2 additions & 5 deletions python-bareos/bareos/bsock/lowlevel.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ def __init__(self):
self.logger.debug("init")
self.status = None
self.address = None
self.timeout = None
self.timeout = 30
self.password = None
self.pam_username = None
self.pam_password = None
Expand Down Expand Up @@ -236,12 +236,9 @@ def __connect(self):
return auth

def __connect_plain(self):
self.socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
# initialize
try:
if self.timeout:
self.socket.settimeout(self.timeout)
self.socket.connect((self.address, self.port))
self.socket=socket.create_connection((self.address, self.port),self.timeout)
except (socket.error, socket.gaierror) as e:
self._handleSocketError(e)
raise bareos.exceptions.ConnectionError(
Expand Down

0 comments on commit 7c36267

Please sign in to comment.