STREAMS on HP-UX - HP UX

This is a discussion on STREAMS on HP-UX - HP UX ; How do I use STREAMS on HP-UX? The program below is supposed to send a descriptor over a pipe with ioctl I_SENDFD, but the ioctls complain "Not a typewriter" - ENOTTY. (I know about descriptor passing over sockets, but I'm ...

+ Reply to Thread
Results 1 to 2 of 2

Thread: STREAMS on HP-UX

  1. STREAMS on HP-UX

    How do I use STREAMS on HP-UX? The program below is supposed to send
    a descriptor over a pipe with ioctl I_SENDFD, but the ioctls complain
    "Not a typewriter" - ENOTTY. (I know about descriptor passing over
    sockets, but I'm doing STREAMS now. Or trying to.)

    Rick Jones tells me the HP-UX TCP/IP stack became "Streams-based" in
    HP-UX 11.0 and remains that way today. The box I'm using is more
    recent than that; uname -a says
    HP-UX hagrid B.11.11 U 9000/782 2002917847 unlimited-user license

    I found a libstream.a in /usr/lib and tried to link that in case that's
    what is missing, but that gave a run-time error:
    /usr/lib/dld.sl: Unresolved symbol: __shlinit (code) from /usr/lib/libstream.2
    ABORT instruction (core dumped)
    Am I missing some other library or magic invocation? The program
    compiles but fails on Linux and OSF1 too, but works on Solaris.

    #include
    #include
    #include
    #include
    #include
    #include
    #include
    #include
    #include

    /* Run either without args, or the read end with arg 'r' and
    * when that is waiting the write end with arg 'w'. */
    int main(int argc, char **argv)
    {
    int pp[2], fd, r = 0, w = 0;
    char *pipename = "/tmp/thepipe", *filename = "/tmp/thefile";
    # define CK(expr) ((expr) ? (void)0 : (perror(#expr), exit(1)))
    /* Open pipe descriptors */
    if (argc == 1) {
    CK(pipe(pp) == 0);
    w = r = 1;
    } else if (argv[1][0] == 'r') {
    unlink(pipename);
    CK(mkfifo(pipename, 0644) == 0);
    CK((pp[0] = open(pipename, O_RDONLY)) >= 0);
    r = 1;
    } else {
    CK((pp[1] = open(pipename, O_WRONLY)) >= 0);
    w = 1;
    }
    /* Handle write end */
    if (w) {
    static const char hello[] = "Hello, world!\n";
    unlink(filename);
    CK((fd = open(filename, O_CREAT|O_RDWR, 0644)) >= 0);
    unlink(filename);
    CK(write(fd, hello, sizeof(hello) - 1) == (int) sizeof(hello) - 1);
    CK(lseek(fd, 0, SEEK_SET) == 0);
    CK(ioctl(pp[1], I_SENDFD, fd) != -1);
    CK(close(fd) == 0);
    CK(close(pp[1]) == 0);
    }
    /* Handle read end */
    if (r) {
    struct strrecvfd fdinfo;
    static char buf[20];
    CK(ioctl(pp[0], I_RECVFD, &fdinfo) != -1);
    CK(close(pp[0]) == 0);
    if (!w)
    unlink(pipename);
    CK(read(fdinfo.fd, buf, sizeof(buf) - 1) >= 0);
    fputs(buf, stdout);
    CK(close(fdinfo.fd) == 0);
    }
    return 0;
    }

    --
    Regards,
    Hallvard

  2. Re: STREAMS on HP-UX

    While the TCP/IP stack is Streams based, "pipes" may not be Streams
    based by default (Sorry, forgot about that earlier). I believe it
    is a kernel tunable to enable/disable streams-based pipes. There
    should be more about Streams somewhere on docs.hp.com.

    rick jones
    --
    Wisdom Teeth are impacted, people are affected by the effects of events.
    these opinions are mine, all mine; HP might not want them anyway...
    feel free to post, OR email to rick.jones2 in hp.com but NOT BOTH...

+ Reply to Thread