// Test push and pop of queue using normal queue not-safe goroutine func TestDefQueue(t *testing.T) { q := queue.NewDefQueue() q.Push("hello") q.Push("world") v, ok := q.Pop() if !ok { t.Error("Pop failed!") } if v.(string) != "hello" { t.Errorf("Expected : hello, Result : %s", v.(string)) } if q.Len() != 1 { t.Errorf("Expected queue size : 1, Result : %d", q.Len()) } v, ok = q.Pop() if !ok { t.Error("Pop failed!") } if v.(string) != "world" { t.Errorf("Expected : world, Result : %s", v.(string)) } if q.Len() != 0 { t.Errorf("Expected queue size : 0, Result : %d", q.Len()) } }
func NewChatServer(port int16) *ChatServer { s := new(ChatServer) s.protocol = gonet.NewPacketProtocol() s.stub.OnReqLogin = s.OnReqLogin s.users = make(map[*gonet.Client]*ChatUser) s.freeSessionId = queue.NewDefQueue() // Generate a pool for free session ids for i := 0; i < MAX_USERS; i++ { s.freeSessionId.Push(int32(i)) } s.Init(port, s, s.protocol, true) return s }