Newsgroups: vmsnet.networks.tcp-ip.wintcp
Subject: Re: porting Unix code to Wollongong
From: fxmlk@acad3.alaska.edu (KIENENBERGER MIKE L)
Date: Thu, 17 Dec 1992 04:23:00 GMT
Organization: University of Alaska - Fairbanks
News-Software: VAX/VMS VNEWS 1.41.UAC

In article <1gocceINN124@pith.uoregon.edu>, jqj@duff.uoregon.edu (JQ Johnson) writes...
>I'm in the process of porting some moderately complex Unix networking
>code to Wollongong, and would like to solicit some advice from the
>community.  My problem is with netread(), netwrite(), and netclose().
> 
>The code I'm working with makes the assumption that local fds (generated
>by VAXC open()) and remote sockets (generated by Wollongong socket())
>can be treated equivalently.  For instance, there are library
>routines that accept either and (sometimes after several levels of
>subroutine) call read() or write() to perform the I/O.  What's the
>best way to port such code?
> 
>My options seem to be (1) to duplicate the library routines, and have the
>high level routines call the net- version of the library if appropriate,
>(2) [almost equivalent] add flag parameters or global variables to
>communicate whether a particular int refers to a VAXC fd or a TWG socket,
>or (3) to decide in the low level routine what a particular int refers to.
>What's my best bet?  
> 
>In particular, is there any reliable way to distinguish between a fd and a
>socket?  I notice that VAXC, like most Unixes, returns small sequential
>ints for fds; Wollongong appears to return user memory addresses, e.g.
>280, 284, etc., so a gross check on value would appear to be possible.
> 
>By the way, I have the same questions as the above for Multinet.  UCX
>presumably is not a problem in this regard.

Yeah, I discovered this problem.
My solution was to just use sys$wflor() and sys$qio calls.
Make sure to use unique event flags for each channel/socket.

Here's some snippets of code from something I was using.
It "selects" between a TWG socket and terminal fd.

    done = 0;
    status = sys$clref(13);
    status = sys$clref(14);
    checkingsocket = checkingterminal = 0;
    while(0 == done)
    {
        struct iosbtype
        {
            short cond;
            short count;
            int something;
        } terminaliosb, socketiosb;

        if (0 == checkingsocket)
        {
           status = sys$qio(13, socketchannel, IO$_RECEIVE, &socketiosb, 0, 0,
                            socketbuffer, sizeof(socketbuffer), 0, 0, 0, 0);
            checkingsocket = 1;
        }
        if (0 == checkingterminal)
        {
	    status = sys$qio(14, termchannel, IO$_READVBLK, &terminaliosb, 0,
                             0, terminalbuffer, sizeof(terminalbuffer), 0, 0,
                             0, 0);    
            checkingterminal = 1;
        }
        status = sys$wflor(1,24576); /* 2^13 + 2^14 */

        status = sys$clref(13);
        if (status == SS$_WASSET)
        {
            checkingsocket = 0;
	    /* Do something now that the socket is ready */
        }

        status = sys$clref(14);
        if (status == SS$_WASSET)
        {
            checkingterminal = 0;
	    /* Do something now that the terminal is ready */
         }
    }

=============================================================================
-Mike Kienenberger                       FXMLK@ALASKA           (BITNet)
 Academic Computing                      FXMLK@acad3.alaska.edu (Internet)
 University of Alaska-Fairbanks
 "I'm a computer programmer....<link><link><kludge><kludge> say-no-more!"
Newsgroups: vmsnet.networks.tcp-ip.wintcp