1

我有一台服务器,它有一个进程等待连接,然后将套接字放入队列中,以便工作线程可以获取连接并与客户端通信并执行任何操作。

收货流程

    while True:
        # Wait for a connection
        print >>sys.stdout, 'waiting for a connection'

        readySocks = select.select(socksToCheck, [], [], d_consts.SELECT_SEC)
        for s in readySocks[0]:
            if s is serverClient:
                sock, client_address = s.accept()
                print >>sys.stdout, 'Client connection from ', client_address

                sockfd = multiprocessing.reduction.reduce_handle(sock.fileno())
                self.cmpQueue.put(inter_proc_msgs.ConMsg(sockfd, client_address))
                print >>sys.stdout, 'Client connection sent for processing: ', client_address

工作进程

        try:
            print '[%s] Checking Queue...' % self.name
            clientConMsg = self.cmpQueue.get(block=False) #throws exception if empty
            print 'something in queue'
            fileDescriptor = multiprocessing.reduction.rebuild_handle(clientConMsg.sockfd )
            newCon = socket.fromfd(fileDescriptor, socket.AF_INET, socket.SOCK_STREAM)
            print self.name, newCon, time.strftime("%a, %d %b %Y %H:%M:%S", time.gmtime())

            #wrap in ssl
            sslsock = ssl.wrap_socket(newCon,
                                 server_side=True,
                                 certfile="newcert.pem",
                                 keyfile="privkey.pem",
                                 ssl_version=ssl.PROTOCOL_SSLv23)
            ##non blocking
            sslsock.setblocking(0)
            #add to the list of client sockets to check with TTL
            self.clientSocketsWTTL.appendleft(self.createTupleSocknTTL(newCon, clientConMsg.clientAdd))

        except Queue.Empty:
            print '[%s] X Nothing in Queue...' % self.name 
            #pass

现在这在我使用 SSL 之前可以工作,但现在使用 SSL 我得到:

追溯

Traceback (most recent call last):
  File "/usr/lib/python2.7/multiprocessing/process.py", line 258, in _bootstrap
    self.run()
  File "/home/max/workspace/Dealer/src/client_msg_processor.py", line 35, in run
    self.processClientSideTasks()
  File "/home/max/workspace/Dealer/src/client_msg_processor.py", line 66, in processClientSideTasks
    self.testSSL()
  File "/home/max/workspace/Dealer/src/client_msg_processor.py", line 113, in testSSL
    ssl_version=ssl.PROTOCOL_SSLv23)
  File "/usr/lib/python2.7/ssl.py", line 381, in wrap_socket
    ciphers=ciphers)
  File "/usr/lib/python2.7/ssl.py", line 111, in __init__
    socket.__init__(self, _sock=sock._sock)
AttributeError: '_socket.socket' object has no attribute '_sock'

知道这是否可以解决吗?我拼命地试图避免不得不重组整个服务器。

4

1 回答 1

1

做可以newCon = socket.socket(_sock=newCon)解决问题。

http://www.velocityreviews.com/forums/t557014-socket-vs-_socketobject.html

于 2013-05-24T17:27:33.273 回答