©2004 by Marc J. Rochkind. All rights reserved. Portions marked "Open Source" may be copied under license.

 

Main Page   Modules   Namespace List   Class Hierarchy   Compound List   File List   Namespace Members   Compound Members   File Members  

c6/pcsync.c

Go to the documentation of this file.
00001 /*
00002     Synchronize processes with pipe
00003     AUP2, Sec. 6.02, 9.02.3 (not in book)
00004 
00005     Copyright 2003 by Marc J. Rochkind. All rights reserved.
00006     May be copied only for purposes and under conditions described
00007     on the Web page www.basepath.com/aup/copyright.htm.
00008 
00009     The Example Files are provided "as is," without any warranty;
00010     without even the implied warranty of merchantability or fitness
00011     for a particular purpose. The author and his publisher are not
00012     responsible for any damages, direct or incidental, resulting
00013     from the use or non-use of these Example Files.
00014 
00015     The Example Files may contain defects, and some contain deliberate
00016     coding mistakes that were included for educational reasons.
00017     You are responsible for determining if and how the Example Files
00018     are to be used.
00019 
00020 */
00021 #include "defs.h"
00022 #include "pcsync.h"
00023 
00024 bool pcsync_init(struct pcsync *p)
00025 {
00026     ec_neg1( pipe(p->fdpc) )
00027     ec_neg1( pipe(p->fdcp) )
00028     return true;
00029 
00030 EC_CLEANUP_BGN
00031     return false;
00032 EC_CLEANUP_END
00033 }
00034 
00035 bool pcsync_wait_for_parent(struct pcsync *p)
00036 {
00037     fd_set fdset;
00038 #if 1
00039     ec_neg1( write(p->fdcp[1], "x", 1) )
00040     FD_ZERO(&fdset);
00041     FD_SET(p->fdpc[0], &fdset);
00042     ec_neg1( select(FD_SETSIZE, &fdset, NULL, NULL, NULL) )
00043 #else
00044 #endif
00045     return true;
00046 
00047 EC_CLEANUP_BGN
00048     return false;
00049 EC_CLEANUP_END
00050 }
00051 
00052 bool pcsync_unblock_children(struct pcsync *p, int children,
00053   pid_t *pid_child)
00054 {
00055     int n;
00056     char c;
00057 
00058 #if 1
00059     for (n = 0; n < children; n++)
00060         switch (read(p->fdcp[0], &c, 1)) {
00061         case 0: /* impossible */
00062             errno = 0;
00063             /* fall through */
00064         case -1:
00065             EC_FAIL
00066         }
00067     ec_neg1( write(p->fdpc[1], "x", 1) )
00068 #endif
00069     return true;
00070 
00071 EC_CLEANUP_BGN
00072     return false;
00073 EC_CLEANUP_END
00074 }
00075 
00076 bool pcsync_end(struct pcsync *p)
00077 {
00078     (void)close(p->fdpc[0]);
00079     (void)close(p->fdpc[1]);
00080     (void)close(p->fdcp[0]);
00081     (void)close(p->fdcp[1]);
00082     return true;
00083 }
00084 

Generated on Fri Apr 23 10:56:57 2004 for AUP2 Example Source by doxygen 1.3.1