MCPcopy
hub / github.com/grpc/grpc-go / SendMsg

Method SendMsg

stream.go:1446–1495  ·  view source on GitHub ↗
(m any)

Source from the content-addressed store, hash-verified

1444}
1445
1446func (as *addrConnStream) SendMsg(m any) (err error) {
1447 defer func() {
1448 if err != nil && err != io.EOF {
1449 // Call finish on the client stream for errors generated by this SendMsg
1450 // call, as these indicate problems created by this client. (Transport
1451 // errors are converted to an io.EOF error in csAttempt.sendMsg; the real
1452 // error will be returned from RecvMsg eventually in that case, or be
1453 // retried.)
1454 as.finish(err)
1455 }
1456 }()
1457 if as.sentLast {
1458 return status.Errorf(codes.Internal, "SendMsg called after CloseSend")
1459 }
1460 if !as.desc.ClientStreams {
1461 as.sentLast = true
1462 }
1463
1464 // load hdr, payload, data
1465 hdr, data, payload, pf, err := prepareMsg(m, as.codec, as.sendCompressorV0, as.sendCompressorV1, as.ac.dopts.copts.BufferPool)
1466 if err != nil {
1467 return err
1468 }
1469
1470 defer func() {
1471 data.Free()
1472 // only free payload if compression was made, and therefore it is a different set
1473 // of buffers from data.
1474 if pf.isCompressed() {
1475 payload.Free()
1476 }
1477 }()
1478
1479 // TODO(dfawley): should we be checking len(data) instead?
1480 if payload.Len() > *as.callInfo.maxSendMessageSize {
1481 return status.Errorf(codes.ResourceExhausted, "trying to send message larger than max (%d vs. %d)", payload.Len(), *as.callInfo.maxSendMessageSize)
1482 }
1483
1484 if err := as.transportStream.Write(hdr, payload, &transport.WriteOptions{Last: !as.desc.ClientStreams}); err != nil {
1485 if !as.desc.ClientStreams {
1486 // For non-client-streaming RPCs, we return nil instead of EOF on error
1487 // because the generated code requires it. finish is not called; RecvMsg()
1488 // will call it with the stream's status independently.
1489 return nil
1490 }
1491 return io.EOF
1492 }
1493
1494 return nil
1495}
1496
1497func (as *addrConnStream) RecvMsg(m any) (err error) {
1498 defer func() {

Callers

nothing calls this directly

Calls 7

finishMethod · 0.95
ErrorfFunction · 0.92
prepareMsgFunction · 0.85
isCompressedMethod · 0.80
FreeMethod · 0.65
LenMethod · 0.65
WriteMethod · 0.65

Tested by

no test coverage detected