refactoring and conform 0mq#4.1

This commit is contained in:
badim 2016-04-11 22:39:59 +03:00
parent 9645fcea79
commit d4ace86514
3 changed files with 183 additions and 354 deletions

View File

@ -37,8 +37,8 @@ public enum SocketType {
case Pull case Pull
case Pair case Pair
case Stream case Stream
case Server // case Server
case Client // case Client
} }
extension SocketType { extension SocketType {
@ -56,8 +56,8 @@ extension SocketType {
case ZMQ_PULL: self = Pull case ZMQ_PULL: self = Pull
case ZMQ_PAIR: self = Pair case ZMQ_PAIR: self = Pair
case ZMQ_STREAM: self = Stream case ZMQ_STREAM: self = Stream
case ZMQ_SERVER: self = Server // case ZMQ_SERVER: self = Server
case ZMQ_CLIENT: self = Client // case ZMQ_CLIENT: self = Client
default: return nil default: return nil
} }
@ -79,8 +79,8 @@ extension SocketType {
case .Pull: return ZMQ_PULL case .Pull: return ZMQ_PULL
case .Pair: return ZMQ_PAIR case .Pair: return ZMQ_PAIR
case .Stream: return ZMQ_STREAM case .Stream: return ZMQ_STREAM
case .Server: return ZMQ_SERVER // case .Server: return ZMQ_SERVER
case .Client: return ZMQ_CLIENT // case .Client: return ZMQ_CLIENT
} }
} }
} }
@ -136,14 +136,14 @@ public final class Context {
} }
extension Context { extension Context {
public var blocky: Bool { // public var blocky: Bool {
set { // set {
setOption(ZMQ_BLOCKY, value: newValue ? 1 : 0) // setOption(ZMQ_BLOCKY, value: newValue ? 1 : 0)
} // }
get { // get {
return getOption(ZMQ_BLOCKY) != 0 // return getOption(ZMQ_BLOCKY) != 0
} // }
} // }
public var IOThreads: Int32 { public var IOThreads: Int32 {
set { set {

View File

@ -34,7 +34,7 @@ public struct PollEvent : OptionSet {
public static let In = PollEvent(rawValue: Int16(ZMQ_POLLIN)) public static let In = PollEvent(rawValue: Int16(ZMQ_POLLIN))
public static let Out = PollEvent(rawValue: Int16(ZMQ_POLLOUT)) public static let Out = PollEvent(rawValue: Int16(ZMQ_POLLOUT))
public static let Error = PollEvent(rawValue: Int16(ZMQ_POLLERR)) public static let Error = PollEvent(rawValue: Int16(ZMQ_POLLERR))
public static let Priority = PollEvent(rawValue: Int16(ZMQ_POLLPRI)) // public static let Priority = PollEvent(rawValue: Int16(ZMQ_POLLPRI))
} }
public enum PollItemEvent { public enum PollItemEvent {

View File

@ -190,6 +190,34 @@ public struct SocketEvent : OptionSet {
public static let MonitorStopped = SocketEvent(rawValue: ZMQ_EVENT_MONITOR_STOPPED) public static let MonitorStopped = SocketEvent(rawValue: ZMQ_EVENT_MONITOR_STOPPED)
} }
extension Socket {
func setOption(option: Int32, _ value: Bool) throws {
var value = value ? 1 : 0
try setOption(option, value: &value, length: strideof(Int32))
}
func setOption(option: Int32, _ value: Int32) throws {
var value = value
try setOption(option, value: &value, length: strideof(Int32))
}
func setOption(option: Int32, _ value: String) throws {
try value.withCString { v in
try setOption(option, value: v, length: value.utf8.count)
}
}
func setOption(option: Int32, _ value: Data) throws {
try setOption(option, value: value.bytes, length: value.count)
}
func setOption(option: Int32, _ value: String?) throws {
if let value = value {
try value.withCString { v in
try setOption(option, value: v, length: value.utf8.count)
}
} else {
try setOption(option, value: nil, length: 0)
}
}
}
extension Socket { extension Socket {
public func setAffinity(value: UInt64) throws { public func setAffinity(value: UInt64) throws {
var value = value var value = value
@ -197,127 +225,87 @@ extension Socket {
} }
public func setBacklog(value: Int32) throws { public func setBacklog(value: Int32) throws {
var value = value try setOption(ZMQ_BACKLOG, value)
try setOption(ZMQ_BACKLOG, value: &value, length: strideof(Int32))
} }
public func setConnectRID(value: String) throws { public func setConnectRID(value: String) throws {
try value.withCString { v in try setOption(ZMQ_CONNECT_RID, value)
try setOption(ZMQ_CONNECT_RID, value: v, length: value.utf8.count)
}
} }
public func setConflate(value: Bool) throws { public func setConflate(value: Bool) throws {
var v = value ? 1 : 0 try setOption(ZMQ_CONFLATE, value)
try setOption(ZMQ_CONFLATE, value: &v, length: strideof(Int32))
} }
public func setConnectTimeout(value: Int32) throws { // public func setConnectTimeout(value: Int32) throws {
var value = value // try setOption(ZMQ_CONNECT_TIMEOUT, value)
try setOption(ZMQ_CONNECT_TIMEOUT, value: &value, length: strideof(Int32)) // }
}
public func setCURVEPublicKey(value: String?) throws { public func setCURVEPublicKey(value: String?) throws {
if let value = value { try setOption(ZMQ_CURVE_PUBLICKEY, value)
try value.withCString { v in
try setOption(ZMQ_CURVE_PUBLICKEY, value: v, length: value.utf8.count)
}
} else {
try setOption(ZMQ_CURVE_PUBLICKEY, value: nil, length: 0)
}
} }
public func setCURVESecretKey(value: String?) throws { public func setCURVESecretKey(value: String?) throws {
if let value = value { try setOption(ZMQ_CURVE_SECRETKEY, value)
try value.withCString { v in
try setOption(ZMQ_CURVE_SECRETKEY, value: v, length: value.utf8.count)
}
} else {
try setOption(ZMQ_CURVE_SECRETKEY, value: nil, length: 0)
}
} }
public func setCURVEServer(value: Bool) throws { public func setCURVEServer(value: Bool) throws {
var v = value ? 1 : 0 try setOption(ZMQ_CURVE_SERVER, value)
try setOption(ZMQ_CURVE_SERVER, value: &v, length: strideof(Int32))
} }
public func setCURVEServerKey(value: String?) throws { public func setCURVEServerKey(value: String?) throws {
if let value = value { try setOption(ZMQ_CURVE_SERVERKEY, value)
try value.withCString { v in
try setOption(ZMQ_CURVE_SERVERKEY, value: v, length: value.utf8.count)
}
} else {
try setOption(ZMQ_CURVE_SERVERKEY, value: nil, length: 0)
}
} }
public func setGSSAPIPlainText(value: Bool) throws { public func setGSSAPIPlainText(value: Bool) throws {
var v = value ? 1 : 0 try setOption(ZMQ_GSSAPI_PLAINTEXT, value)
try setOption(ZMQ_GSSAPI_PLAINTEXT, value: &v, length: strideof(Int32))
} }
public func setGSSAPIPrincipal(value: String) throws { public func setGSSAPIPrincipal(value: String) throws {
try value.withCString { v in try setOption(ZMQ_GSSAPI_PRINCIPAL, value)
try setOption(ZMQ_GSSAPI_PRINCIPAL, value: v, length: value.utf8.count)
}
} }
public func setGSSAPIServer(value: Bool) throws { public func setGSSAPIServer(value: Bool) throws {
var v = value ? 1 : 0 try setOption(ZMQ_GSSAPI_SERVER, value)
try setOption(ZMQ_GSSAPI_SERVER, value: &v, length: strideof(Int32))
} }
public func setGSSAPIServicePrincipal(value: String) throws { public func setGSSAPIServicePrincipal(value: String) throws {
try value.withCString { v in try setOption(ZMQ_GSSAPI_SERVICE_PRINCIPAL, value)
try setOption(ZMQ_GSSAPI_SERVICE_PRINCIPAL, value: v, length: value.utf8.count)
}
} }
public func setHandshakeInterval(value: Int32) throws { public func setHandshakeInterval(value: Int32) throws {
var value = value try setOption(ZMQ_HANDSHAKE_IVL, value)
try setOption(ZMQ_HANDSHAKE_IVL, value: &value, length: strideof(Int32))
} }
public func setHeartbeatInterval(value: Int32) throws { // public func setHeartbeatInterval(value: Int32) throws {
var value = value // try setOption(ZMQ_HEARTBEAT_IVL, value)
try setOption(ZMQ_HEARTBEAT_IVL, value: &value, length: strideof(Int32)) // }
}
public func setHeartbeatTimeout(value: Int32) throws { // public func setHeartbeatTimeout(value: Int32) throws {
var value = value // try setOption(ZMQ_HEARTBEAT_TIMEOUT, value)
try setOption(ZMQ_HEARTBEAT_TIMEOUT, value: &value, length: strideof(Int32)) // }
}
public func setHeartbeatTTTL(value: Int32) throws { // public func setHeartbeatTTTL(value: Int32) throws {
var value = value // try setOption(ZMQ_HEARTBEAT_TTL, value)
try setOption(ZMQ_HEARTBEAT_TTL, value: &value, length: strideof(Int32)) // }
}
public func setIdentity(value: String) throws { public func setIdentity(value: String) throws {
try value.withCString { v in try setOption(ZMQ_IDENTITY, value)
try setOption(ZMQ_IDENTITY, value: v, length: value.utf8.count)
}
} }
public func setImmediate(value: Bool) throws { public func setImmediate(value: Bool) throws {
var value = value ? 1 : 0 try setOption(ZMQ_IMMEDIATE, value)
try setOption(ZMQ_IMMEDIATE, value: &value, length: strideof(Int32))
} }
public func setInvertMatching(value: Bool) throws { // public func setInvertMatching(value: Bool) throws {
var value = value ? 1 : 0 // try setOption(ZMQ_INVERT_MATCHING, value)
try setOption(ZMQ_INVERT_MATCHING, value: &value, length: strideof(Int32)) // }
}
public func setIPV6(value: Bool) throws { public func setIPV6(value: Bool) throws {
var value = value ? 1 : 0 try setOption(ZMQ_IPV6, value)
try setOption(ZMQ_IPV6, value: &value, length: strideof(Int32))
} }
public func setLinger(value: Int32) throws { public func setLinger(value: Int32) throws {
var value = value try setOption(ZMQ_LINGER, value)
try setOption(ZMQ_LINGER, value: &value, length: strideof(Int32))
} }
public func setMaxMessageSize(value: Int64) throws { public func setMaxMessageSize(value: Int64) throws {
@ -326,144 +314,107 @@ extension Socket {
} }
public func setMulticastHops(value: Int32) throws { public func setMulticastHops(value: Int32) throws {
var value = value try setOption(ZMQ_MULTICAST_HOPS, value)
try setOption(ZMQ_MULTICAST_HOPS, value: &value, length: strideof(Int32))
} }
public func setPlainPassword(value: String?) throws { public func setPlainPassword(value: String?) throws {
if let value = value { try setOption(ZMQ_PLAIN_PASSWORD, value)
try value.withCString { v in
try setOption(ZMQ_PLAIN_PASSWORD, value: v, length: value.utf8.count)
}
} else {
try setOption(ZMQ_PLAIN_PASSWORD, value: nil, length: 0)
}
} }
public func setPlainServer(value: Bool) throws { public func setPlainServer(value: Bool) throws {
var v = value ? 1 : 0 try setOption(ZMQ_PLAIN_SERVER, value)
try setOption(ZMQ_PLAIN_SERVER, value: &v, length: strideof(Int32))
} }
public func setPlainUsername(value: String?) throws { public func setPlainUsername(value: String?) throws {
if let value = value { try setOption(ZMQ_PLAIN_USERNAME, value)
try value.withCString { v in
try setOption(ZMQ_PLAIN_USERNAME, value: v, length: value.utf8.count)
}
} else {
try setOption(ZMQ_PLAIN_USERNAME, value: nil, length: 0)
}
} }
public func setProbeRouter(value: Bool) throws { public func setProbeRouter(value: Bool) throws {
var value = value ? 1 : 0 try setOption(ZMQ_PROBE_ROUTER, value)
try setOption(ZMQ_PROBE_ROUTER, value: &value, length: strideof(Int32))
} }
public func setRate(value: Int32) throws { public func setRate(value: Int32) throws {
var value = value try setOption(ZMQ_RATE, value)
try setOption(ZMQ_RATE, value: &value, length: strideof(Int32))
} }
public func setReceiveBuffer(value: Int32) throws { public func setReceiveBuffer(value: Int32) throws {
var value = value try setOption(ZMQ_RCVBUF, value)
try setOption(ZMQ_RCVBUF, value: &value, length: strideof(Int32))
} }
public func setReceiveHighWaterMark(value: Int32) throws { public func setReceiveHighWaterMark(value: Int32) throws {
var value = value try setOption(ZMQ_RCVHWM, value)
try setOption(ZMQ_RCVHWM, value: &value, length: strideof(Int32))
} }
public func setReceiveTimeout(value: Int32) throws { public func setReceiveTimeout(value: Int32) throws {
var value = value try setOption(ZMQ_RCVTIMEO, value)
try setOption(ZMQ_RCVTIMEO, value: &value, length: strideof(Int32))
} }
public func setReconnectInterval(value: Int32) throws { public func setReconnectInterval(value: Int32) throws {
var value = value try setOption(ZMQ_RECONNECT_IVL, value)
try setOption(ZMQ_RECONNECT_IVL, value: &value, length: strideof(Int32))
} }
public func setReconnectIntervalMax(value: Int32) throws { public func setReconnectIntervalMax(value: Int32) throws {
var value = value try setOption(ZMQ_RECONNECT_IVL_MAX, value)
try setOption(ZMQ_RECONNECT_IVL_MAX, value: &value, length: strideof(Int32))
} }
public func setRecoveryInterval(value: Int32) throws { public func setRecoveryInterval(value: Int32) throws {
var value = value try setOption(ZMQ_RECOVERY_IVL, value)
try setOption(ZMQ_RECOVERY_IVL, value: &value, length: strideof(Int32))
} }
public func setReqCorrelate(value: Bool) throws { public func setReqCorrelate(value: Bool) throws {
var value = value ? 1 : 0 try setOption(ZMQ_REQ_CORRELATE, value)
try setOption(ZMQ_REQ_CORRELATE, value: &value, length: strideof(Int32))
} }
public func setReqRelaxed(value: Bool) throws { public func setReqRelaxed(value: Bool) throws {
var value = value ? 1 : 0 try setOption(ZMQ_REQ_RELAXED, value)
try setOption(ZMQ_REQ_RELAXED, value: &value, length: strideof(Int32))
} }
public func setRouterHandover(value: Bool) throws { public func setRouterHandover(value: Bool) throws {
var value = value ? 1 : 0 try setOption(ZMQ_ROUTER_HANDOVER, value)
try setOption(ZMQ_ROUTER_HANDOVER, value: &value, length: strideof(Int32))
} }
public func setRouterMandatory(value: Bool) throws { public func setRouterMandatory(value: Bool) throws {
var value = value ? 1 : 0 try setOption(ZMQ_ROUTER_MANDATORY, value)
try setOption(ZMQ_ROUTER_MANDATORY, value: &value, length: strideof(Int32))
} }
public func setRouterRaw(value: Bool) throws { public func setRouterRaw(value: Bool) throws {
var value = value ? 1 : 0 try setOption(ZMQ_ROUTER_RAW, value)
try setOption(ZMQ_ROUTER_RAW, value: &value, length: strideof(Int32))
} }
public func setSendBuffer(value: Int32) throws { public func setSendBuffer(value: Int32) throws {
var value = value try setOption(ZMQ_SNDBUF, value)
try setOption(ZMQ_SNDBUF, value: &value, length: strideof(Int32))
} }
public func setSendHighWaterMark(value: Int32) throws { public func setSendHighWaterMark(value: Int32) throws {
var value = value try setOption(ZMQ_SNDHWM, value)
try setOption(ZMQ_SNDHWM, value: &value, length: strideof(Int32))
} }
public func setSendTimeout(value: Int32) throws { public func setSendTimeout(value: Int32) throws {
var value = value try setOption(ZMQ_SNDTIMEO, value)
try setOption(ZMQ_SNDTIMEO, value: &value, length: strideof(Int32))
} }
public func setStreamNotify(value: Bool) throws { // public func setStreamNotify(value: Bool) throws {
var value = value ? 1 : 0 // try setOption(ZMQ_STREAM_NOTIFY, value)
try setOption(ZMQ_STREAM_NOTIFY, value: &value, length: strideof(Int32)) // }
}
public func setSubscribe(value: String) throws { public func setSubscribe(value: Data) throws {
try value.withCString { v in try setOption(ZMQ_SUBSCRIBE, value)
try setOption(ZMQ_SUBSCRIBE, value: v, length: value.utf8.count)
}
} }
public func setTCPKeepAlive(value: Int32) throws { public func setTCPKeepAlive(value: Int32) throws {
var value = value try setOption(ZMQ_TCP_KEEPALIVE, value)
try setOption(ZMQ_TCP_KEEPALIVE, value: &value, length: strideof(Int32))
} }
public func setTCPKeepAliveCount(value: Int32) throws { public func setTCPKeepAliveCount(value: Int32) throws {
var value = value try setOption(ZMQ_TCP_KEEPALIVE_CNT, value)
try setOption(ZMQ_TCP_KEEPALIVE_CNT, value: &value, length: strideof(Int32))
} }
public func setTCPKeepAliveIdle(value: Int32) throws { public func setTCPKeepAliveIdle(value: Int32) throws {
var value = value try setOption(ZMQ_TCP_KEEPALIVE_IDLE, value)
try setOption(ZMQ_TCP_KEEPALIVE_IDLE, value: &value, length: strideof(Int32))
} }
public func setTCPKeepAliveInterval(value: Int32) throws { public func setTCPKeepAliveInterval(value: Int32) throws {
var value = value try setOption(ZMQ_TCP_KEEPALIVE_INTVL, value)
try setOption(ZMQ_TCP_KEEPALIVE_INTVL, value: &value, length: strideof(Int32))
} }
// public func setTCPRetransmitTimeout(var value: Int32) throws { // public func setTCPRetransmitTimeout(var value: Int32) throws {
@ -471,19 +422,15 @@ extension Socket {
// } // }
public func setTypeOfService(value: Int32) throws { public func setTypeOfService(value: Int32) throws {
var value = value try setOption(ZMQ_TOS, value)
try setOption(ZMQ_TOS, value: &value, length: strideof(Int32))
} }
public func setUnsubscribe(value: String) throws { public func setUnsubscribe(value: Data) throws {
try value.withCString { v in try setOption(ZMQ_UNSUBSCRIBE, value)
try setOption(ZMQ_UNSUBSCRIBE, value: v, length: value.utf8.count)
}
} }
public func setXPubVerbose(value: Bool) throws { public func setXPubVerbose(value: Bool) throws {
var v = value ? 1 : 0 try setOption(ZMQ_XPUB_VERBOSE, value)
try setOption(ZMQ_XPUB_VERBOSE, value: &v, length: strideof(Int32))
} }
// public func setXPubVerboseUnsubscribe(value: Bool) throws { // public func setXPubVerboseUnsubscribe(value: Bool) throws {
@ -491,30 +438,38 @@ extension Socket {
// try setOption(ZMQ_XPUB_VERBOSE_UNSUBSCRIBE, value: &v, length: strideof(Int32)) // try setOption(ZMQ_XPUB_VERBOSE_UNSUBSCRIBE, value: &v, length: strideof(Int32))
// } // }
public func setXPubManual(value: Bool) throws { // public func setXPubManual(value: Bool) throws {
var v = value ? 1 : 0 // try setOption(ZMQ_XPUB_MANUAL, value)
try setOption(ZMQ_XPUB_MANUAL, value: &v, length: strideof(Int32)) // }
}
public func setXPubNoDrop(value: Bool) throws { public func setXPubNoDrop(value: Bool) throws {
var v = value ? 1 : 0 try setOption(ZMQ_XPUB_NODROP, value)
try setOption(ZMQ_XPUB_NODROP, value: &v, length: strideof(Int32))
} }
public func setXPubWelcomeMessage(value: String) throws { // public func setXPubWelcomeMessage(value: String) throws {
try value.withCString { v in // try setOption(ZMQ_XPUB_WELCOME_MSG, value)
try setOption(ZMQ_XPUB_WELCOME_MSG, value: v, length: value.utf8.count) // }
}
}
public func setZAPDomain(value: String?) throws { public func setZAPDomain(value: String?) throws {
if let value = value { try setOption(ZMQ_ZAP_DOMAIN, value)
try value.withCString { v in }
try setOption(ZMQ_ZAP_DOMAIN, value: v, length: value.utf8.count) }
} extension Socket {
} else { func getOption(option: Int32) throws -> Int32 {
try setOption(ZMQ_ZAP_DOMAIN, value: nil, length: 0) var value: Int32 = 0
} var length = strideof(Int32)
try getOption(option, value: &value, length: &length)
return value
}
func getOption(option: Int32) throws -> Bool {
let value: Int32 = try getOption(option)
return value != 0
}
func getOption(option: Int32, count: Int) throws -> String? {
var value = [Int8](repeating: 0, count: count)
var length = value.count
try getOption(option, value: &value, length: &length)
return String(validatingUTF8: Array(value[0 ..< length]))
} }
} }
@ -527,136 +482,80 @@ extension Socket {
} }
public func getBacklog() throws -> Int32 { public func getBacklog() throws -> Int32 {
var value: Int32 = 0 return try getOption(ZMQ_BACKLOG)
var length = strideof(Int32)
try getOption(ZMQ_BACKLOG, value: &value, length: &length)
return value
} }
public func getConnectTimeout() throws -> Int32 { // public func getConnectTimeout() throws -> Int32 {
var value: Int32 = 0 // return try getOption(ZMQ_CONNECT_TIMEOUT)
var length = strideof(Int32) // }
try getOption(ZMQ_CONNECT_TIMEOUT, value: &value, length: &length)
return value
}
public func getCURVEPublicKey() throws -> String { public func getCURVEPublicKey() throws -> String {
var value = [Int8](repeating: 0, count: 41) return try getOption(ZMQ_CURVE_PUBLICKEY, count: 41)!
var length = value.count
try getOption(ZMQ_CURVE_PUBLICKEY, value: &value, length: &length)
return String(validatingUTF8: Array(value[0 ..< length]))!
} }
public func getCURVESecretKey() throws -> String { public func getCURVESecretKey() throws -> String {
var value = [Int8](repeating: 0, count: 41) return try getOption(ZMQ_CURVE_SECRETKEY, count: 41)!
var length = value.count
try getOption(ZMQ_CURVE_SECRETKEY, value: &value, length: &length)
return String(validatingUTF8: Array(value[0 ..< length]))!
} }
public func getCURVEServerKey() throws -> String { public func getCURVEServerKey() throws -> String {
var value = [Int8](repeating: 0, count: 41) return try getOption(ZMQ_CURVE_SERVERKEY, count: 41)!
var length = value.count
try getOption(ZMQ_CURVE_SERVERKEY, value: &value, length: &length)
return String(validatingUTF8: Array(value[0 ..< length]))!
} }
public func getEvents() throws -> PollEvent? { public func getEvents() throws -> PollEvent? {
var value: Int32 = 0 let value: Int32 = try getOption(ZMQ_EVENTS)
var length = strideof(Int32)
try getOption(ZMQ_EVENTS, value: &value, length: &length)
return Int(value) == -1 ? nil : PollEvent(rawValue: Int16(value)) return Int(value) == -1 ? nil : PollEvent(rawValue: Int16(value))
} }
public func getFileDescriptor() throws -> Int32 { public func getFileDescriptor() throws -> Int32 {
var value: Int32 = 0 return try getOption(ZMQ_FD)
var length = strideof(Int32)
try getOption(ZMQ_FD, value: &value, length: &length)
return value
} }
public func getGSSAPIPlainText() throws -> Bool { public func getGSSAPIPlainText() throws -> Bool {
var value: Int32 = 0 return try getOption(ZMQ_GSSAPI_PLAINTEXT)
var length = strideof(Int32)
try getOption(ZMQ_GSSAPI_PLAINTEXT, value: &value, length: &length)
return value != 0
} }
public func getGSSAPIPrincipal() throws -> String { public func getGSSAPIPrincipal() throws -> String {
var value = [Int8](repeating: 0, count: 256) return try getOption(ZMQ_GSSAPI_PRINCIPAL, count: 256)!
var length = value.count
try getOption(ZMQ_GSSAPI_PRINCIPAL, value: &value, length: &length)
return String(validatingUTF8: Array(value[0 ..< length]))!
} }
public func getGSSAPIServer() throws -> Bool { public func getGSSAPIServer() throws -> Bool {
var value: Int32 = 0 return try getOption(ZMQ_GSSAPI_SERVER)
var length = strideof(Int32)
try getOption(ZMQ_GSSAPI_SERVER, value: &value, length: &length)
return value != 0
} }
public func getGSSAPIServicePrincipal() throws -> String { public func getGSSAPIServicePrincipal() throws -> String {
var value = [Int8](repeating: 0, count: 256) return try getOption(ZMQ_GSSAPI_SERVICE_PRINCIPAL, count: 256)!
var length = value.count
try getOption(ZMQ_GSSAPI_SERVICE_PRINCIPAL, value: &value, length: &length)
return String(validatingUTF8: Array(value[0 ..< length]))!
} }
public func getHandshakeInterval() throws -> Int32 { public func getHandshakeInterval() throws -> Int32 {
var value: Int32 = 0 return try getOption(ZMQ_HANDSHAKE_IVL)
var length = strideof(Int32)
try getOption(ZMQ_HANDSHAKE_IVL, value: &value, length: &length)
return value
} }
public func getIdentity() throws -> String { public func getIdentity() throws -> String {
var value = [Int8](repeating: 0, count: 256) return try getOption(ZMQ_IDENTITY, count: 256) ?? ""
var length = value.count
try getOption(ZMQ_IDENTITY, value: &value, length: &length)
return String(validatingUTF8: Array(value[0 ..< length])) ?? ""
} }
public func getImmediate() throws -> Bool { public func getImmediate() throws -> Bool {
var value: Int32 = 0 return try getOption(ZMQ_IMMEDIATE)
var length = strideof(Int32)
try getOption(ZMQ_IMMEDIATE, value: &value, length: &length)
return value != 0
} }
public func getInvertMatching() throws -> Bool { // public func getInvertMatching() throws -> Bool {
var value: Int32 = 0 // return try getOption(ZMQ_INVERT_MATCHING)
var length = strideof(Int32) // }
try getOption(ZMQ_INVERT_MATCHING, value: &value, length: &length)
return value != 0
}
public func getIPV4Only() throws -> Bool { public func getIPV4Only() throws -> Bool {
var value: Int32 = 0 return try getOption(ZMQ_IPV4ONLY)
var length = strideof(Int32)
try getOption(ZMQ_IPV4ONLY, value: &value, length: &length)
return value != 0
} }
public func getIPV6() throws -> Bool { public func getIPV6() throws -> Bool {
var value: Int32 = 0 return try getOption(ZMQ_IPV6)
var length = strideof(Int32)
try getOption(ZMQ_IPV6, value: &value, length: &length)
return value != 0
} }
public func getLastEndpoint() throws -> String { public func getLastEndpoint() throws -> String {
var value = [Int8](repeating: 0, count: 256) return try getOption(ZMQ_LAST_ENDPOINT, count: 256)!
var length = value.count
try getOption(ZMQ_LAST_ENDPOINT, value: &value, length: &length)
return String(validatingUTF8: Array(value[0 ..< length]))!
} }
public func getLinger() throws -> Int32 { public func getLinger() throws -> Int32 {
var value: Int32 = 0 return try getOption(ZMQ_LINGER)
var length = strideof(Int32)
try getOption(ZMQ_LINGER, value: &value, length: &length)
return value
} }
public func getMaxMessageSize() throws -> Int64 { public func getMaxMessageSize() throws -> Int64 {
@ -667,143 +566,84 @@ extension Socket {
} }
public func getMechanism() throws -> SecurityMechanism { public func getMechanism() throws -> SecurityMechanism {
var value: Int32 = 0 let value: Int32 = try getOption(ZMQ_MECHANISM)
var length = strideof(Int32)
try getOption(ZMQ_MECHANISM, value: &value, length: &length)
return SecurityMechanism(rawValue: value)! return SecurityMechanism(rawValue: value)!
} }
public func getMulticastHops() throws -> Int32 { public func getMulticastHops() throws -> Int32 {
var value: Int32 = 0 return try getOption(ZMQ_MULTICAST_HOPS)
var length = strideof(Int32)
try getOption(ZMQ_MULTICAST_HOPS, value: &value, length: &length)
return value
} }
public func getPlainPassword() throws -> String { public func getPlainPassword() throws -> String {
var value = [Int8](repeating: 0, count: 256) return try getOption(ZMQ_PLAIN_PASSWORD, count: 256)!
var length = value.count
try getOption(ZMQ_PLAIN_PASSWORD, value: &value, length: &length)
return String(validatingUTF8: Array(value[0 ..< length]))!
} }
public func getPlainServer() throws -> Bool { public func getPlainServer() throws -> Bool {
var value: Int32 = 0 return try getOption(ZMQ_PLAIN_SERVER)
var length = strideof(Int32)
try getOption(ZMQ_PLAIN_SERVER, value: &value, length: &length)
return value != 0
} }
public func getPlainUsername() throws -> String { public func getPlainUsername() throws -> String {
var value = [Int8](repeating: 0, count: 256) return try getOption(ZMQ_PLAIN_USERNAME, count: 256)!
var length = value.count
try getOption(ZMQ_PLAIN_USERNAME, value: &value, length: &length)
return String(validatingUTF8: Array(value[0 ..< length]))!
} }
public func getRate() throws -> Int32 { public func getRate() throws -> Int32 {
var value: Int32 = 0 return try getOption(ZMQ_RATE)
var length = strideof(Int32)
try getOption(ZMQ_RATE, value: &value, length: &length)
return value
} }
public func getReceiveBuffer() throws -> Int32 { public func getReceiveBuffer() throws -> Int32 {
var value: Int32 = 0 return try getOption(ZMQ_RCVBUF)
var length = strideof(Int32)
try getOption(ZMQ_RCVBUF, value: &value, length: &length)
return value
} }
public func getReceiveHighWaterMark() throws -> Int32 { public func getReceiveHighWaterMark() throws -> Int32 {
var value: Int32 = 0 return try getOption(ZMQ_RCVHWM)
var length = strideof(Int32)
try getOption(ZMQ_RCVHWM, value: &value, length: &length)
return value
} }
public func getReceiveMore() throws -> Bool { public func getReceiveMore() throws -> Bool {
var value: Int32 = 0 return try getOption(ZMQ_RCVMORE)
var length = strideof(Int32)
try getOption(ZMQ_RCVMORE, value: &value, length: &length)
return value != 0
} }
public func getReceiveTimeout() throws -> Int32 { public func getReceiveTimeout() throws -> Int32 {
var value: Int32 = 0 return try getOption(ZMQ_RCVTIMEO)
var length = strideof(Int32)
try getOption(ZMQ_RCVTIMEO, value: &value, length: &length)
return value
} }
public func getReconnectInterval() throws -> Int32 { public func getReconnectInterval() throws -> Int32 {
var value: Int32 = 0 return try getOption(ZMQ_RECONNECT_IVL)
var length = strideof(Int32)
try getOption(ZMQ_RECONNECT_IVL, value: &value, length: &length)
return value
} }
public func getReconnectIntervalMax() throws -> Int32 { public func getReconnectIntervalMax() throws -> Int32 {
var value: Int32 = 0 return try getOption(ZMQ_RECONNECT_IVL_MAX)
var length = strideof(Int32)
try getOption(ZMQ_RECONNECT_IVL_MAX, value: &value, length: &length)
return value
} }
public func getRecoveryInterval() throws -> Int32 { public func getRecoveryInterval() throws -> Int32 {
var value: Int32 = 0 return try getOption(ZMQ_RECOVERY_IVL)
var length = strideof(Int32)
try getOption(ZMQ_RECOVERY_IVL, value: &value, length: &length)
return value
} }
public func getSendBuffer() throws -> Int32 { public func getSendBuffer() throws -> Int32 {
var value: Int32 = 0 return try getOption(ZMQ_SNDBUF)
var length = strideof(Int32)
try getOption(ZMQ_SNDBUF, value: &value, length: &length)
return value
} }
public func getSendHighWaterMark() throws -> Int32 { public func getSendHighWaterMark() throws -> Int32 {
var value: Int32 = 0 return try getOption(ZMQ_SNDHWM)
var length = strideof(Int32)
try getOption(ZMQ_SNDHWM, value: &value, length: &length)
return value
} }
public func getSendTimeout() throws -> Int32 { public func getSendTimeout() throws -> Int32 {
var value: Int32 = 0 return try getOption(ZMQ_SNDTIMEO)
var length = strideof(Int32)
try getOption(ZMQ_SNDTIMEO, value: &value, length: &length)
return value
} }
public func getTCPKeepAlive() throws -> Int32 { public func getTCPKeepAlive() throws -> Int32 {
var value: Int32 = 0 return try getOption(ZMQ_TCP_KEEPALIVE)
var length = strideof(Int32)
try getOption(ZMQ_TCP_KEEPALIVE, value: &value, length: &length)
return value
} }
public func getTCPKeepAliveCount() throws -> Int32 { public func getTCPKeepAliveCount() throws -> Int32 {
var value: Int32 = 0 return try getOption(ZMQ_TCP_KEEPALIVE_CNT)
var length = strideof(Int32)
try getOption(ZMQ_TCP_KEEPALIVE_CNT, value: &value, length: &length)
return value
} }
public func getTCPKeepAliveIdle() throws -> Int32 { public func getTCPKeepAliveIdle() throws -> Int32 {
var value: Int32 = 0 return try getOption(ZMQ_TCP_KEEPALIVE_IDLE)
var length = strideof(Int32)
try getOption(ZMQ_TCP_KEEPALIVE_IDLE, value: &value, length: &length)
return value
} }
public func getTCPKeepAliveInterval() throws -> Int32 { public func getTCPKeepAliveInterval() throws -> Int32 {
var value: Int32 = 0 return try getOption(ZMQ_TCP_KEEPALIVE_INTVL)
var length = strideof(Int32)
try getOption(ZMQ_TCP_KEEPALIVE_INTVL, value: &value, length: &length)
return value
} }
// public func getTCPRetransmitTimeout() throws -> Int32 { // public func getTCPRetransmitTimeout() throws -> Int32 {
@ -813,32 +653,21 @@ extension Socket {
// return value // return value
// } // }
public func getThreadSafe() throws -> Bool { // public func getThreadSafe() throws -> Bool {
var value: Int32 = 0 // return try getOption(ZMQ_THREAD_SAFE)
var length = strideof(Int32) // }
try getOption(ZMQ_THREAD_SAFE, value: &value, length: &length)
return value != 0
}
public func getTypeOfService() throws -> Int32 { public func getTypeOfService() throws -> Int32 {
var value: Int32 = 0 return try getOption(ZMQ_TOS)
var length = strideof(Int32)
try getOption(ZMQ_TOS, value: &value, length: &length)
return value
} }
public func getType() throws -> SocketType { public func getType() throws -> SocketType {
var value: Int32 = 0 let value: Int32 = try getOption(ZMQ_TYPE)
var length = strideof(Int32)
try getOption(ZMQ_TYPE, value: &value, length: &length)
return SocketType(rawValue: value)! return SocketType(rawValue: value)!
} }
public func getZAPDomain() throws -> String { public func getZAPDomain() throws -> String {
var value = [Int8](repeating: 0, count: 256) return try getOption(ZMQ_ZAP_DOMAIN, count: 256)!
var length = value.count
try getOption(ZMQ_ZAP_DOMAIN, value: &value, length: &length)
return String(validatingUTF8: Array(value[0 ..< length]))!
} }
} }