mirror of
https://github.com/apple/swift-nio
synced 2026-11-26 04:57:49 +00:00
Fixup thread unsafety
This commit is contained in:
1 parent
3768e2a2b9
commit
453b87ff5e
2 files changed
+8
-5
No files matched your search
@@ -576,7 +576,7 @@ class BaseSocketChannel<T : BaseSocket> : SelectableChannel, ChannelCore {
|
||||
|
||||
if closed {
|
||||
interestedEvent = .none
|
||||
throw ChannelError.alreadyClosed
|
||||
throw ChannelError.ioOnClosedChannel
|
||||
}
|
||||
interestedEvent = interested
|
||||
do {
|
||||
|
||||
@@ -154,19 +154,20 @@ public class EventLoopTest : XCTestCase {
|
||||
XCTFail("Unexpected error on close: \(error)")
|
||||
}
|
||||
}
|
||||
let loop = group.next() as! SelectableEventLoop
|
||||
|
||||
// We're going to create and register a channel, but not actually attempt to do anything with it.
|
||||
let wedgeHandler = WedgeOpenHandler()
|
||||
let channel = try SocketChannel(eventLoop: group.next() as! SelectableEventLoop, protocolFamily: AF_INET)
|
||||
let channel = try SocketChannel(eventLoop: loop, protocolFamily: AF_INET)
|
||||
try channel.pipeline.add(handler: wedgeHandler).then {
|
||||
channel.register()
|
||||
}.wait()
|
||||
|
||||
// Now we're going to start closing the event loop. This should not immediately succeed.
|
||||
let loopCloseFut = (group.next() as! SelectableEventLoop).closeGently()
|
||||
let loopCloseFut = loop.closeGently()
|
||||
|
||||
// Now we're going to attempt to register a new channel. This should immediately fail.
|
||||
let newChannel = try SocketChannel(eventLoop: group.next() as! SelectableEventLoop, protocolFamily: AF_INET)
|
||||
let newChannel = try SocketChannel(eventLoop: loop, protocolFamily: AF_INET)
|
||||
|
||||
do {
|
||||
try newChannel.register().wait()
|
||||
@@ -181,7 +182,9 @@ public class EventLoopTest : XCTestCase {
|
||||
XCTAssertFalse(loopCloseFut.fulfilled)
|
||||
|
||||
// Now let it close.
|
||||
wedgeHandler.closePromise!.succeed(result: ())
|
||||
loop.execute {
|
||||
wedgeHandler.closePromise!.succeed(result: ())
|
||||
}
|
||||
XCTAssertNoThrow(try loopCloseFut.wait())
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user