(netConn net.Conn, readBufSize, writeBufSize int)
| 142 | } |
| 143 | |
| 144 | func 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 | |
| 180 | func (cn *Conn) UsedAt() time.Time { |
| 181 | return time.Unix(0, cn.usedAt.Load()) |
no test coverage detected