MCPcopy
hub / github.com/go-sql-driver/mysql / writePacket

Method writePacket

packets.go:126–175  ·  packets.go::mysqlConn.writePacket

Write packet buffer 'data'

(data []byte)

Source from the content-addressed store, hash-verified

124
125// Write packet buffer 'data'
126func (mc *mysqlConn) writePacket(data []byte) error {
127 pktLen := len(data) - 4
128 if pktLen > mc.maxAllowedPacket {
129 return ErrPktTooLarge
130 }
131
132 writeFunc := mc.writeWithTimeout
133 if mc.compress {
134 writeFunc = mc.compIO.writePackets
135 }
136
137 for {
138 size := min(maxPacketSize, pktLen)
139 putUint24(data[:3], size)
140 data[3] = mc.sequence
141
142 // Write packet
143 if debug {
144 fmt.Fprintf(os.Stderr, "writePacket: size=%v seq=%v\n", size, mc.sequence)
145 }
146
147 n, err := writeFunc(data[:4+size])
148 if err != nil {
149 mc.cleanup()
150 if cerr := mc.canceled.Value(); cerr != nil {
151 return cerr
152 }
153 if n == 0 && pktLen == len(data)-4 {
154 // only for the first loop iteration when nothing was written yet
155 mc.log(err)
156 return errBadConnNoWrite
157 } else {
158 return err
159 }
160 }
161 if n != 4+size {
162 // io.Writer(b) must return a non-nil error if it cannot write len(b) bytes.
163 // The io.ErrShortWrite error is used to indicate that this rule has not been followed.
164 mc.cleanup()
165 return io.ErrShortWrite
166 }
167
168 mc.sequence++
169 if size != maxPacketSize {
170 return nil
171 }
172 pktLen -= size
173 data = data[size:]
174 }
175}
176
177/******************************************************************************
178* Initialization Process *

Callers 10

writeAuthSwitchPacketMethod · 0.95
writeCommandPacketMethod · 0.95
writeCommandPacketStrMethod · 0.95
handleAuthResultMethod · 0.95
writeCommandLongDataMethod · 0.80
writeExecutePacketMethod · 0.80
compressHelperFunction · 0.80
handleInFileRequestMethod · 0.80

Calls 4

cleanupMethod · 0.95
logMethod · 0.95
putUint24Function · 0.85
ValueMethod · 0.45

Tested by 1

compressHelperFunction · 0.64