<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def poll(self):
 """ Perform a non-blocking scan of recv and send states on the server and client connection sockets. Process new connection requests, read incomming data, and send outgoing data. Sends and receives may be partial. """

        #print len(self.connections)
        ## Build a list of connections to test for receive data pending
        recv_list = [self.server_fileno]    # always add the server

        for client in self.clients.values():
            if client.active:
                recv_list.append(client.fileno)
            ## Delete inactive connections from the dictionary
            else:
                #print "-- Lost connection to %s" % client.addrport()
                #client.sock.close()
                self.on_disconnect(client)
                del self.clients[client.fileno]


        ## Build a list of connections that need to send data
        send_list = []
        for client in self.clients.values():
            if client.send_pending:
                send_list.append(client.fileno)

        ## Get active socket file descriptors from select.select()
        try:
            rlist, slist, elist = select.select(recv_list, send_list, [],
                self.timeout)

        except select.error, err:
            ## If we can't even use select(), game over man, game over
            print >> sys.stderr, ("!! FATAL SELECT error '%d:%s'!"
                % (err[0], err[1]))
            sys.exit(1)

        ## Process socket file descriptors with data to recieve
        for sock_fileno in rlist:

            ## If it's coming from the server's socket then this is a new
            ## connection request.
            if sock_fileno == self.server_fileno:

                try:
                    sock, addr_tup = self.server_socket.accept()

                except socket.error, err:
                    print >> sys.stderr, ("!! ACCEPT error '%d:%s'." %
                        (err[0], err[1]))
                    continue

                ## Check for maximum connections
                if self.client_count() >= MAX_CONNECTIONS:
                    print '?? Refusing new connection; maximum in use.'
                    sock.close()
                    continue

                new_client = TelnetClient(sock, addr_tup)
                #print "++ Opened connection to %s" % new_client.addrport()
                ## Add the connection to our dictionary and call handler
                self.clients[new_client.fileno] = new_client
                self.on_connect(new_client)

            else:
                ## Call the connection's recieve method
                try:
                    self.clients[sock_fileno].socket_recv()
                except BogConnectionLost:
                    self.clients[sock_fileno].deactivate()

        ## Process sockets with data to send
        for sock_fileno in slist:
            ## Call the connection's send method
            self.clients[sock_fileno].socket_send()