@@ -356,6 +356,53 @@ static void sender_timeout(void *parameter)
356
356
rt_schedule ();
357
357
}
358
358
359
+ /**
360
+ * Get file vnode from fd.
361
+ */
362
+ static void * _ipc_msg_get_file (int fd )
363
+ {
364
+ struct dfs_file * d ;
365
+
366
+ d = fd_get (fd );
367
+ if (d == RT_NULL )
368
+ return RT_NULL ;
369
+
370
+ if (!d -> vnode )
371
+ return RT_NULL ;
372
+
373
+ d -> vnode -> ref_count ++ ;
374
+ return (void * )d -> vnode ;
375
+ }
376
+
377
+ /**
378
+ * Get fd from file vnode.
379
+ */
380
+ static int _ipc_msg_fd_new (void * file )
381
+ {
382
+ int fd ;
383
+ struct dfs_file * d ;
384
+
385
+ fd = fd_new ();
386
+ if (fd < 0 )
387
+ {
388
+ return -1 ;
389
+ }
390
+
391
+ d = fd_get (fd );
392
+ if (!d )
393
+ {
394
+ fd_release (fd );
395
+ return -1 ;
396
+ }
397
+
398
+ d -> vnode = (struct dfs_vnode * )file ;
399
+ d -> flags = O_RDWR ; /* set flags as read and write */
400
+ d -> vnode -> size = 0 ;
401
+ d -> pos = 0 ;
402
+
403
+ return fd ;
404
+ }
405
+
359
406
/**
360
407
* Send data through an IPC channel, wait for the reply or not.
361
408
*/
@@ -398,6 +445,12 @@ static rt_err_t _rt_raw_channel_send_recv_timeout(rt_channel_t ch, rt_channel_ms
398
445
return - RT_ENOMEM ;
399
446
}
400
447
448
+ /* IPC message : file descriptor */
449
+ if (data -> type == RT_CHANNEL_FD )
450
+ {
451
+ data -> u .fd .file = _ipc_msg_get_file (data -> u .fd .fd );
452
+ }
453
+
401
454
rt_ipc_msg_init (msg , data , need_reply );
402
455
403
456
if (need_reply )
@@ -686,6 +739,10 @@ static rt_err_t _rt_raw_channel_recv_timeout(rt_channel_t ch, rt_channel_msg_t d
686
739
ch -> stat = RT_IPC_STAT_ACTIVE ; /* no valid suspened receivers */
687
740
}
688
741
* data = msg_ret -> msg ; /* extract the transferred data */
742
+ if (data -> type == RT_CHANNEL_FD )
743
+ {
744
+ data -> u .fd .fd = _ipc_msg_fd_new (data -> u .fd .file );
745
+ }
689
746
_ipc_msg_free (msg_ret ); /* put back the message to kernel */
690
747
}
691
748
else
@@ -740,6 +797,10 @@ static rt_err_t _rt_raw_channel_recv_timeout(rt_channel_t ch, rt_channel_msg_t d
740
797
}
741
798
/* If waked up, the received message has been store into the thread. */
742
799
* data = ((rt_ipc_msg_t )(thread -> msg_ret ))-> msg ; /* extract data */
800
+ if (data -> type == RT_CHANNEL_FD )
801
+ {
802
+ data -> u .fd .fd = _ipc_msg_fd_new (data -> u .fd .file );
803
+ }
743
804
_ipc_msg_free (thread -> msg_ret ); /* put back the message to kernel */
744
805
thread -> msg_ret = RT_NULL ;
745
806
}
0 commit comments