File tree Expand file tree Collapse file tree 1 file changed +28
-1
lines changed 
Sources/AsyncDNSResolver/dnssd Expand file tree Collapse file tree 1 file changed +28
-1
lines changed Original file line number Diff line number Diff line change @@ -141,6 +141,10 @@ struct DNSSD {
141141            let  serviceRefPtr  =  UnsafeMutablePointer< DNSServiceRef?> . allocate( capacity:  1 ) 
142142            defer  {  serviceRefPtr. deallocate ( )  } 
143143
144+             continuation. onTermination =  {  _ in 
145+                 DNSServiceRefDeallocate ( serviceRefPtr. pointee) 
146+             } 
147+ 
144148            // Run the query
145149            let  _code  =  DNSServiceQueryRecord ( 
146150                serviceRefPtr, 
@@ -158,9 +162,32 @@ struct DNSSD {
158162                return  continuation. finish ( throwing:  AsyncDNSResolver . Error ( dnssdCode:  _code) ) 
159163            } 
160164
165+             let  serviceSockFD  =  DNSServiceRefSockFD ( serviceRefPtr. pointee) 
166+             guard  serviceSockFD !=  - 1  else  { 
167+                 return  continuation. finish ( throwing:  AsyncDNSResolver . Error ( code:  . internalError) ) 
168+             } 
169+ 
170+             var  pollFDs  =  [ pollfd ( fd:  serviceSockFD,  events:  Int16 ( POLLIN) ,  revents:  0 ) ] 
171+             while  true  { 
172+                 guard  !Task. isCancelled else  { 
173+                     return  continuation. finish ( throwing:  CancellationError ( ) ) 
174+                 } 
175+ 
176+                 let  result  =  poll ( & pollFDs,  1 ,  0 ) 
177+                 guard  result !=  - 1  else  { 
178+                     return  continuation. finish ( throwing:  AsyncDNSResolver . Error ( code:  . internalError) ) 
179+                 } 
180+ 
181+                 if  result ==  0  { 
182+                     continue 
183+                 } 
184+                 if  result ==  1  { 
185+                     break 
186+                 } 
187+             } 
188+ 
161189            // Read reply from the socket (blocking) then call reply handler
162190            DNSServiceProcessResult ( serviceRefPtr. pointee) 
163-             DNSServiceRefDeallocate ( serviceRefPtr. pointee) 
164191
165192            // Streaming done
166193            continuation. finish ( ) 
    
 
   
 
     
   
   
          
     
  
    
     
 
    
      
     
 
     
    You can’t perform that action at this time.
  
 
    
  
     
    
      
        
     
 
       
      
     
   
 
    
    
  
 
  
 
     
    
0 commit comments