Exemplo n.º 1
0
def http_recv_package(body, addr, fd, header):
    global g_index
    global http_work_thread
    thread_len = len(g_szWorkThread)
    g_index += 1
    if g_index >= thread_len:
        g_index = 0
    data = MsgQueue.ServerMessage()
    data.m_iId = g_index + 1
    data.m_sData = body
    MsgQueue.ForwardServer(data)
    http_work_thread.m_stPartsMgr.m_http_server.http_response(fd, "OK")
Exemplo n.º 2
0
	def __init__(self,stPartsMgr):
		#部件
		self.m_stPartsMgr = stPartsMgr
		#NetFdData
		self.m_hFdData    = {}
		#网络回调
		stPartsMgr.m_stMsgQ.RegMsg(MsgQueue.MsgData(MsgQueue.MsgQType.eMsgNetSock,self.NetDispatchMsg))
Exemplo n.º 3
0
	def DispatchList(self,stTimeNode):
		while stTimeNode != None:
			self.m_stNextNode = stTimeNode.m_stNext
			if stTimeNode.m_bLoop:
				stTimeNode.Reset()
				stTimeNode.m_iExpire = self.GetExpire(stTimeNode.m_iTime)
				self.AddNode(stTimeNode)
			else:
				self.RemoveSession(stTimeNode.m_iId,stTimeNode.m_iSession)
			# logger.debug("dispatch %s node=%s"%(stTimeNode.Log(),stTimeNode))
			self.UnLock()
			MsgQueue.ForwardTimerMsg(stTimeNode)
			self.Lock()
			stTimeNode = self.m_stNextNode
		self.m_stNextNode = None
Exemplo n.º 4
0
    MsgQueue.ForwardServer(data)
    http_work_thread.m_stPartsMgr.m_http_server.http_response(fd, "OK")


if __name__ == "__main__":
    config_log()
    #定时器
    g_time_thread = TimerThread()
    #api 网络
    g_sock_thread = NetThread()
    #工作服个数
    work_thread_count = 20
    for i in xrange(work_thread_count):
        cur = WorkThread(i + 1)
        cur.m_stPartsMgr = PartsMgr(cur)
        cur.m_stPartsMgr.m_stMsgQ = MsgQueue.MsgQueue(cur.m_stPartsMgr)
        cur.m_stPartsMgr.m_stNetServer = NetServer.NetServer(cur.m_stPartsMgr)
        cur.m_stPartsMgr.m_best_mysql = best_mysql.best_mysql(cur.m_stPartsMgr)
        cur.m_stPartsMgr.m_best_mysql.init_consumer()
        g_szWorkThread.append(cur)
    #http 服
    http_work_thread = WorkThread(len(g_szWorkThread) + 1)
    http_work_thread.m_stPartsMgr = PartsMgr(http_work_thread)
    http_work_thread.m_stPartsMgr.m_stMsgQ = MsgQueue.MsgQueue(
        http_work_thread.m_stPartsMgr)
    http_work_thread.m_stPartsMgr.m_stNetServer = NetServer.NetServer(
        http_work_thread.m_stPartsMgr)
    http_work_thread.m_stPartsMgr.m_http_server = http_recv.http_recv(
        http_work_thread.m_stPartsMgr, http_recv_package, False)
    http_work_thread.m_stPartsMgr.m_stTimerMgr = g_time_thread.m_stTimerMgr
    http_work_thread.m_stPartsMgr.m_stSockServer = g_sock_thread.m_stSockServer
Exemplo n.º 5
0
    g_type %= 3
    g_recv_mgr.http_response(fd, http_get_data1)


g_index = 0
g_body = None
g_recv_mgr = None
g_stWork = WorkThread()
g_body = ""
g_type = 1

#主函数
if __name__ == "__main__":
    ConfigLog()
    #消息调度模块
    g_stWork.m_stPartsMgr.m_stMsgQ = MsgQueue.MsgQueue(g_stWork.m_stPartsMgr)
    #定时器模块
    g_stWork.m_stPartsMgr.m_stTimerMgr = TimeMgr.WheelTimerMgr()
    #底层网络服务
    g_stWork.m_stPartsMgr.m_stSockServer = SocketServer.SocketServer()
    #逻辑网络服务
    g_stWork.m_stPartsMgr.m_stNetServer = NetServer.NetServer(
        g_stWork.m_stPartsMgr)
    #http 模块
    g_recv_mgr = http_recv.http_recv(g_stWork.m_stPartsMgr, http_recv_package)
    #开始 http 服务
    g_recv_mgr.start_server("0.0.0.0", 8889)
    #设置 epoll_wait 等时间为 0
    g_stWork.m_stPartsMgr.m_stSockServer.SetWaitTime(0)
    while True:
        while g_stWork.m_stPartsMgr.m_stSockServer.ServerPoll():
Exemplo n.º 6
0
 def __init__(self, parts_mgr):
     self.m_parts_mgr = parts_mgr
     self.m_consumer = best_consumer.best_consumer()
     parts_mgr.m_stMsgQ.RegMsg(
         MsgQueue.MsgData(MsgQueue.MsgQType.eMsgServer,
                          self.server_dispathch_msg))
Exemplo n.º 7
0
            pass


#主函数
if __name__ == '__main__':
    Watcher()
    g_stWorkThread = WorkThread(1)
    g_stNetThread = NetThread()
    g_stTimerThread = TimerThread()

    ConfigLog()

    #设置部件
    g_stWorkThread.m_stPart.m_stThread = g_stWorkThread
    #消息调度模块
    g_stWorkThread.m_stPart.m_stMsgQ = MsgQueue.MsgQueue(
        g_stWorkThread.m_stPart)
    #定时器模块
    g_stWorkThread.m_stPart.m_stTimerMgr = g_stTimerThread.m_stTimerMgr
    #底层网络服务
    g_stWorkThread.m_stPart.m_stSockServer = g_stNetThread.m_stSockServer
    #逻辑网络服务
    g_stWorkThread.m_stPart.m_stNetServer = NetServer.NetServer(
        g_stWorkThread.m_stPart)

    ListenSockTest()

    #启动工作线程
    g_stWorkThread.start()
    #启动网络线程
    g_stNetThread.start()
    #启动定时器线程