3. Any inter-process communication (Socketpair_binder)
Each time the process executes open open file, it will have a structure of file in the kernel to represent it;
For each process in the kernel there will be a task_struct representation process, the structure of the body has a files_struct structure, the structure has a fdtble structure, the structure has a struct file **fd,fd is the number of groups, fd[ The handle returned at open] is the file structure of the corresponding files saved
Therefore, the file handle of a different process only has meaning in this process, if you want to use this file handle outside the process, you need to let the outside process fd[any handle can] point to the desired process file
Here you use Binder to transfer file handles:
(1) APP1 open (file) gets fd1;
(2) by Binder Drive, according to FD1 get FILE:FILES->FDT->FD[FD1]
(3) Remove the empty item Fd2 from APP2 's files->fdt->fd, let Fd[fd2] point to the file
(4) APP1 through the FD1,APP2 through the FD2 can access the same file files, fd1 and FD2 is not the same
Remove App_0004_binder_cpp_app V4 to modify:
First time:
git clone https://github.com/weidongshan/APP_0004_Binder_CPP_App.git
Update:
Git pull origin
Remove the specified version:
git checkout v4//Compatible App_0005_binder_java_app
Reference code:
Frameworks\base\core\jni\android_view_inputchannel.cpp (using binder to transfer file handles)
Server-side Write Fd:android_view_inputchannel_nativewritetoparcel
Parcel->writedupfiledescriptor
Client-side Read Fd:android_view_inputchannel_nativereadfromparcel
int rawfd = Parcel->readfiledescriptor ();
int DUPFD = DUP (RAWFD);
Frameworks\native\libs\binder\parcel.cpp
Program V5 that supports transferring file handles:
First time:
git clone https://github.com/weidongshan/APP_0004_Binder_CPP_App.git
Update:
Git pull origin
Remove the specified version:
git checkout v5//V5, use Binder to transfer file descriptor
Compile:
Put App_0004_binder_cpp_app into/work/android-5.0.2/frameworks/testing.
Cd/work/android-5.0.2/
. Setenv
Lunch//Select single board
Mmm Frameworks/testing/app_0004_binder_cpp_app
Cp/work/android-5.0.2/out/target/product/tiny4412/system/bin/test_*/work/nfs_root/android_fs/
Test:
Su
BusyBox mount-t nfs-o nolock,vers=2 192.168.1.123:/work/nfs_root/mnt
Logcat helloservice:* goodbyeservice:* testservice:* *:s &
echo ASFSDFASDF > 1.txt
./test_server 1.txt &
./test_client ReadFile
10.3, Android Input System _ Prerequisite Linux Programming Knowledge _ arbitrary process bidirectional communication (Scoketpair+binder)