MCPcopy
hub / github.com/keploy/keploy / ReadFirstBuffer

Function ReadFirstBuffer

pkg/agent/proxy/integrations/mysql/utils/util.go:20–39  ·  view source on GitHub ↗

ReadFirstBuffer reads the first buffer from either clientConn or destConn

(ctx context.Context, logger *zap.Logger, clientConn, destConn net.Conn)

Source from the content-addressed store, hash-verified

18
19// ReadFirstBuffer reads the first buffer from either clientConn or destConn
20func ReadFirstBuffer(ctx context.Context, logger *zap.Logger, clientConn, destConn net.Conn) ([]byte, string, error) {
21 // Attempt to read from destConn first
22 buf, err := util.ReadBytes(ctx, logger, destConn)
23 // If there is data from destConn, return it
24 if err == nil {
25 return buf, "destination", nil
26 }
27 // If the error is a timeout, try to read from clientConn
28 if netErr, ok := err.(net.Error); ok && netErr.Timeout() {
29 buf, err = util.ReadBytes(ctx, logger, clientConn)
30 // If there is data from clientConn, return it
31 if err == nil {
32 return buf, "client", nil
33 }
34 // Return any error from reading clientConn
35 return nil, "", err
36 }
37 // Return any other error from reading destConn
38 return nil, "", err
39}
40
41// ReadPacketStream reads packets from the connection and sends them to the bufferChannel
42func ReadPacketStream(ctx context.Context, logger *zap.Logger, conn net.Conn, bufferChannel chan []byte, errChannel chan error) {

Callers

nothing calls this directly

Calls 2

ReadBytesFunction · 0.92
TimeoutMethod · 0.65

Tested by

no test coverage detected