[comp.unix.questions] DATAGRAM sockets in the UNIX DOMAIN.

pau@stl.stc.co.uk (Vipin Pau) (09/09/87)

Help needed with INTERRUPTS when used with DATAGRAM sockets
in the UNIX domain.


At the moment we have a simple CLIENT/SERVER model where
the communication is done using DATAGRAM sockets in the INET domain 
with INTERRUPTS which works successfully.

The same exercise in the UNIX  domain has not been sucessful. 
A skeleton code is supplied to clarify (hopefully)


/*  SERVER */
struct sockaddr_un sock;
fd=socket(AF_UNIX,SOCK_DGRAM,0);  /*create a socket */
bind(fd,&sock,sizeof(sock.sun_family)+1+strlen(sokname))
				  /*binding tjhe socket */
icotl(fd,FIOASYNC,(char*)&fioasync) /* setting flag for async I/O */
icotl(fd,SIOCSPGRP,(char*)&pid)     /* set process group pid for signal  */
signal(SIGIO,sig_handler)
sigpause(SIGIO)
.
.
/* END SERVER */




/*  CLIENT */
struct sockaddr_un sock;
fd=socket(AF_UNIX,SOCK_DGRAM,0);  /*create a socket */
bind(fd,&sock,sizeof(sock.sun_family)+1+strlen(sokname))
				  /*binding the socket */
icotl(fd,FIOASYNC,(char*)&fioasync) /* setting flag for async I/O */
icotl(fd,SIOCSPGRP,(char*)&pid)     /* set process group pid for signal  */
signal(SIGIO,sig_handler)
.
.
sendto(fd,...)               /*sendto SERVER */
.
.
.
sigpause(SIGIO)
.
/* END CLIENT */


sig_handler() performs recvfrom for the CLIENT  and
	      recvfrom & sendto for the SERVER.


We would like to hear from people who have had similar experiance
or success!!
-- 
Regards

pau      ( pau@stl.stc.co.uk +44-279-29531 )

edw@ius1.cs.cmu.edu (Eddie Wyatt) (09/13/87)

> /*  SERVER */
> struct sockaddr_un sock;
> fd=socket(AF_UNIX,SOCK_DGRAM,0);  /*create a socket */
> bind(fd,&sock,sizeof(sock.sun_family)+1+strlen(sokname))
> 				  /*binding tjhe socket */
> icotl(fd,FIOASYNC,(char*)&fioasync) /* setting flag for async I/O */
> icotl(fd,SIOCSPGRP,(char*)&pid)     /* set process group pid for signal  */
			    ^^^^

    int pgrp = -getpid();


    (void) signal(_WHICH_INTERRUPT,urgent_message_processor);
    (void) ioctl(port,SIOCSPGRP, (char *) &pgrp);


> signal(SIGIO,sig_handler)
> sigpause(SIGIO)
> .
> .
> /* END SERVER */
> 
> 
> 
> 
> /*  CLIENT */
> struct sockaddr_un sock;
> fd=socket(AF_UNIX,SOCK_DGRAM,0);  /*create a socket */
> bind(fd,&sock,sizeof(sock.sun_family)+1+strlen(sokname))
> 				  /*binding the socket */
> icotl(fd,FIOASYNC,(char*)&fioasync) /* setting flag for async I/O */
> icotl(fd,SIOCSPGRP,(char*)&pid)     /* set process group pid for signal  */
			     ^^^
			Same here.

> signal(SIGIO,sig_handler)
> .
> .
> sendto(fd,...)               /*sendto SERVER */
> .
> .
> .
> sigpause(SIGIO)
> .
> /* END CLIENT */
> 
> 
> sig_handler() performs recvfrom for the CLIENT  and
> 	      recvfrom & sendto for the SERVER.


				Eddie Wyatt
-- 

					Eddie Wyatt

e-mail: edw@ius1.cs.cmu.edu

chris@mimsy.UUCP (Chris Torek) (09/15/87)

In article <1041@ius1.cs.cmu.edu> edw@ius1.cs.cmu.edu (Eddie Wyatt) writes:
>>ioctl(fd,SIOCSPGRP,(char*)&pid)     /* set process group pid for signal  */
>			    ^^^^
>    int pgrp = -getpid();
>    (void) ioctl(port,SIOCSPGRP, (char *) &pgrp);

Careful; the semantics were reversed in the change from 4.2BSD to
4.3BSD.  (I had nothing to do with this!)  See your socket(2) and
fcntl(2) manuals for details.  I think -getpid() => pgrp on 4.3BSD,
and -getpid() => pid on 4.2BSD.
-- 
In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 7690)
Domain:	chris@mimsy.umd.edu	Path:	uunet!mimsy!chris