Commit 8c2c8e00 authored by Yoshinori Okuji's avatar Yoshinori Okuji

Reoreder initialization sequences so that connection objects are not...

Reoreder initialization sequences so that connection objects are not registered to an event manager until they are initialized.

git-svn-id: https://svn.erp5.org/repos/neo/branches/prototype3@216 71dcc9de-d417-0410-9af5-da40c76e7ee4
parent 2107a5ff
......@@ -82,15 +82,15 @@ class ListeningConnection(BaseConnection):
class Connection(BaseConnection):
"""A connection."""
def __init__(self, event_manager, handler, s = None, addr = None):
BaseConnection.__init__(self, event_manager, handler, s = s, addr = addr)
if s is not None:
event_manager.addReader(self)
self.read_buf = []
self.write_buf = []
self.cur_id = 0
self.event_dict = {}
self.aborted = False
self.uuid = None
BaseConnection.__init__(self, event_manager, handler, s = s, addr = addr)
if s is not None:
event_manager.addReader(self)
def getUUID(self):
return self.uuid
......@@ -271,8 +271,8 @@ class Connection(BaseConnection):
class ClientConnection(Connection):
"""A connection from this node to a remote node."""
def __init__(self, event_manager, handler, addr = None, **kw):
Connection.__init__(self, event_manager, handler, addr = addr)
self.connecting = False
Connection.__init__(self, event_manager, handler, addr = addr)
handler.connectionStarted(self)
try:
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
......@@ -316,13 +316,17 @@ class ServerConnection(Connection):
class MTClientConnection(ClientConnection):
"""A Multithread-safe version of ClientConnection."""
def __init__(self, *args, **kwargs):
super(MTClientConnection, self).__init__(*args, **kwargs)
lock = RLock()
self.acquire = lock.acquire
self.release = lock.release
super(MTClientConnection, self).__init__(*args, **kwargs)
def lock(self, blocking = 1):
return self.acquire(blocking = blocking)
try:
return self.acquire(blocking = blocking)
except:
import pdb
pdb.set_trace()
def unlock(self):
self.release()
......@@ -330,10 +334,10 @@ class MTClientConnection(ClientConnection):
class MTServerConnection(ServerConnection):
"""A Multithread-safe version of ServerConnection."""
def __init__(self, *args, **kwargs):
super(MTClientConnection, self).__init__(*args, **kwargs)
lock = RLock()
self.acquire = lock.acquire
self.release = lock.release
super(MTServerConnection, self).__init__(*args, **kwargs)
def lock(self, blocking = 1):
return self.acquire(blocking = blocking)
......
......@@ -214,28 +214,40 @@ class EpollEventManager(object):
pass
def addReader(self, conn):
fd = conn.getSocket().fileno()
if fd not in self.reader_set:
self.reader_set.add(fd)
self.epoll.modify(fd, 1, fd in self.writer_set)
try:
fd = conn.getSocket().fileno()
if fd not in self.reader_set:
self.reader_set.add(fd)
self.epoll.modify(fd, 1, fd in self.writer_set)
except AttributeError:
pass
def removeReader(self, conn):
fd = conn.getSocket().fileno()
if fd in self.reader_set:
self.reader_set.remove(fd)
self.epoll.modify(fd, 0, fd in self.writer_set)
try:
fd = conn.getSocket().fileno()
if fd in self.reader_set:
self.reader_set.remove(fd)
self.epoll.modify(fd, 0, fd in self.writer_set)
except AttributeError:
pass
def addWriter(self, conn):
fd = conn.getSocket().fileno()
if fd not in self.writer_set:
self.writer_set.add(fd)
self.epoll.modify(fd, fd in self.reader_set, 1)
try:
fd = conn.getSocket().fileno()
if fd not in self.writer_set:
self.writer_set.add(fd)
self.epoll.modify(fd, fd in self.reader_set, 1)
except AttributeError:
pass
def removeWriter(self, conn):
fd = conn.getSocket().fileno()
if fd in self.writer_set:
self.writer_set.remove(fd)
self.epoll.modify(fd, fd in self.reader_set, 0)
try:
fd = conn.getSocket().fileno()
if fd in self.writer_set:
self.writer_set.remove(fd)
self.epoll.modify(fd, fd in self.reader_set, 0)
except AttributeError:
pass
# Default to EpollEventManager.
EventManager = EpollEventManager
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