S
Stéphane Ninin
Hi.
I am trying to understand the asyncore module.
I read it and found something which seems strange
(nb: I am still using Python 2.2.2).
I will keep only what seems useful in this post:
class dispatcher:
# [...]
def __init__ (self, sock=None, map=None):
if sock:
self.set_socket (sock, map)
# I think it should inherit this anyway
self.socket.setblocking (0)
self.connected = 1
# XXX Does the constructor require that the socket passed
# be connected?
try:
self.addr = sock.getpeername()
except socket.error:
# The addr isn't crucial
pass
else:
self.socket = None
def add_channel (self, map=None):
#self.log_info ('adding channel %s' % self)
if map is None:
map=socket_map
map [self._fileno] = self
def create_socket (self, family, type):
self.family_and_type = family, type
self.socket = socket.socket (family, type)
self.socket.setblocking(0)
self._fileno = self.socket.fileno()
self.add_channel()
My problem is the following:
what happens if dispatcher is created with non global map
but with no socket, like:
d=dispatcher(self,sock=None,map=some_map)
then create_socket called:
d.create_socket()
This dispatcher will be added to the global map.
But probably user will call asyncore.loop(map=some_map),
as d was buillt with this map.
Is there not something wrong here, or am I just missing something ?
Regards,
I am trying to understand the asyncore module.
I read it and found something which seems strange
(nb: I am still using Python 2.2.2).
I will keep only what seems useful in this post:
class dispatcher:
# [...]
def __init__ (self, sock=None, map=None):
if sock:
self.set_socket (sock, map)
# I think it should inherit this anyway
self.socket.setblocking (0)
self.connected = 1
# XXX Does the constructor require that the socket passed
# be connected?
try:
self.addr = sock.getpeername()
except socket.error:
# The addr isn't crucial
pass
else:
self.socket = None
def add_channel (self, map=None):
#self.log_info ('adding channel %s' % self)
if map is None:
map=socket_map
map [self._fileno] = self
def create_socket (self, family, type):
self.family_and_type = family, type
self.socket = socket.socket (family, type)
self.socket.setblocking(0)
self._fileno = self.socket.fileno()
self.add_channel()
My problem is the following:
what happens if dispatcher is created with non global map
but with no socket, like:
d=dispatcher(self,sock=None,map=some_map)
then create_socket called:
d.create_socket()
This dispatcher will be added to the global map.
But probably user will call asyncore.loop(map=some_map),
as d was buillt with this map.
Is there not something wrong here, or am I just missing something ?
Regards,