@@ -356,6 +356,51 @@ 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
+
401
+ return fd ;
402
+ }
403
+
359
404
/**
360
405
* Send data through an IPC channel, wait for the reply or not.
361
406
*/
@@ -398,6 +443,12 @@ static rt_err_t _rt_raw_channel_send_recv_timeout(rt_channel_t ch, rt_channel_ms
398
443
return - RT_ENOMEM ;
399
444
}
400
445
446
+ /* IPC message : file descriptor */
447
+ if (data -> type == RT_CHANNEL_FD )
448
+ {
449
+ data -> u .fd .file = _ipc_msg_get_file (data -> u .fd .fd );
450
+ }
451
+
401
452
rt_ipc_msg_init (msg , data , need_reply );
402
453
403
454
if (need_reply )
@@ -686,6 +737,10 @@ static rt_err_t _rt_raw_channel_recv_timeout(rt_channel_t ch, rt_channel_msg_t d
686
737
ch -> stat = RT_IPC_STAT_ACTIVE ; /* no valid suspened receivers */
687
738
}
688
739
* data = msg_ret -> msg ; /* extract the transferred data */
740
+ if (data -> type == RT_CHANNEL_FD )
741
+ {
742
+ data -> u .fd .fd = _ipc_msg_fd_new (data -> u .fd .file );
743
+ }
689
744
_ipc_msg_free (msg_ret ); /* put back the message to kernel */
690
745
}
691
746
else
@@ -740,6 +795,10 @@ static rt_err_t _rt_raw_channel_recv_timeout(rt_channel_t ch, rt_channel_msg_t d
740
795
}
741
796
/* If waked up, the received message has been store into the thread. */
742
797
* data = ((rt_ipc_msg_t )(thread -> msg_ret ))-> msg ; /* extract data */
798
+ if (data -> type == RT_CHANNEL_FD )
799
+ {
800
+ data -> u .fd .fd = _ipc_msg_fd_new (data -> u .fd .file );
801
+ }
743
802
_ipc_msg_free (thread -> msg_ret ); /* put back the message to kernel */
744
803
thread -> msg_ret = RT_NULL ;
745
804
}
0 commit comments