Beispiel #1
0
	def createInternetSocket(self):
		"""(internal) Create a non-blocking socket using
		self.addressFamily, self.socketType.
		"""
		s = socket.socket(self.addressFamily, self.socketType)
		s.setblocking(0)
		fdesc._setCloseOnExec(s.fileno())
		return s
Beispiel #2
0
    def createInternetSocket(self):
        """(internal) Create a non-blocking socket using
		self.addressFamily, self.socketType.
		"""
        s = socket.socket(self.addressFamily, self.socketType)
        s.setblocking(0)
        fdesc._setCloseOnExec(s.fileno())
        return s
Beispiel #3
0
    def __init__(self, reactor):
        """Initialize.
		"""
        self.reactor = reactor
        self.i, self.o = os.pipe()
        fdesc.setNonBlocking(self.i)
        fdesc._setCloseOnExec(self.i)
        fdesc.setNonBlocking(self.o)
        fdesc._setCloseOnExec(self.o)
        self.fileno = lambda: self.i
Beispiel #4
0
	def __init__(self, reactor):
		"""Initialize.
		"""
		self.reactor = reactor
		self.i, self.o = os.pipe()
		fdesc.setNonBlocking(self.i)
		fdesc._setCloseOnExec(self.i)
		fdesc.setNonBlocking(self.o)
		fdesc._setCloseOnExec(self.o)
		self.fileno = lambda: self.i
Beispiel #5
0
    def __init__(self, reactor=None):
        FileDescriptor.__init__(self, reactor=reactor)

        # Smart way to allow parametrization of libc so I can override
        # it and test for the system errors.
        self._fd = self._inotify.init()

        fdesc.setNonBlocking(self._fd)
        fdesc._setCloseOnExec(self._fd)

        # The next 2 lines are needed to have self.loseConnection()
        # to call connectionLost() on us. Since we already created the
        # fd that talks to inotify we want to be notified even if we
        # haven't yet started reading.
        self.connected = 1
        self._writeDisconnected = True

        self._buffer = ''
        self._watchpoints = {}
        self._watchpaths = {}
Beispiel #6
0
	def __init__(self, reactor=None):
		FileDescriptor.__init__(self, reactor=reactor)

		# Smart way to allow parametrization of libc so I can override
		# it and test for the system errors.
		self._fd = self._inotify.init()

		fdesc.setNonBlocking(self._fd)
		fdesc._setCloseOnExec(self._fd)

		# The next 2 lines are needed to have self.loseConnection()
		# to call connectionLost() on us. Since we already created the
		# fd that talks to inotify we want to be notified even if we
		# haven't yet started reading.
		self.connected = 1
		self._writeDisconnected = True

		self._buffer = ''
		self._watchpoints = {}
		self._watchpaths = {}
Beispiel #7
0
	def createInternetSocket(self):
		s = socket.socket(self.addressFamily, self.socketType)
		s.setblocking(0)
		fdesc._setCloseOnExec(s.fileno())
		return s
Beispiel #8
0
 def createInternetSocket(self):
     s = socket.socket(self.addressFamily, self.socketType)
     s.setblocking(0)
     fdesc._setCloseOnExec(s.fileno())
     return s
Beispiel #9
0
	def doRead(self):
		"""Called when my socket is ready for reading.

		This accepts a connection and calls self.protocol() to handle the
		wire-level protocol.
		"""
		try:
			if platformType == "posix":
				numAccepts = self.numberAccepts
			else:
				# win32 event loop breaks if we do more than one accept()
				# in an iteration of the event loop.
				numAccepts = 1
			for i in range(numAccepts):
				# we need this so we can deal with a factory's buildProtocol
				# calling our loseConnection
				if self.disconnecting:
					return
				try:
					skt, addr = self.socket.accept()
				except socket.error, e:
					if e.args[0] in (EWOULDBLOCK, EAGAIN):
						self.numberAccepts = i
						break
					elif e.args[0] == EPERM:
						# Netfilter on Linux may have rejected the
						# connection, but we get told to try to accept()
						# anyway.
						continue
					elif e.args[0] in (EMFILE, ENOBUFS, ENFILE, ENOMEM, ECONNABORTED):

						# Linux gives EMFILE when a process is not allowed
						# to allocate any more file descriptors.  *BSD and
						# Win32 give (WSA)ENOBUFS.  Linux can also give
						# ENFILE if the system is out of inodes, or ENOMEM
						# if there is insufficient memory to allocate a new
						# dentry.  ECONNABORTED is documented as possible on
						# both Linux and Windows, but it is not clear
						# whether there are actually any circumstances under
						# which it can happen (one might expect it to be
						# possible if a client sends a FIN or RST after the
						# server sends a SYN|ACK but before application code
						# calls accept(2), however at least on Linux this
						# _seems_ to be short-circuited by syncookies.

						log.msg("Could not accept new connection (%s)" % (
							errorcode[e.args[0]],))
						break
					raise

				fdesc._setCloseOnExec(skt.fileno())
				protocol = self.factory.buildProtocol(self._buildAddr(addr))
				if protocol is None:
					skt.close()
					continue
				s = self.sessionno
				self.sessionno = s+1
				transport = self.transport(skt, protocol, addr, self, s, self.reactor)
				transport = self._preMakeConnection(transport)
				protocol.makeConnection(transport)
			else:
Beispiel #10
0
    def doRead(self):
        """Called when my socket is ready for reading.

		This accepts a connection and calls self.protocol() to handle the
		wire-level protocol.
		"""
        try:
            if platformType == "posix":
                numAccepts = self.numberAccepts
            else:
                # win32 event loop breaks if we do more than one accept()
                # in an iteration of the event loop.
                numAccepts = 1
            for i in range(numAccepts):
                # we need this so we can deal with a factory's buildProtocol
                # calling our loseConnection
                if self.disconnecting:
                    return
                try:
                    skt, addr = self.socket.accept()
                except socket.error, e:
                    if e.args[0] in (EWOULDBLOCK, EAGAIN):
                        self.numberAccepts = i
                        break
                    elif e.args[0] == EPERM:
                        # Netfilter on Linux may have rejected the
                        # connection, but we get told to try to accept()
                        # anyway.
                        continue
                    elif e.args[0] in (EMFILE, ENOBUFS, ENFILE, ENOMEM,
                                       ECONNABORTED):

                        # Linux gives EMFILE when a process is not allowed
                        # to allocate any more file descriptors.  *BSD and
                        # Win32 give (WSA)ENOBUFS.  Linux can also give
                        # ENFILE if the system is out of inodes, or ENOMEM
                        # if there is insufficient memory to allocate a new
                        # dentry.  ECONNABORTED is documented as possible on
                        # both Linux and Windows, but it is not clear
                        # whether there are actually any circumstances under
                        # which it can happen (one might expect it to be
                        # possible if a client sends a FIN or RST after the
                        # server sends a SYN|ACK but before application code
                        # calls accept(2), however at least on Linux this
                        # _seems_ to be short-circuited by syncookies.

                        log.msg("Could not accept new connection (%s)" %
                                (errorcode[e.args[0]], ))
                        break
                    raise

                fdesc._setCloseOnExec(skt.fileno())
                protocol = self.factory.buildProtocol(self._buildAddr(addr))
                if protocol is None:
                    skt.close()
                    continue
                s = self.sessionno
                self.sessionno = s + 1
                transport = self.transport(skt, protocol, addr, self, s,
                                           self.reactor)
                transport = self._preMakeConnection(transport)
                protocol.makeConnection(transport)
            else: