Skip to content

Commit

Permalink
Helper to stop and join a series of agent
Browse files Browse the repository at this point in the history
  • Loading branch information
mpiraux committed Feb 7, 2019
1 parent 71e9127 commit f826d80
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 8 deletions.
7 changes: 7 additions & 0 deletions agents/base_agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,13 @@ func (c *ConnectionAgents) Get(name string) Agent {
return c.agents[name]
}

func (c *ConnectionAgents) Stop(names... string) {
for _, n := range names {
c.Get(n).Stop()
c.Get(n).Join()
}
}

func (c *ConnectionAgents) StopAll() {
for _, a := range c.agents {
a.Stop()
Expand Down
3 changes: 1 addition & 2 deletions scenarii/ack_only.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ func (s *AckOnlyScenario) Run(conn *qt.Connection, trace *qt.Trace, preferredUrl
return
}
defer connAgents.CloseConnection(false, 0, "")
connAgents.Get("AckAgent").Stop()
connAgents.Get("AckAgent").Join()
connAgents.Stop("AckAgent")

incPackets := conn.IncomingPackets.RegisterNewChan(1000)

Expand Down
5 changes: 1 addition & 4 deletions scenarii/connection_migration.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,7 @@ func (s *ConnectionMigrationScenario) Run(conn *qt.Connection, trace *qt.Trace,

<-time.NewTimer(3 * time.Second).C // Wait some time before migrating

connAgents.Get("SocketAgent").Stop()
connAgents.Get("SendingAgent").Stop()
connAgents.Get("SocketAgent").Join()
connAgents.Get("SendingAgent").Join()
connAgents.Stop("SocketAgent", "SendingAgent")

newUdpConn, err := qt.EstablishUDPConnection(conn.Host)
if err != nil {
Expand Down
3 changes: 1 addition & 2 deletions scenarii/zero_rtt.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,7 @@ func (s *ZeroRTTScenario) Run(conn *qt.Connection, trace *qt.Trace, preferredUrl
}

connAgents = agents.AttachAgentsToConnection(conn, agents.GetDefaultAgents()...)
connAgents.Get("RecoveryAgent").Stop()
connAgents.Get("RecoveryAgent").Join()
connAgents.Stop("RecoveryAgent")
handshakeAgent := &agents.HandshakeAgent{TLSAgent: connAgents.Get("TLSAgent").(*agents.TLSAgent), SocketAgent: connAgents.Get("SocketAgent").(*agents.SocketAgent)}
connAgents.Add(handshakeAgent)
defer connAgents.CloseConnection(false, 0, "")
Expand Down

0 comments on commit f826d80

Please sign in to comment.