Skip to content

Commit a00071e

Browse files
committed
remove engine
2 parents 44a2df1 + 64b5253 commit a00071e

File tree

7 files changed

+34
-16
lines changed

7 files changed

+34
-16
lines changed

Package.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@ let package = Package(
1717
.package(url: "https://github.com/vapor/crypto.git", .revision("3.0.0-beta.1")),
1818

1919
// Networking
20-
.package(url: "https://github.com/vapor/sockets.git", .revision("3.0.0-beta.1")),
20+
.package(url: "https://github.com/vapor/sockets.git", .revision("3.0.0-beta.2")),
2121

2222
// SSL support
23-
.package(url: "https://github.com/vapor/tls.git", .revision("3.0.0-beta.1")),
23+
.package(url: "https://github.com/vapor/tls.git", .revision("3.0.0-beta.2")),
2424
],
2525
targets: [
2626
.target(name: "MySQL", dependencies: ["CodableKit", "Crypto", "TCP", "TLS"]),

Sources/MySQL/Connection/Connection.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public struct MySQLSSLConfig {
1616
}
1717
}
1818

19-
/// A connectio to a MySQL database servers
19+
/// A connection to a MySQL database servers
2020
public struct MySQLConnection {
2121
let stateMachine: MySQLStateMachine
2222

Sources/MySQL/Connection/PacketParser.swift

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -130,8 +130,8 @@ internal struct MySQLPacketParser: ByteParser {
130130
guard buffer.count >= 3 else { return nil }
131131

132132
let byte0: UInt32 = numericCast(buffer[0])
133-
let byte1: UInt32 = numericCast(buffer[1])
134-
let byte2: UInt32 = numericCast(buffer[2])
133+
let byte1: UInt32 = numericCast(buffer[1]) << 8
134+
let byte2: UInt32 = numericCast(buffer[2]) << 16
135135

136136
return numericCast(byte0 | byte1 | byte2) as Int
137137
}
@@ -157,16 +157,16 @@ internal struct MySQLPacketParser: ByteParser {
157157
// Take the cached previous packet edge-case bytes into consideration
158158
switch headerBytes.count {
159159
case 1:
160-
byte0 = (numericCast(headerBytes[0]) as UInt32).littleEndian
160+
byte0 = numericCast(headerBytes[0])
161161

162-
byte1 = (numericCast(pointer[0]) as UInt32).littleEndian << 8
163-
byte2 = (numericCast(pointer[1]) as UInt32).littleEndian << 16
162+
byte1 = numericCast(pointer[0]) << 8
163+
byte2 = numericCast(pointer[1]) << 16
164164
parsed = 2
165165
case 2:
166-
byte0 = (numericCast(headerBytes[0]) as UInt32).littleEndian
167-
byte1 = (numericCast(headerBytes[1]) as UInt32).littleEndian << 8
166+
byte0 = numericCast(headerBytes[0])
167+
byte1 = numericCast(headerBytes[1]) << 8
168168

169-
byte2 = (numericCast(pointer[0]) as UInt32).littleEndian << 16
169+
byte2 = numericCast(pointer[0]) << 16
170170
parsed = 1
171171
default:
172172
fatalError("Invalid MySQL parsing scenario reached")

Sources/MySQL/Internals/Handshake.swift

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,12 @@ extension Packet {
4646

4747
// Require decimal `10` to be the protocol version
4848
guard try parser.byte() == 10 else {
49-
throw MySQLError(.invalidHandshake)
49+
// if the first byte is 0xff then we got an error packet
50+
if parser.payload[0] == 0xff {
51+
throw MySQLError(packet: self)
52+
} else {
53+
throw MySQLError(.invalidHandshake)
54+
}
5055
}
5156

5257
// UTF-8

Sources/MySQL/Internals/MySQLStream.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ final class MySQLStateMachine {
1414
var affectedRows: UInt64?
1515

1616
var handshake: Handshake?
17+
/// We currently don't use sequenceId
1718
var sequenceId: UInt8
1819
private let ssl: MySQLSSLConfig?
1920
let connected: Promise<Void>

Sources/MySQL/Internals/Packet.swift

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ internal final class Packet: ExpressibleByArrayLiteral {
1515

1616
/// The sequence ID is incremented per message
1717
/// This client doesn't use this
18+
/// The max packet size is 2^24-1 bytes, so the packet fragmenting is hardly used.
19+
/// There are cases like bigdata bulk loading, big blob fetch etc when the SERVER will use it,
20+
/// therefore later we need to address this
21+
1822
var sequenceId: UInt8 {
1923
get {
2024
return containsPacketSize ? buffer[3] : buffer[0]
@@ -86,8 +90,11 @@ internal final class Packet: ExpressibleByArrayLiteral {
8690
UInt8((elements.count >> 8) & 0xff),
8791
UInt8((elements.count >> 16) & 0xff),
8892
]
89-
93+
var sequenceId = UInt8(0)
94+
9095
memcpy(pointer, packetSizeBytes, 3)
96+
97+
memcpy(pointer.advanced(by: 3), &sequenceId, 1)
9198

9299
memcpy(pointer.advanced(by: 4), elements, elements.count)
93100

@@ -102,10 +109,12 @@ internal final class Packet: ExpressibleByArrayLiteral {
102109
UInt8((data.count >> 8) & 0xff),
103110
UInt8((data.count >> 16) & 0xff),
104111
]
105-
112+
var sequenceId = UInt8(0)
106113
memcpy(pointer, packetSizeBytes, 3)
107114

108-
_ = memcpy(pointer.advanced(by: 4), data, data.count)
115+
memcpy(pointer.advanced(by: 3), &sequenceId, 1)
116+
117+
memcpy(pointer.advanced(by: 4), data, data.count)
109118

110119
self.init(payload: MutableByteBuffer(start: pointer, count: 4 &+ data.count), containsPacketSize: true)
111120
}
@@ -118,9 +127,12 @@ internal final class Packet: ExpressibleByArrayLiteral {
118127
UInt8((data.count >> 8) & 0xff),
119128
UInt8((data.count >> 16) & 0xff),
120129
]
130+
var sequenceId = UInt8(0)
121131

122132
memcpy(pointer, packetSizeBytes, 3)
123133

134+
memcpy(pointer.advanced(by: 3), &sequenceId, 1)
135+
124136
data.withByteBuffer { buffer in
125137
_ = memcpy(pointer.advanced(by: 4), buffer.baseAddress!, data.count)
126138
}

circle.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ version: 2
33
jobs:
44
macos:
55
macos:
6-
xcode: "9.0"
6+
xcode: "9.2"
77
steps:
88
- run: brew install mysql
99
- run: brew services start mysql

0 commit comments

Comments
 (0)