import { BindOptions , Socket } from 'dgram' ; import { AddressInfo } from 'net' ; /**
 * Async version of upd socket bind
 */ export function udpBind ( conn , port ? , address ? ) ; export function udpBind ( conn , options ) ; export function udpBind ( conn , arg1 ? , arg2 ? ) { return new Promise ( ( resolve , reject ) => { conn . once ( 'error' , reject ) ; conn . once ( 'listening' , ( ) => { conn . off ( 'error' , reject ) ; resolve ( conn . address ( ) ) ; } ) ; if ( arg2 !== undefined ) { conn . bind ( arg1 , arg2 ) ; } else { conn . bind ( arg1 ) ; } } ) ; } /**
 * Async version of udp socket read
 */ export function udpRead ( conn ) { return new Promise < Buffer > ( resolve => conn . once ( 'message' , resolve ) ) ; } /**
 * Async version of udp socket send
 */ export function udpSend ( conn , msg , port , address ) ; export function udpSend ( conn , msg , offset , length , port , address ) ; export function udpSend ( conn , arg1 , arg2 , arg3 , arg4 ? , arg5 ? ) { return new Promise ( ( resolve , reject ) => { try { if ( arg4 !== undefined ) { conn . send ( arg1 , arg2 , arg3 , arg4 , arg5 , ( err , sent ) => err ? reject ( err ) : resolve ( sent ) ) ; } else { conn . send ( arg1 , arg2 , arg3 , ( err , sent ) => ( err ? reject ( err ) : resolve ( sent ) ) ) ; } } catch ( err ) { reject ( err ) ; } } ) ; } /**
 * Async version of udp socket close
 */ export function udpClose ( conn ) { return new Promise ( ( resolve , reject ) => { try { conn . once ( 'close' , resolve ) ; conn . close ( ) ; } catch ( err ) { reject ( err ) ; } } ) ; }