From a10d58c8caf60d1b43f66a1c78267a8afd6f325d Mon Sep 17 00:00:00 2001 From: Lucas Clemente Date: Sun, 15 May 2016 18:49:09 +0200 Subject: [PATCH] privatize session.run ref #60 --- congestion/cubic_sender_test.go | 2 +- server.go | 4 ++-- server_test.go | 2 +- session.go | 4 ++-- session_test.go | 16 ++++++++-------- 5 files changed, 14 insertions(+), 14 deletions(-) diff --git a/congestion/cubic_sender_test.go b/congestion/cubic_sender_test.go index c8e7a3d0..480ebf4b 100644 --- a/congestion/cubic_sender_test.go +++ b/congestion/cubic_sender_test.go @@ -414,7 +414,7 @@ var _ = Describe("Cubic Sender", func() { Expect(sender.RetransmissionDelay()).To(Equal(expected_delay)) for i := 0; i < 100; i++ { - // Run to make sure that we converge. + // run to make sure that we converge. rttStats.UpdateRTT(kRttMs+kDeviationMs, 0, clock.Now()) rttStats.UpdateRTT(kRttMs-kDeviationMs, 0, clock.Now()) } diff --git a/server.go b/server.go index 22e00f86..c91ed2b8 100644 --- a/server.go +++ b/server.go @@ -15,7 +15,7 @@ import ( // packetHandler handles packets type packetHandler interface { handlePacket(addr interface{}, hdr *publicHeader, data []byte) - Run() + run() } // A Server of QUIC @@ -128,7 +128,7 @@ func (s *Server) handlePacket(conn *net.UDPConn, remoteAddr *net.UDPAddr, packet s.streamCallback, s.closeCallback, ) - go session.Run() + go session.run() s.sessionsMutex.Lock() s.sessions[hdr.ConnectionID] = session s.sessionsMutex.Unlock() diff --git a/server_test.go b/server_test.go index cef459b7..fbade42d 100644 --- a/server_test.go +++ b/server_test.go @@ -22,7 +22,7 @@ func (s *mockSession) handlePacket(addr interface{}, hdr *publicHeader, data []b s.packetCount++ } -func (s *mockSession) Run() { +func (s *mockSession) run() { } func newMockSession(conn connection, v protocol.VersionNumber, connectionID protocol.ConnectionID, sCfg *handshake.ServerConfig, streamCallback StreamCallback, closeCallback closeCallback) packetHandler { diff --git a/session.go b/session.go index a9897662..497abf9f 100644 --- a/session.go +++ b/session.go @@ -126,8 +126,8 @@ func newSession(conn connection, v protocol.VersionNumber, connectionID protocol return session } -// Run the session main loop -func (s *Session) Run() { +// run the session main loop +func (s *Session) run() { for { // Close immediately if requested select { diff --git a/session_test.go b/session_test.go index 11f3c507..34d8fdeb 100644 --- a/session_test.go +++ b/session_test.go @@ -315,7 +315,7 @@ var _ = Describe("Session", func() { scfg := handshake.NewServerConfig(crypto.NewCurve25519KEX(), signer) nGoRoutinesBefore = runtime.NumGoroutine() session = newSession(conn, 0, 0, scfg, nil, func(protocol.ConnectionID) { closed = true }).(*Session) - go session.Run() + go session.run() Eventually(func() int { return runtime.NumGoroutine() }).Should(Equal(nGoRoutinesBefore + 2)) }) @@ -437,13 +437,13 @@ var _ = Describe("Session", func() { 0x18, 0x6f, 0x44, 0xba, 0x97, 0x35, 0xd, 0x6f, 0xbf, 0x64, 0x3c, 0x79, 0x66, 0x6f, 0x6f, 0x62, 0x61, 0x72, }, } - session.Run() + session.run() Expect(session.sendingScheduled).To(Receive()) }) Context("bundling of small packets", func() { It("bundles two small frames into one packet", func() { - go session.Run() + go session.run() session.queueStreamFrame(&frames.StreamFrame{ StreamID: 5, @@ -458,7 +458,7 @@ var _ = Describe("Session", func() { }) It("sends out two big frames in two packet", func() { - go session.Run() + go session.run() session.queueStreamFrame(&frames.StreamFrame{ StreamID: 5, @@ -473,7 +473,7 @@ var _ = Describe("Session", func() { }) It("sends out two small frames that are written to long after one another into two packet", func() { - go session.Run() + go session.run() session.queueStreamFrame(&frames.StreamFrame{ StreamID: 5, @@ -489,7 +489,7 @@ var _ = Describe("Session", func() { }) It("sends a queued ACK frame only once", func() { - go session.Run() + go session.run() packetNumber := protocol.PacketNumber(0x1337) session.receivedPacketHandler.ReceivedPacket(packetNumber, true) @@ -540,7 +540,7 @@ var _ = Describe("Session", func() { } session.handlePacket(nil, hdr, []byte("foobar")) } - session.Run() + session.run() Expect(conn.written).To(HaveLen(1)) Expect(conn.written[0]).To(ContainSubstring(string([]byte("PRST")))) @@ -568,7 +568,7 @@ var _ = Describe("Session", func() { }) session.packer.connectionParametersManager = session.connectionParametersManager session.packer.sentPacketHandler = newMockSentPacketHandler() - session.Run() // Would normally not return + session.run() // Would normally not return Expect(conn.written[0]).To(ContainSubstring("No recent network activity.")) close(done) }, 0.5)