~adiroiban/twisted/twisted-5046

« back to all changes in this revision

Viewing changes to twisted/internet/cfreactor.py

  • Committer: exarkun
  • Date: 2011-08-03 10:20:35 UTC
  • Revision ID: svn-v4:bbbe8e31-12d6-0310-92fd-ac37d47ddeeb:trunk:32411
Merge cfreactor-import-5088

Author: exarkun
Reviewer: glyph
Fixes: #5088

Fix a bad import in cfreactor which caused it to be unusable.  Also fix the
call-fileno-after-removal behavior which #4539 fixed for the other reactors.

Show diffs side-by-side

added added

removed removed

Lines of Context:
21
21
 
22
22
from twisted.internet.interfaces import IReactorFDSet
23
23
from twisted.internet.posixbase import PosixReactorBase, _Waker
24
 
from twisted.internet.selectreactor import _NO_FILENO, _NO_FILEDESC
 
24
from twisted.internet.posixbase import _NO_FILEDESC
25
25
 
26
26
from twisted.python import log
27
27
 
167
167
                self._cfrunloop, smugglesrc, kCFRunLoopCommonModes
168
168
            )
169
169
            return
 
170
 
 
171
        why = None
 
172
        isRead = False
 
173
        src, skt, readWriteDescriptor, rw = self._fdmap[fd]
170
174
        try:
171
 
            src, skt, readWriteDescriptor, rw = self._fdmap[fd]
172
 
            why = None
173
 
            isRead = callbackType == kCFSocketReadCallBack
174
 
            try:
 
175
            if readWriteDescriptor.fileno() == -1:
 
176
                why = _NO_FILEDESC
 
177
            else:
 
178
                isRead = callbackType == kCFSocketReadCallBack
175
179
                # CFSocket seems to deliver duplicate read/write notifications
176
180
                # sometimes, especially a duplicate writability notification
177
181
                # when first registering the socket.  This bears further
187
191
                else:
188
192
                    if rw[_WRITE]:
189
193
                        why = readWriteDescriptor.doWrite()
190
 
            except:
191
 
                why = sys.exc_info()[1]
192
 
                log.err()
193
 
            handfn = getattr(readWriteDescriptor, 'fileno', None)
194
 
            if handfn is None:
195
 
                why = _NO_FILENO
196
 
            elif handfn() == -1:
197
 
                why = _NO_FILEDESC
198
 
            if why:
199
 
                self._disconnectSelectable(readWriteDescriptor, why, isRead)
200
194
        except:
 
195
            why = sys.exc_info()[1]
201
196
            log.err()
 
197
        if why:
 
198
            self._disconnectSelectable(readWriteDescriptor, why, isRead)
202
199
 
203
200
 
204
201
    def _watchFD(self, fd, descr, flag):