@@ -117,9 +117,9 @@ public final class L2CAPSocket: L2CAPSocketProtocol {
117117 return optionValue
118118 }
119119
120- //. socket domain and protocol
120+ // socket domain and protocol
121121 guard try value ( for: SO_DOMAIN) == AF_BLUETOOTH,
122- try value ( for: SO_PROTOCOL) == BluetoothProtocol . l2cap. rawValue
122+ try value ( for: SO_PROTOCOL) == BluetoothSocketProtocol . l2cap. rawValue
123123 else { return false }
124124
125125 return true
@@ -135,7 +135,7 @@ public final class L2CAPSocket: L2CAPSocketProtocol {
135135 // open socket
136136 let internalSocket = socket ( AF_BLUETOOTH,
137137 SOCK_SEQPACKET,
138- BluetoothProtocol . l2cap. rawValue)
138+ BluetoothSocketProtocol . l2cap. rawValue)
139139
140140 // error creating socket
141141 guard internalSocket >= 0
@@ -164,18 +164,15 @@ public final class L2CAPSocket: L2CAPSocketProtocol {
164164
165165 /// Bluetooth address
166166 public var address : BluetoothAddress {
167-
168167 return BluetoothAddress ( littleEndian: internalAddress. l2_bdaddr)
169168 }
170169
171170 public var addressType : AddressType {
172-
173171 return AddressType ( rawValue: internalAddress. l2_bdaddr_type) !
174172 }
175173
176174 /// Protocol/Service Multiplexer (PSM)
177175 public var protocolServiceMultiplexer : UInt16 {
178-
179176 return UInt16 ( littleEndian: internalAddress. l2_psm)
180177 }
181178
@@ -260,7 +257,7 @@ public final class L2CAPSocket: L2CAPSocketProtocol {
260257 // make socket non-blocking
261258 try setNonblocking ( )
262259 }
263-
260+
264261 /// Reads from the socket.
265262 public func recieve( _ bufferSize: Int = 1024 ) throws -> Data ? {
266263
@@ -287,6 +284,16 @@ public final class L2CAPSocket: L2CAPSocketProtocol {
287284 return Data ( actualBytes)
288285 }
289286
287+ /// Blocks until data is ready.
288+ public func waitForEvents( timeout: TimeInterval ) {
289+ var pollData = pollfd (
290+ fd: internalSocket,
291+ events: Int16 ( POLLIN) & Int16 ( POLLOUT) & Int16 ( POLLPRI) & Int16 ( POLLERR) & Int16 ( POLLHUP) & Int16 ( POLLNVAL) ,
292+ revents: 0
293+ )
294+ poll ( & pollData, 1 , 0 )
295+ }
296+
290297 private func canRead( ) throws -> Bool {
291298
292299 var readSockets = FileDescriptorSet ( )
0 commit comments