4 * Copyright (C) 2009 Adam Williams <broadcast at earthling dot net>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 #ifndef __FORKBASE_H__
23 #define __FORKBASE_H__
25 #include "forkbase.inc"
29 // Utility functions for all the forking classes
33 class ForkBase : public Mutex
36 enum { EXIT_CODE=0x7fff };
37 typedef struct { int64_t token; int bytes; } token_bfr_t;
42 virtual int is_running() = 0;
43 void send_bfr(int fd, const void *bfr, int len);
44 int read_timeout(int64_t usec, int fd, void *data, int bytes);
46 int read_parent(int64_t usec);
47 int send_parent(int64_t value, const void *data, int bytes);
48 int read_child(int64_t usec);
49 int send_child(int64_t value, const void *data, int bytes);
68 class ForkChild : public ForkBase
73 virtual int child_iteration(int64_t usec) = 0;
78 class ForkParent : public Thread, public ForkBase
82 virtual ~ForkParent();
83 virtual int handle_parent();
84 virtual ForkChild *new_fork() = 0;
91 int parent_iteration();