[comp.protocols.tcp-ip] Asyncio on Sockets

jon@CS.UCL.AC.UK (Jon Crowcroft) (07/03/87)

I know this is a Unix question and not really appropriate here,
but Berkeley and Sun people seem to read this list a lot.

Has anyone found problems setting async io on a RAW IP socket?
Under 3.2 on a Sun, it just doesn't seem to work; at least I
never get a SIGIO even when I see packets (using a net wathcer)
arriving at the machine. The manual pages and tutorials are somewhat
thin in this area.

Also, when using asyncio on a UDP socket, the process doesn't
get a SIGIO unless it has had another signal first.

Jon

brady@MACOM4.ARPA (Sean Brady) (07/07/87)

In reference to your question, we are using asynch io through raw sockets 
on Sun3's (under release 3.2), and have had little problems getting things
going once the initial slugging is done. If you look in the documentation,
you will be hopelessly confused unless you take the time to play with it 
for a bit. 
This is how we set up a asynch io socket under suntools (another confusing
beast):
make_my_socket(proto)
int proto;
{
        int s;

        if ((s = socket(AF_INET, SOCK_RAW, proto)) < 0) {
                perror("socket");
        }
        fcntl(s, F_SETFL, FASYNC);
        fcntl(s, F_SETOWN, pktpid);
        (void) notify_set_input_func(frame, process, s);
        return(s);
}
where pktpid is the process id that is setting up the socket.

If you are outside the suntools environment, just substitute a

      signal(SIGIO,process);

for the notify_set_input_func(bla...bla), where process is your socket reader.

That should give you a live socket that interupts when a packet of type
"socket" arrives. You could then use the "recvfrom" call to read from
and the "sendto" call to write to the socket created.

Hope this helps...

		-Sean (He who Laughs, Lasts)
***********************************************************************
"Mistakes are often the stepping stones to utter failure."