× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



>
> Maybe I should ask if anyone's ever _used_ getsockopt() on an AS/400 to
> retrieve error info as is described for write() and send() in the Unix
> APIs guide? If anyone's been successful with it, then I'll expect my
> logic is wrong. Otherwise I'll contact IBM. (Unfortunately, if there's a
> bug, it means support is gone for pre-V5; and V5R1 is closing fast.)
>

Sorry I didn't reply earlier, you're a smart guy and I didn't want to
make a fool of myself by replying without first being able to test my
theory, for fear of looking like a fool. :)

I wrote a sample program that connects to the web server I've got running
on my iSeries.   It sends QUIT, gobbles up the server's reply, then starts
writing data to get an EPIPE error.

It then proceeds to call getsockopt() to get the SO_ERROR error number,
so that you can see what went wrong.   In my case, of course, the error
was that the socket was reset by the peer (as expected, since that's
actually what happened!)

This program also demonstrates another interesting aspect of getsockopt()
for the SO_ERROR option...   it resets the value of the error.   Since the
server disconnects me rather quickly (it being on localhost and all) I'm
able to get the actual error the first time, and get error 0 (no error
occured) on the next few iterations of the loop.

Hope you find it useful.   Here it is:

      **
      **  the /copy files in this code are from my socket tutorial
      **  which you can find here:
      **          http://www.scottklement.com/rpg/socktut/
      **
      **  compile with:
      **        CRTBNDRPG xxx SRCFILE(xxx/xxx)
      **
     h dftactgrp(*no) actgrp(*new) bnddir('QC2LE')

     d/copy socktut/qrpglesrc,socket_h
     d/copy socktut/qrpglesrc,errno_h

     D read            PR            10I 0 ExtProc('read')
     D  handle                       10i 0 value
     D  buffer                         *   value
     D  bytes                        10U 0 value
     D write           PR            10I 0 ExtProc('write')
     D  handle                       10I 0 value
     D  buffer                         *   value
     D  bytes                        10U 0 value

     D msg             s             50A
     D s               s             10I 0
     D connto          s                   like(sockaddr)
     D ch              s              1A
     D buf             s          16384A   inz(*ALLx'00')
     d err             s             10I 0
     d len             s             10I 0
     d x               s             10I 0

     D trans           pr                  extpgm('QDCXLATE')
     D   length                       5P 0 const
     D   buf                      32766A   options(*varsize)
     D   table                       10A   const

     c                   eval      *inlr = *on

      ** make a socket and connect it to the web server on the loopback
      ** interface.
     c                   eval      s = socket(AF_INET: SOCK_STREAM: 0)
     c                   if        s < 0
     c                   eval      msg = 'socket() failed?!'
     c                   dsply                   msg
     c                   return
     c                   endif

     c                   eval      p_sockaddr = %addr(connto)
     c                   eval      connto = *ALLx'00'
     c                   eval      sin_family = AF_INET
     c                   eval      sin_addr = INADDR_LOOPBACK
     c                   eval      sin_port = 80

     c                   if        connect(s:%addr(connto):%size(connto))<0
     c                   eval      msg = 'connect() failed?!'
     c                   dsply                   msg
     c                   return
     c                   endif

      ** make the web server disconnect me:
     c                   eval      buf = 'QUIT' + x'0d25'
     c                   callp     trans(%len(%trimr(buf)): buf: 'QTCPASC')
     c                   callp     write(s: %addr(buf): %len(%trimr(buf)))

      ** gobble up the message the server sent back
     c                   dow       read(s: %addr(buf): %size(buf)) > 0
     c                   enddo

      ** now, we should get EPIPE errors sending, because we
      ** lost connection.
     c                   do        5             x
     c                   eval      len = write(s: %addr(buf): %size(buf))
     c                   if        len < %size(buf)
     c                   if        errno = EPIPE
     c                   eval      len = %size(err)
     c                   callp     getsockopt(s: SOL_SOCKET: SO_ERROR:
     c                                 %addr(err): len)
     c     ' '           dsply
     c                   eval      msg = %trim(%editc(x:'Z'))  +
     c                                   ' SO_ERROR = ' +
     c                                    %trim(%editc(err:'Z'))
     c     msg           dsply
     c                   eval      msg = %str(strerror(err))
     c     msg           dsply
     c                   endif
     c                   endif
     c                   enddo

     c                   callp     close(s)
     c                   eval      *inlr = *on

      /define ERRNO_LOAD_PROCEDURE
      /copy socktut/qrpglesrc,errno_h

As an Amazon Associate we earn from qualifying purchases.

This thread ...

Follow-Ups:
Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.