Support IPv6 connections

This commit is contained in:
Lukas Martini 2015-12-04 11:41:47 +01:00 committed by jacob1
parent 9f64b13489
commit e7cdf1eb50

View File

@ -21,6 +21,7 @@ import sys
import threading
import time
import traceback
import os
from oyoyo.parse import parse_raw_irc_command
@ -99,7 +100,7 @@ class IRCClient(object):
To enable blocking pass blocking=True.
"""
self.socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
self.socket = None
self.nickname = ""
self.hostmask = ""
self.ident = ""
@ -120,10 +121,6 @@ class IRCClient(object):
self.__dict__.update(kwargs)
self.command_handler = cmd_handler
if self.use_ssl:
self.socket = ssl.wrap_socket(self.socket)
self._end = 0
def send(self, *args, **kwargs):
@ -177,13 +174,17 @@ class IRCClient(object):
retries = 0
while True:
try:
self.socket.connect(("{0}".format(self.host), self.port))
self.socket = socket.create_connection(("{0}".format(self.host), self.port))
break
except socket.error as e:
retries += 1
self.stream_handler('Error: {0}'.format(e), level="warning")
if retries > 3:
break
exit(os.EX_UNAVAILABLE)
if self.use_ssl:
self.socket = ssl.wrap_socket(self.socket)
if not self.blocking:
self.socket.setblocking(0)