Exemplo n.º 1
0
/**
 * client tcp accept
 * one thread call
 **/
func processNewAcceptedConn(conn net.Conn) *udpsession.Session {
	s := udpsession.CreateNewSession(sessionCount, LOG)
	s.C = &conn
	s.ModulesCount = ut.ModulesCount
	idSessionMap[sessionCount] = s
	sessionCount++
	//LOG.Println("sessionCount", sessionCount)
	return s
}
Exemplo n.º 2
0
func getSession(id uint32) *udpsession.Session {
	s, ok := idSessionMap[id]
	if !ok {
		lock.Lock()
		s, ok = idSessionMap[id]
		if !ok {
			s = udpsession.CreateNewSession(id, LOG)
			s.ModulesCount = ut.ModulesCount
			idSessionMap[id] = s
			ok := connectToServer(s)
			if !ok {
				delete(idSessionMap, id)
				s.Destroy(false)
				lock.Unlock()
				return nil
			}
			lock.Unlock()
			go processRead(s)
		}
	}
	return s
}