@@ -37,6 +37,7 @@ static uvwasi_errno_t uvwasi__insert_stdio(uvwasi_t* uvwasi,
3737  err  =  uvwasi_fd_table_insert (uvwasi ,
3838                               table ,
3939                               fd ,
40+                                NULL ,
4041                               name ,
4142                               name ,
4243                               type ,
@@ -58,6 +59,7 @@ static uvwasi_errno_t uvwasi__insert_stdio(uvwasi_t* uvwasi,
5859uvwasi_errno_t  uvwasi_fd_table_insert (uvwasi_t *  uvwasi ,
5960                                      struct  uvwasi_fd_table_t *  table ,
6061                                      uv_file  fd ,
62+                                       uv_tcp_t *  sock ,
6163                                      const  char *  mapped_path ,
6264                                      const  char *  real_path ,
6365                                      uvwasi_filetype_t  type ,
@@ -78,29 +80,40 @@ uvwasi_errno_t uvwasi_fd_table_insert(uvwasi_t* uvwasi,
7880  char *  rp_copy ;
7981  char *  np_copy ;
8082
81-   mp_len  =  strlen (mapped_path );
82-   rp_len  =  strlen (real_path );
83+   if  (type  !=  UVWASI_FILETYPE_SOCKET_STREAM ) {
84+     mp_len  =  strlen (mapped_path );
85+     rp_len  =  strlen (real_path );
86+   } else  {
87+     mp_len  =  0 ;
88+     rp_len  =  0 ;
89+     rp_copy  =  NULL ;
90+     mp_copy  =  NULL ;
91+     np_copy  =  NULL ;
92+   }
93+ 
8394  /* Reserve room for the mapped path, real path, and normalized mapped path. */ 
8495  entry  =  (struct  uvwasi_fd_wrap_t * )
8596    uvwasi__malloc (uvwasi , sizeof (* entry ) +  mp_len  +  mp_len  +  rp_len  +  3 );
8697  if  (entry  ==  NULL )
8798    return  UVWASI_ENOMEM ;
8899
89-   mp_copy  =  (char * )(entry  +  1 );
90-   rp_copy  =  mp_copy  +  mp_len  +  1 ;
91-   np_copy  =  rp_copy  +  rp_len  +  1 ;
92-   memcpy (mp_copy , mapped_path , mp_len );
93-   mp_copy [mp_len ] =  '\0' ;
94-   memcpy (rp_copy , real_path , rp_len );
95-   rp_copy [rp_len ] =  '\0' ;
96- 
97-   /* Calculate the normalized version of the mapped path, as it will be used for 
98-      any path calculations on this fd. Use the length of the mapped path as an 
99-      upper bound for the normalized path length. */ 
100-   err  =  uvwasi__normalize_path (mp_copy , mp_len , np_copy , mp_len );
101-   if  (err ) {
102-     uvwasi__free (uvwasi , entry );
103-     goto exit ;
100+   if  (type  !=  UVWASI_FILETYPE_SOCKET_STREAM ) {
101+     mp_copy  =  (char * )(entry  +  1 );
102+     rp_copy  =  mp_copy  +  mp_len  +  1 ;
103+     np_copy  =  rp_copy  +  rp_len  +  1 ;
104+     memcpy (mp_copy , mapped_path , mp_len );
105+     mp_copy [mp_len ] =  '\0' ;
106+     memcpy (rp_copy , real_path , rp_len );
107+     rp_copy [rp_len ] =  '\0' ;
108+ 
109+     /* Calculate the normalized version of the mapped path, as it will be used for 
110+        any path calculations on this fd. Use the length of the mapped path as an 
111+        upper bound for the normalized path length. */ 
112+     err  =  uvwasi__normalize_path (mp_copy , mp_len , np_copy , mp_len );
113+     if  (err ) {
114+       uvwasi__free (uvwasi , entry );
115+       goto exit ;
116+     }
104117  }
105118
106119  uv_rwlock_wrlock (& table -> rwlock );
@@ -150,6 +163,7 @@ uvwasi_errno_t uvwasi_fd_table_insert(uvwasi_t* uvwasi,
150163
151164  entry -> id  =  index ;
152165  entry -> fd  =  fd ;
166+   entry -> sock  =  sock ;
153167  entry -> path  =  mp_copy ;
154168  entry -> real_path  =  rp_copy ;
155169  entry -> normalized_path  =  np_copy ;
@@ -280,6 +294,7 @@ uvwasi_errno_t uvwasi_fd_table_insert_preopen(uvwasi_t* uvwasi,
280294  return  uvwasi_fd_table_insert (uvwasi ,
281295                                table ,
282296                                fd ,
297+                                 NULL ,
283298                                path ,
284299                                real_path ,
285300                                UVWASI_FILETYPE_DIRECTORY ,
@@ -290,6 +305,26 @@ uvwasi_errno_t uvwasi_fd_table_insert_preopen(uvwasi_t* uvwasi,
290305}
291306
292307
308+ uvwasi_errno_t  uvwasi_fd_table_insert_preopen_socket (uvwasi_t *  uvwasi ,
309+                                               struct  uvwasi_fd_table_t *  table ,
310+                                               uv_tcp_t *  sock ) {
311+   if  (table  ==  NULL  ||  sock  ==  NULL )
312+     return  UVWASI_EINVAL ;
313+ 
314+   return  uvwasi_fd_table_insert (uvwasi ,
315+                                 table ,
316+                                 -1 ,
317+                                 sock ,
318+                                 NULL ,
319+                                 NULL ,
320+                                 UVWASI_FILETYPE_SOCKET_STREAM ,
321+                                 UVWASI__RIGHTS_SOCKET_BASE ,
322+                                 UVWASI__RIGHTS_SOCKET_INHERITING ,
323+                                 1 ,
324+                                 NULL );
325+ }
326+ 
327+ 
293328uvwasi_errno_t  uvwasi_fd_table_get (struct  uvwasi_fd_table_t *  table ,
294329                                   const  uvwasi_fd_t  id ,
295330                                   struct  uvwasi_fd_wrap_t * *  wrap ,
0 commit comments