How to create named pipe (mkfifo) in Android?

后端 未结 5 1855
南方客
南方客 2020-12-13 07:35

I am having trouble in creating named pipe in Android and the example below illustrates my dilemma:

res = mkfifo(\"/sdcard/fifo9000\", S_IRWXO);
if (res != 0         


        
5条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-13 08:22

    I would like to append to the accepted answer:

    1) I am able to use this method to connect a socket between two native modules of an Android app.

    2) write() should be in a loop since it may not write the full amount requested in the first go. For example, it should read something like:

    void *p = buffer;
    count = 0;
    while ((count += write(clientSock, buffer, num_bytes - count)) < num_bytes)
    {
        if (count < 0)
        {
            close(clientSock);
            errCode = count;
            break;
        }
        p += count;
    }
    

    The error handling shown above is insufficient, since several error codes simply indicate to try again. See the documentation for write.

提交回复
热议问题