mirror of
https://github.com/schollz/croc.git
synced 2024-11-24 16:23:47 +03:00
better cleaning of empty rooms
This commit is contained in:
parent
1802ebcd00
commit
7d91f8200c
@ -55,13 +55,18 @@ func (s *server) start() (err error) {
|
||||
go func() {
|
||||
for {
|
||||
time.Sleep(10 * time.Minute)
|
||||
roomsToDelete := []string{}
|
||||
s.rooms.Lock()
|
||||
for room := range s.rooms.rooms {
|
||||
if time.Since(s.rooms.rooms[room].opened) > 3*time.Hour {
|
||||
delete(s.rooms.rooms, room)
|
||||
roomsToDelete = append(roomsToDelete,room)
|
||||
}
|
||||
}
|
||||
s.rooms.Unlock()
|
||||
|
||||
for _, room := range roomsToDelete {
|
||||
s.deleteRoom(room)
|
||||
}
|
||||
}
|
||||
}()
|
||||
|
||||
|
@ -1,7 +1,6 @@
|
||||
package tcp
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
@ -11,9 +10,8 @@ import (
|
||||
func TestTCP(t *testing.T) {
|
||||
go Run("debug", "8081", "8082")
|
||||
time.Sleep(100 * time.Millisecond)
|
||||
c1, banner, ipaddr, err := ConnectToTCPServer("localhost:8081", "testRoom")
|
||||
c1, banner, _, err := ConnectToTCPServer("localhost:8081", "testRoom")
|
||||
assert.Equal(t, banner, "8082")
|
||||
assert.True(t, strings.HasPrefix(ipaddr, "127.0.0.1"))
|
||||
assert.Nil(t, err)
|
||||
c2, _, _, err := ConnectToTCPServer("localhost:8081", "testRoom")
|
||||
assert.Nil(t, err)
|
||||
|
Loading…
Reference in New Issue
Block a user