Skip to content

Commit 768dfe8

Browse files
Fixed linux build.
1 parent e279c4e commit 768dfe8

File tree

2 files changed

+14
-14
lines changed

2 files changed

+14
-14
lines changed

Sources/Linux.swift

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public class LinuxIO: IO {
1919

2020
public required init(_ port: in_port_t, forceIPv4: Bool, bindAddress: String? = nil) throws {
2121

22-
self.server = try LinuxAsyncServer.nonBlockingSocketForListenening(port, forceIPv4: forceIPv4, address: bindAddress)
22+
self.server = try LinuxIO.nonBlockingSocketForListenening(port, forceIPv4: forceIPv4, address: bindAddress)
2323

2424
self.descriptors.append(pollfd(fd: self.server, events: Int16(POLLIN), revents: 0))
2525
}
@@ -32,7 +32,7 @@ public class LinuxIO: IO {
3232
let result = Glibc.write(socket, data, data.count)
3333
if result == -1 {
3434
defer { self.finish(socket) }
35-
throw AsyncError.writeFailed(Process.error)
35+
throw SwifterError.writeFailed(Process.error)
3636
}
3737
if result == data.count {
3838
if done() == .terminate {
@@ -52,20 +52,20 @@ public class LinuxIO: IO {
5252

5353
public func wait(_ callback: ((IOEvent) -> Void)) throws {
5454
guard poll(&descriptors, UInt(descriptors.count), -1) != -1 else {
55-
throw AsyncError.async(Process.error)
55+
throw SwifterError.async(Process.error)
5656
}
5757
for i in 0..<descriptors.count {
5858
if descriptors[i].revents == 0 {
5959
continue
6060
}
6161
if descriptors[i].fd == server {
6262
while case let client = accept(server, nil, nil), client > 0 {
63-
try LinuxAsyncServer.setSocketNonBlocking(client)
63+
try LinuxIO.setSocketNonBlocking(client)
6464
self.backlog[Int32(client)] = []
6565
descriptors.append(pollfd(fd: client, events: Int16(POLLIN), revents: 0))
6666
callback(IOEvent.connect("", Int32(client)))
6767
}
68-
if errno != EWOULDBLOCK { throw AsyncError.acceptFailed(Process.error) }
68+
if errno != EWOULDBLOCK { throw SwifterError.acceptFailed(Process.error) }
6969
} else {
7070
if (descriptors[i].revents & Int16(POLLERR) != 0) || (descriptors[i].revents & Int16(POLLHUP) != 0) || (descriptors[i].revents & Int16(POLLNVAL) != 0) {
7171
self.finish(descriptors[i].fd)
@@ -147,13 +147,13 @@ public class LinuxIO: IO {
147147
let server = Glibc.socket(forceIPv4 ? AF_INET : AF_INET6, Int32(SOCK_STREAM.rawValue), 0)
148148

149149
guard server != -1 else {
150-
throw AsyncError.socketCreation(Process.error)
150+
throw SwifterError.socketCreation(Process.error)
151151
}
152152

153153
var value: Int32 = 1
154154
if Glibc.setsockopt(server, SOL_SOCKET, SO_REUSEADDR, &value, socklen_t(MemoryLayout<Int32>.size)) == -1 {
155155
defer { let _ = Glibc.close(server) }
156-
throw AsyncError.setReuseAddrFailed(Process.error)
156+
throw SwifterError.setReuseAddrFailed(Process.error)
157157
}
158158

159159
do {
@@ -170,7 +170,7 @@ public class LinuxIO: IO {
170170

171171
if Glibc.listen(server, SOMAXCONN) == -1 {
172172
defer { let _ = Glibc.close(server) }
173-
throw AsyncError.listenFailed(Process.error)
173+
throw SwifterError.listenFailed(Process.error)
174174
}
175175

176176
return server
@@ -185,7 +185,7 @@ public class LinuxIO: IO {
185185

186186
if let addressFound = address {
187187
guard addressFound.withCString({ inet_pton(AF_INET, $0, &addr.sin_addr) }) == 1 else {
188-
throw AsyncError.inetPtonFailed(Errno.description())
188+
throw SwifterError.inetPtonFailed(Errno.description())
189189
}
190190
} else {
191191
addr.sin_addr = in_addr(s_addr: in_addr_t(0))
@@ -198,7 +198,7 @@ public class LinuxIO: IO {
198198
}
199199

200200
guard bindResult != -1 else {
201-
throw AsyncError.bindFailed(Errno.description())
201+
throw SwifterError.bindFailed(Errno.description())
202202
}
203203
}
204204

@@ -211,7 +211,7 @@ public class LinuxIO: IO {
211211

212212
if let addressFound = address {
213213
guard addressFound.withCString({ inet_pton(AF_INET6, $0, &addr.sin6_addr) }) == 1 else {
214-
throw AsyncError.inetPtonFailed(Errno.description())
214+
throw SwifterError.inetPtonFailed(Errno.description())
215215
}
216216
} else {
217217
addr.sin6_addr = in6addr_any
@@ -224,13 +224,13 @@ public class LinuxIO: IO {
224224
}
225225

226226
guard bindResult != -1 else {
227-
throw AsyncError.bindFailed(Errno.description())
227+
throw SwifterError.bindFailed(Errno.description())
228228
}
229229
}
230230

231231
public static func setSocketNonBlocking(_ socket: Int32) throws {
232232
if Glibc.fcntl(socket, F_SETFL, fcntl(socket, F_GETFL, 0) | O_NONBLOCK) == -1 {
233-
throw AsyncError.setNonBlockFailed(Process.error)
233+
throw SwifterError.setNonBlockFailed(Process.error)
234234
}
235235
}
236236
}

Sources/Server.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public class Server {
1515

1616
public init(_ port: in_port_t = 8080, forceIPv4: Bool = false) throws {
1717
#if os(Linux)
18-
self.io = try LinuxAsyncServer(port, forceIPv4: forceIPv4)
18+
self.io = try LinuxIO(port, forceIPv4: forceIPv4)
1919
#else
2020
self.io = try MacOSIO(port, forceIPv4: forceIPv4)
2121
#endif

0 commit comments

Comments
 (0)