You are an expert in writing code in many different languages. Your goal is to perform code completion for the following code, keeping in mind the rest of the code and the file meta data.
    Metadata details:
    filename: recv.go
    path of file: ./repos/gapid/core/java/jdwp
    
    the code of the file until where you have to start completion: // Copyright (C) 2017 Google Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//      http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License
    
func (c *Connection) recv(ctx context.Context) {
	for !task.Stopped(ctx) {
		packet, err := c.readPacket()
		switch err {
		case nil:
		case io.EOF:
			return
		default:
			if !task.Stopped(ctx) {
				log.W(ctx, "Failed to read packet. Error: %v", err)
			}
			return
		}

		switch packet := packet.(type) {
		case replyPacket:
			c.Lock()
			out, ok := c.replies[packet.id]
			delete(c.replies, packet.id)
			c.Unlock()
			if !ok {
				log.W(ctx, "Unexpected reply for packet %d", packet.id)
				continue
			}
			out <- packet

		case cmdPacket:
			switch {
			case packet.cmdSet == cmdSetEvent && packet.cmdID == cmdCompositeEvent:
				d := endian.Reader(bytes.NewReader(packet.data), device.BigEndian)
				l := events{}
				if err := c.decode(d, reflect.ValueOf(&l)); err != nil {
					log.F(ctx, true, "Couldn't decode composite event data. Error: %v", err)
					continue
				}

				for _, ev := range l.Events {
					dbg("<%v> event: %T %+v", ev.request(), ev, ev)

					c.Lock()
					handler, ok := c.events[ev.request()]
					c.Unlock()

					if ok {
						handler <- ev
					} else {
						dbg("No event handler registered for %+v", ev)
					}
				}

			default:
				dbg("received unknown packet %+v", packet)
				// Unknown packet. Ignore.
			}
		}
	}
}