#include #include "test.h" #include "tests.h" typedef struct priv PRIV; struct priv { int lfd; int cfd; } ; static void run_l_c_cc_cl_run_l(void *pv) { PRIV *p; pid_t mypid; int fd; char c; p = pv; mypid = getpid(); printf("l-c-cc-cl: listener is %d\n",(int)mypid); printf("l-c-cc-cl: listener doing PIDCONN_LISTEN\n"); sleep(1); SET_PIDCONN(fd,PIDCONN_LISTEN,0,0); mustwrite(p->lfd,"",1); mustread(p->lfd,&c,1); sleep(1); printf("l-c-cc-cl: listener sending PID to connecter\n"); sleep(1); mustwrite(p->lfd,&mypid,sizeof(pid_t)); sleep(1); printf("l-c-cc-cl: listener reading response\n"); sleep(1); mustread(p->lfd,&c,1); sleep(1); printf("l-c-cc-cl: listener closing\n"); sleep(1); close(fd); sleep(1); printf("l-c-cc-cl: listener writing interlock to connecter\n"); sleep(1); mustwrite(p->lfd,"",1); sleep(1); printf("l-c-cc-cl: listener done\n"); } static void run_l_c_cc_cl_run_c(void *pv) { PRIV *p; pid_t lpid; int fd; char c; p = pv; printf("l-c-cc-cl: connecter is %d\n",(int)getpid()); mustread(p->cfd,&c,1); mustwrite(p->cfd,"",1); printf("l-c-cc-cl: connecter reading PID from listener\n"); sleep(1); mustread(p->cfd,&lpid,sizeof(pid_t)); sleep(1); printf("l-c-cc-cl: connecter doing PIDCONN_CONNECT to %d\n",(int)lpid); sleep(1); SET_PIDCONN(fd,PIDCONN_CONNECT,0,lpid); sleep(1); printf("l-c-cc-cl: connecter closing\n"); sleep(1); close(fd); sleep(1); printf("l-c-cc-cl: connecter writing interlock to listener\n"); sleep(1); mustwrite(p->cfd,"",1); sleep(1); printf("l-c-cc-cl: connecter reading interlock from listener\n"); sleep(1); mustread(p->cfd,&c,1); sleep(1); printf("l-c-cc-cl: connecter done\n"); } static void run_l_c_cc_cl(void) { PRIV p; KID *kl; KID *kc; local_socketpair(&p.lfd,&p.cfd); kl = fork_kid(&run_l_c_cc_cl_run_l,&p); kc = fork_kid(&run_l_c_cc_cl_run_c,&p); close(p.lfd); close(p.cfd); reap_kid(kl); reap_kid(kc); printf("l-c-cc-cl: done\n"); } const TEST test_l_c_cc_cl = { &run_l_c_cc_cl };