getmsg error - Linux

This is a discussion on getmsg error - Linux ; It's an APUE example. #include #include #include #include #define BUFFSIZE 8192 int main() { int n,flag; char ctlbuf[BUFFSIZE],databuf[BUFFSIZE]; struct strbuf ctl,dat; ctl.buf=ctlbuf; ctl.maxlen=BUFFSIZE; dat.buf=databuf; dat.maxlen=BUFFSIZE; for(; { flag=0; if ((n=getmsg(STDIN_FILENO,&ctl,&dat,&flag)) fprintf(stderr,"getmsg error\n"); fprintf(stderr,"flag=%d\nctl.len=%d\ndat.len=%d\n\n",flag,ctl.len,dat.len); if(dat.len==0){ exit(0); }else if(dat.len>0){ if(write(STDOUT_FILENO,dat.buf,dat.len)!=dat.len){ fprintf(stderr,"write error\n"); ...

+ Reply to Thread
Results 1 to 4 of 4

Thread: getmsg error

  1. getmsg error

    It's an APUE example.

    #include
    #include
    #include
    #include

    #define BUFFSIZE 8192

    int main()
    {
    int n,flag;
    char ctlbuf[BUFFSIZE],databuf[BUFFSIZE];
    struct strbuf ctl,dat;

    ctl.buf=ctlbuf;
    ctl.maxlen=BUFFSIZE;
    dat.buf=databuf;
    dat.maxlen=BUFFSIZE;
    for(;{
    flag=0;
    if ((n=getmsg(STDIN_FILENO,&ctl,&dat,&flag))<0)
    fprintf(stderr,"getmsg error\n");
    fprintf(stderr,"flag=%d\nctl.len=%d\ndat.len=%d\n\n",flag,ctl.len,dat.len);
    if(dat.len==0){
    exit(0);
    }else if(dat.len>0){
    if(write(STDOUT_FILENO,dat.buf,dat.len)!=dat.len){
    fprintf(stderr,"write error\n");
    }
    }
    }
    return 0;
    }

    ubuntu 6.06
    $ echo hello | a.out
    getmsg error #this may because the implementation of pipe,
    but what's wrong about the following tests? The book said it should be as
    below, but it pritns ``getmsg error" here, why?
    $ ./a.out
    this is line 1 #input
    flag=0 ctl.len=-1 dat.len=15
    this is line 1
    and line 2 #input
    flag=0 ctl.len=-1 dat.len=11
    and line 2
    ^D #input
    flag=0 ctl.len=-1 dat.len=0



  2. Re: getmsg error

    Ronald wrote:
    > It's an APUE example.


    > if ((n=getmsg(STDIN_FILENO,&ctl,&dat,&flag))<0)
    > fprintf(stderr,"getmsg error\n");


    > ubuntu 6.06
    > $ echo hello | a.out
    > getmsg error #this may because the implementation of pipe,
    > but what's wrong about the following tests? The book said it should be as
    > below, but it pritns ``getmsg error" here, why?


    If you have that kind of problem it's often useful to determine why
    a function failed by checking errno, e.g. by using the perror() function
    (for which you would need to include ). And APUE outputs a bit
    more elaborate error nessages, involving outputting errno (or a string
    associated with the value). That typically gives you a good idea of the
    reason it failed. On my machine errno is set to ENOSYS, indicating that
    the function isn't implemented on the system. Perhaps it's also missing
    on yours? I also tried if STDIN_FILENO is a file descriptor for a STREAMS
    file at all but isastream() indicates that it isn't, but perhaps
    isastream() always returns this value since the other functions aren't
    implemented...
    Regards, Jens
    --
    \ Jens Thoms Toerring ___ jt@toerring.de
    \__________________________ http://toerring.de

  3. Re: getmsg error

    Jens Thoms Toerring wrote:
    > Ronald wrote:
    >> It's an APUE example.

    >
    >> if ((n=getmsg(STDIN_FILENO,&ctl,&dat,&flag))<0)
    >> fprintf(stderr,"getmsg error\n");

    >
    >> ubuntu 6.06
    >> $ echo hello | a.out
    >> getmsg error #this may because the implementation of pipe,
    >> but what's wrong about the following tests? The book said it should be as
    >> below, but it pritns ``getmsg error" here, why?

    >
    > If you have that kind of problem it's often useful to determine why
    > a function failed by checking errno, e.g. by using the perror() function
    > (for which you would need to include ). And APUE outputs a bit
    > more elaborate error nessages, involving outputting errno (or a string
    > associated with the value). That typically gives you a good idea of the
    > reason it failed. On my machine errno is set to ENOSYS, indicating that
    > the function isn't implemented on the system. Perhaps it's also missing
    > on yours? I also tried if STDIN_FILENO is a file descriptor for a STREAMS
    > file at all but isastream() indicates that it isn't, but perhaps
    > isastream() always returns this value since the other functions aren't
    > implemented...
    > Regards, Jens
    > --
    > \ Jens Thoms Toerring ___ jt@toerring.de
    > \__________________________ http://toerring.de

    Truely, it said ``Function not implemented".
    Does it mean it is unnecessary to be implemented by far, and it's only
    legacy?

  4. Re: getmsg error

    Ronald wrote:
    > Truely, it said ``Function not implemented".
    > Does it mean it is unnecessary to be implemented by far, and it's only
    > legacy?


    I have never used STREAMS, so I am no expert on this at all. But e.g.
    the Wikipedia article on STREAMS (http://en.wikipedia.org/wiki/STREAMS)
    says, that "STREAMS functionality is not included with the Linux kernel;
    the kernel developers consider it technically inadequate,...".

    But there seem to be some implementations:

    http://lis.wanware.com/

    and

    http://www.openss7.org/download.html

    if you really need it.
    Regards, Jens
    --
    \ Jens Thoms Toerring ___ jt@toerring.de
    \__________________________ http://toerring.de

+ Reply to Thread