MCPcopy
hub / github.com/monasticacademy/httptap / Write

Method Write

udp.go:126–152  ·  view source on GitHub ↗
(payload []byte)

Source from the content-addressed store, hash-verified

124}
125
126func (r *udpStackResponder) Write(payload []byte) (int, error) {
127 // set checksums and lengths
128 r.udpheader.SetNetworkLayerForChecksum(r.ipv4header)
129
130 // log
131 verbosef("sending udp packet to subprocess: %s", summarizeUDP(r.ipv4header, r.udpheader, payload))
132
133 // serialize the data
134 packet, err := serializeUDP(r.ipv4header, r.udpheader, payload, r.stack.buf)
135 if err != nil {
136 return 0, fmt.Errorf("error serializing UDP packet: %w", err)
137 }
138
139 // make a copy because the same buffer will be re-used
140 cp := make([]byte, len(packet))
141 copy(cp, packet)
142
143 // send to the subprocess channel non-blocking
144 select {
145 case r.stack.toSubprocess <- cp:
146 default:
147 return 0, fmt.Errorf("channel for sending udp to subprocess would have blocked")
148 }
149
150 // return number of bytes passed in, not number of bytes sent to output
151 return len(payload), nil
152}

Callers

nothing calls this directly

Calls 3

summarizeUDPFunction · 0.85
serializeUDPFunction · 0.85
verbosefFunction · 0.70

Tested by

no test coverage detected