Skip to content

Commit

Permalink
Introduced OperationInterrupted exception to replace NotAnError that …
Browse files Browse the repository at this point in the history
…was included in PR #93.  This makes things clearer.  Also, made the new exception part of Socket to avoid redundant declarations.
  • Loading branch information
Bill Abt committed Oct 26, 2017
1 parent 814b73b commit fb0c9c1
Showing 1 changed file with 21 additions and 12 deletions.
33 changes: 21 additions & 12 deletions Sources/Socket/Socket.swift
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,17 @@ public class Socket: SocketReader, SocketWriter {
public static let SOCKET_ERR_GETSOCKOPT_FAILED = -9967
public static let SOCKET_ERR_INVALID_DELEGATE_CALL = -9966
public static let SOCKET_ERR_MISSING_SIGNATURE = -9965



///
/// Specialized Operation Exception
///
enum OperationInterrupted: Swift.Error {

/// Low level socket accept was interrupted.
/// - **Note:** This is typically _NOT_ an error.
case accept
}

///
/// Flag to indicate the endian-ness of the host. (Readonly)
///
Expand Down Expand Up @@ -1371,9 +1380,6 @@ public class Socket: SocketReader, SocketWriter {

var keepRunning: Bool = true
repeat {
enum NotAnError: Swift.Error {
case nope
}
do {
guard let acceptAddress = try Address(addressProvider: { (addressPointer, addressLengthPointer) in
#if os(Linux)
Expand All @@ -1384,8 +1390,9 @@ public class Socket: SocketReader, SocketWriter {

if fd < 0 {

// The operation was interrupted, continue the loop...
if errno == EINTR {
throw NotAnError.nope
throw OperationInterrupted.accept
}

// Note: if you're running tests inside Xcode and the tests stop on this line
Expand All @@ -1398,7 +1405,9 @@ public class Socket: SocketReader, SocketWriter {
throw Error(code: Socket.SOCKET_ERR_WRONG_PROTOCOL, reason: "Unable to determine incoming socket protocol family.")
}
address = acceptAddress
} catch NotAnError.nope {

} catch OperationInterrupted.accept {

continue
}

Expand Down Expand Up @@ -1484,9 +1493,6 @@ public class Socket: SocketReader, SocketWriter {

var keepRunning: Bool = true
repeat {
enum NotAnError: Swift.Error {
case nope
}
do {
guard let acceptAddress = try Address(addressProvider: { (addressPointer, addressLengthPointer) in
#if os(Linux)
Expand All @@ -1497,8 +1503,9 @@ public class Socket: SocketReader, SocketWriter {

if fd < 0 {

// The operation was interrupted, continue the loop...
if errno == EINTR {
throw NotAnError.nope
throw OperationInterrupted.accept
}

// Note: if you're running tests inside Xcode and the tests stop on this line
Expand All @@ -1511,7 +1518,9 @@ public class Socket: SocketReader, SocketWriter {
throw Error(code: Socket.SOCKET_ERR_WRONG_PROTOCOL, reason: "Unable to determine incoming socket protocol family.")
}
address = acceptAddress
} catch NotAnError.nope {

} catch OperationInterrupted.accept {

continue
}

Expand Down

1 comment on commit fb0c9c1

@mcfedr
Copy link
Contributor

@mcfedr mcfedr commented on fb0c9c1 Oct 27, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks much better this way 👍

Please sign in to comment.