0001    //
0002    //  DispatchIO.swift
0003    //  DispatchKit <https://github.com/anpol/DispatchKit>
0004    //
0005    //  Copyright (c) 2014 Andrei Polushin. All rights reserved.
0006    //
0007    
0008    import Foundation
0009    
0010    public struct DispatchIO
DispatchIO.swift:53
         io: DispatchIO,
: DispatchObject { 0011 0012 @available(*, unavailable, renamed="rawValue") 0013 public var io: dispatch_io_t { 0014 return rawValue 0015 } 0016 0017 @available(*, unavailable, renamed="DispatchIO(rawValue:)") 0018 public init(raw io: dispatch_io_t) { 0019 self.rawValue = io 0020 } 0021 0022 public let rawValue
DispatchIO.swift:25
        self.rawValue = rawValue
DispatchIO.swift:38
        self.rawValue = rawValue
DispatchIO.swift:49
        self.rawValue = rawValue
DispatchIO.swift:56
        guard let rawValue = dispatch_io_create_with_io(type.rawValue, io.rawValue, queue?.rawValue, cleanup) else {
DispatchIO.swift:60
        self.rawValue = rawValue
DispatchIO.swift:86
        dispatch_io_read(rawValue, offset, length, queue.rawValue) {
DispatchIO.swift:95
        dispatch_io_write(rawValue, offset, data.rawValue, queue.rawValue) {
DispatchIO.swift:103
        dispatch_io_close(rawValue, flags.rawValue)
DispatchIO.swift:107
        return dispatch_io_get_descriptor(rawValue)
DispatchIO.swift:111
        dispatch_io_set_high_water(rawValue, highWater)
DispatchIO.swift:115
        dispatch_io_set_low_water(rawValue, lowWater)
DispatchIO.swift:119
        dispatch_io_set_interval(rawValue, UInt64(interval), flags.rawValue)
DispatchIO.swift:123
        dispatch_io_barrier(rawValue, block)
: dispatch_io_t 0023 0024 public init(rawValue: dispatch_io_t) { 0025 self.rawValue = rawValue 0026 } 0027 0028 public typealias CleanupHandler
DispatchIO.swift:32
         queue: DispatchQueue? = nil, cleanup: CleanupHandler! = nil) {
DispatchIO.swift:43
         queue: DispatchQueue? = nil, cleanup: CleanupHandler! = nil) {
DispatchIO.swift:54
         queue: DispatchQueue? = nil, cleanup: CleanupHandler! = nil) {
= (error: CInt) -> Void 0029 0030 public init!(_ type: DispatchIOType, 0031 fd: dispatch_fd_t, 0032 queue: DispatchQueue? = nil, cleanup: CleanupHandler! = nil) { 0033 0034 guard let rawValue = dispatch_io_create(type.rawValue, fd, queue?.rawValue, cleanup) else { 0035 return nil 0036 } 0037 0038 self.rawValue = rawValue 0039 } 0040 0041 public init!(_ type: DispatchIOType, 0042 path: String, oflag: CInt = O_RDONLY, mode: mode_t = 0o644, 0043 queue: DispatchQueue? = nil, cleanup: CleanupHandler! = nil) { 0044 0045 guard let rawValue = dispatch_io_create_with_path(type.rawValue, path, oflag, mode, queue?.rawValue, cleanup) else { 0046 return nil 0047 } 0048 0049 self.rawValue = rawValue 0050 } 0051 0052 public init!(_ type: DispatchIOType, 0053 io: DispatchIO, 0054 queue: DispatchQueue? = nil, cleanup: CleanupHandler! = nil) { 0055 0056 guard let rawValue = dispatch_io_create_with_io(type.rawValue, io.rawValue, queue?.rawValue, cleanup) else { 0057 return nil 0058 } 0059 0060 self.rawValue = rawValue 0061 } 0062 0063 0064 public static func read<T>(fd: dispatch_fd_t, length: Int = Int.max, 0065 queue: DispatchQueue, handler: (DispatchData<T>!, Int) -> Void) { 0066 0067 dispatch_read(fd, length, queue.rawValue) { 0068 (data, error) in 0069 handler(DispatchData<T>(rawValue: data), Int(error)) 0070 } 0071 } 0072 0073 public static func write<T>(fd: dispatch_fd_t, data: DispatchData<T>, 0074 queue: DispatchQueue, handler: (DispatchData<T>!, Int) -> Void) { 0075 0076 dispatch_write(fd, data.rawValue, queue.rawValue) { 0077 (data, error) in 0078 handler(DispatchData<T>(rawValue: data), Int(error)) 0079 } 0080 } 0081 0082 0083 public func read<T>(offset: off_t = 0, length: Int = Int.max, 0084 queue: DispatchQueue, handler: (Bool, DispatchData<T>!, Int) -> Void) { 0085 0086 dispatch_io_read(rawValue, offset, length, queue.rawValue) { 0087 (done, data, error) in 0088 handler(done, DispatchData<T>(rawValue: data), Int(error)) 0089 } 0090 } 0091 0092 public func write<T>(offset: off_t = 0, data: DispatchData<T>, 0093 queue: DispatchQueue, handler: (Bool, DispatchData<T>!, Int) -> Void) { 0094 0095 dispatch_io_write(rawValue, offset, data.rawValue, queue.rawValue) { 0096 (done, data, error) in 0097 handler(done, DispatchData<T>(rawValue: data), Int(error)) 0098 } 0099 } 0100 0101 0102 public func close(flags: DispatchIOCloseFlags = .Unspecified) { 0103 dispatch_io_close(rawValue, flags.rawValue) 0104 } 0105 0106 public var descriptior: dispatch_fd_t { 0107 return dispatch_io_get_descriptor(rawValue) 0108 } 0109 0110 public func setHighWater(highWater: Int) { 0111 dispatch_io_set_high_water(rawValue, highWater) 0112 } 0113 0114 public func setLowWater(lowWater: Int) { 0115 dispatch_io_set_low_water(rawValue, lowWater) 0116 } 0117 0118 public func setInterval(interval: Int64, flags: DispatchIOIntervalFlags = .Unspecified) { 0119 dispatch_io_set_interval(rawValue, UInt64(interval), flags.rawValue) 0120 } 0121 0122 public func barrier(block: dispatch_block_t) { 0123 dispatch_io_barrier(rawValue, block) 0124 } 0125 0126 } 0127