def startup(self, port = 0, host = ''):
self.shutdown()
self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
self.sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
try: self.sock.bind((host, port))
except:
try: self.sock.close()
except: pass
return -1
try: self.sock.listen(65536)
except:
try: self.sock.close()
except: pass
return -1
self.sock.setblocking(0)
self.port = self.sock.getsockname()[1]
self.state = 1
self.host = host
self.timeslap = long(time.time() * 1000)
return 0
# shutdown service
python类bind()的实例源码
def _psyco_speedup():
try:
import psyco
psyco.bind(preprocessor)
psyco.bind(configure)
psyco.bind(coremake)
psyco.bind(emake)
#print 'full optimaze'
except:
return False
return True
#----------------------------------------------------------------------
# distribution
#----------------------------------------------------------------------
def _psyco_speedup():
try:
import psyco
psyco.bind(rc4crypt)
psyco.bind(netstream)
psyco.bind(nethost)
psyco.bind(CCLIB)
except:
return False
return True
def psyco_speedup ():
try:
import psyco
psyco.bind(chessboard)
psyco.bind(evaluation)
except:
pass
return 0
def speedup():
try:
import psyco
psyco.bind(disjointset)
psyco.bind(vector2d)
psyco.bind(line2d)
psyco.bind(savebmp)
except ImportError:
pass