| 888 | } |
| 889 | |
| 890 | func (cn *Conn) WithReader( |
| 891 | ctx context.Context, timeout time.Duration, fn func(rd *proto.Reader) error, |
| 892 | ) error { |
| 893 | if timeout >= 0 { |
| 894 | // Use relaxed timeout if set, otherwise use provided timeout |
| 895 | effectiveTimeout := cn.getEffectiveReadTimeout(timeout) |
| 896 | |
| 897 | // Get the connection directly from atomic storage |
| 898 | netConn := cn.getNetConn() |
| 899 | if netConn == nil { |
| 900 | return errConnectionNotAvailable |
| 901 | } |
| 902 | |
| 903 | if err := netConn.SetReadDeadline(cn.deadline(ctx, effectiveTimeout)); err != nil { |
| 904 | return err |
| 905 | } |
| 906 | } |
| 907 | return fn(cn.rd) |
| 908 | } |
| 909 | |
| 910 | func (cn *Conn) WithWriter( |
| 911 | ctx context.Context, timeout time.Duration, fn func(wr *proto.Writer) error, |