@@ -198,17 +198,25 @@ pub fn op_net_listen_unix(
198198
199199pub fn net_listen_unixpacket (
200200 state : & mut OpState ,
201- address_path : & str ,
201+ address_path : Option < & str > ,
202202) -> Result < ( ResourceId , Option < String > ) , NetError > {
203- let permissions = state. borrow_mut :: < PermissionsContainer > ( ) ;
204- let address_path = permissions
205- . check_open (
206- Cow :: Borrowed ( Path :: new ( address_path) ) ,
207- OpenAccessKind :: ReadWriteNoFollow ,
208- Some ( "Deno.listenDatagram()" ) ,
209- )
210- . map_err ( NetError :: Permission ) ?;
211- let socket = UnixDatagram :: bind ( address_path) ?;
203+ let socket = match address_path {
204+ // Bind to given path
205+ Some ( address_path) => {
206+ let permissions = state. borrow_mut :: < PermissionsContainer > ( ) ;
207+ let address_path = permissions
208+ . check_open (
209+ Cow :: Borrowed ( Path :: new ( address_path) ) ,
210+ OpenAccessKind :: ReadWriteNoFollow ,
211+ Some ( "Deno.listenDatagram()" ) ,
212+ )
213+ . map_err ( NetError :: Permission ) ?;
214+ UnixDatagram :: bind ( address_path) ?
215+ }
216+
217+ // Leave socket unbound
218+ None => UnixDatagram :: unbound ( ) ?,
219+ } ;
212220 let local_addr = socket. local_addr ( ) ?;
213221 let pathname = local_addr. as_pathname ( ) . map ( pathstring) . transpose ( ) ?;
214222 let datagram_resource = UnixDatagramResource {
@@ -223,19 +231,19 @@ pub fn net_listen_unixpacket(
223231#[ serde]
224232pub fn op_net_listen_unixpacket (
225233 state : & mut OpState ,
226- #[ string] path : & str ,
234+ #[ string] path : Option < String > , // todo: Option< &str> not supported in ops yet
227235) -> Result < ( ResourceId , Option < String > ) , NetError > {
228236 super :: check_unstable ( state, "Deno.listenDatagram" ) ;
229- net_listen_unixpacket ( state, path)
237+ net_listen_unixpacket ( state, path. map ( |s| s . as_deref ( ) ) )
230238}
231239
232240#[ op2( stack_trace) ]
233241#[ serde]
234242pub fn op_node_unstable_net_listen_unixpacket (
235243 state : & mut OpState ,
236- #[ string] path : & str ,
244+ #[ string] path : Option < String > , // todo: Option< &str> not supported in ops yet
237245) -> Result < ( ResourceId , Option < String > ) , NetError > {
238- net_listen_unixpacket ( state, path)
246+ net_listen_unixpacket ( state, path. map ( |s| s . as_deref ( ) ) )
239247}
240248
241249pub fn pathstring ( pathname : & Path ) -> Result < String , NetError > {
0 commit comments