MCPcopy
hub / github.com/redis/go-redis / NewConnWithBufferSize

Function NewConnWithBufferSize

internal/pool/conn.go:144–178  ·  view source on GitHub ↗
(netConn net.Conn, readBufSize, writeBufSize int)

Source from the content-addressed store, hash-verified

142}
143
144func NewConnWithBufferSize(netConn net.Conn, readBufSize, writeBufSize int) *Conn {
145 now := time.Now()
146 cn := &Conn{
147 createdAt: now,
148 id: generateConnID(), // Generate unique ID for this connection
149 stateMachine: NewConnStateMachine(),
150 }
151
152 // Use specified buffer sizes, or fall back to 32KiB defaults if 0
153 if readBufSize > 0 {
154 cn.rd = proto.NewReaderSize(netConn, readBufSize)
155 } else {
156 cn.rd = proto.NewReader(netConn) // Uses 32KiB default
157 }
158
159 if writeBufSize > 0 {
160 cn.bw = bufio.NewWriterSize(netConn, writeBufSize)
161 } else {
162 cn.bw = bufio.NewWriterSize(netConn, proto.DefaultBufferSize)
163 }
164
165 // Store netConn atomically for lock-free access using wrapper
166 cn.netConnAtomic.Store(&atomicNetConn{conn: netConn})
167
168 cn.wr = proto.NewWriter(cn.bw)
169 cn.SetUsedAt(now)
170 // Initialize handoff state atomically
171 initialHandoffState := &HandoffState{
172 ShouldHandoff: false,
173 Endpoint: "",
174 SeqID: 0,
175 }
176 cn.handoffStateAtomic.Store(initialHandoffState)
177 return cn
178}
179
180func (cn *Conn) UsedAt() time.Time {
181 return time.Unix(0, cn.usedAt.Load())

Callers 3

NewConnMethod · 0.85
NewConnFunction · 0.85
dialConnMethod · 0.85

Calls 6

SetUsedAtMethod · 0.95
NewReaderSizeFunction · 0.92
NewReaderFunction · 0.92
NewWriterFunction · 0.92
generateConnIDFunction · 0.85
NewConnStateMachineFunction · 0.85

Tested by

no test coverage detected