1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

Merge pull request #5827 from vieux/fix_multiple_events_on_same_computer

allow 2 docker events to be opened on the same computer over unix socket
This commit is contained in:
Victor Vieux 2014-05-16 18:17:46 -07:00
commit 9e7757a3d2
3 changed files with 11 additions and 10 deletions

View file

@ -244,7 +244,7 @@ func getEvents(eng *engine.Engine, version version.Version, w http.ResponseWrite
return err
}
var job = eng.Job("events", r.RemoteAddr)
var job = eng.Job("events")
streamJSON(job, w, true)
job.Setenv("since", r.Form.Get("since"))
job.Setenv("until", r.Form.Get("until"))

View file

@ -198,7 +198,7 @@ func (srv *Server) ContainerKill(job *engine.Job) engine.Status {
return engine.StatusOK
}
func (srv *Server) EvictListener(from string) {
func (srv *Server) EvictListener(from int64) {
srv.Lock()
if old, ok := srv.listeners[from]; ok {
delete(srv.listeners, from)
@ -208,12 +208,12 @@ func (srv *Server) EvictListener(from string) {
}
func (srv *Server) Events(job *engine.Job) engine.Status {
if len(job.Args) != 1 {
return job.Errorf("Usage: %s FROM", job.Name)
if len(job.Args) != 0 {
return job.Errorf("Usage: %s", job.Name)
}
var (
from = job.Args[0]
from = time.Now().UTC().UnixNano()
since = job.GetenvInt64("since")
until = job.GetenvInt64("until")
timeout = time.NewTimer(time.Unix(until, 0).Sub(time.Now()))
@ -2432,7 +2432,7 @@ func NewServer(eng *engine.Engine, config *daemonconfig.Config) (*Server, error)
pullingPool: make(map[string]chan struct{}),
pushingPool: make(map[string]chan struct{}),
events: make([]utils.JSONMessage, 0, 64), //only keeps the 64 last events
listeners: make(map[string]chan utils.JSONMessage),
listeners: make(map[int64]chan utils.JSONMessage),
running: true,
}
daemon.SetServer(srv)
@ -2494,7 +2494,7 @@ type Server struct {
pullingPool map[string]chan struct{}
pushingPool map[string]chan struct{}
events []utils.JSONMessage
listeners map[string]chan utils.JSONMessage
listeners map[int64]chan utils.JSONMessage
Eng *engine.Engine
running bool
}

View file

@ -1,9 +1,10 @@
package server
import (
"github.com/dotcloud/docker/utils"
"testing"
"time"
"github.com/dotcloud/docker/utils"
)
func TestPools(t *testing.T) {
@ -47,14 +48,14 @@ func TestPools(t *testing.T) {
func TestLogEvent(t *testing.T) {
srv := &Server{
events: make([]utils.JSONMessage, 0, 64),
listeners: make(map[string]chan utils.JSONMessage),
listeners: make(map[int64]chan utils.JSONMessage),
}
srv.LogEvent("fakeaction", "fakeid", "fakeimage")
listener := make(chan utils.JSONMessage)
srv.Lock()
srv.listeners["test"] = listener
srv.listeners[1337] = listener
srv.Unlock()
srv.LogEvent("fakeaction2", "fakeid", "fakeimage")