ppc_fork_child.c

00001 /*
00002  * Copyright (c) 2005-2012 by KoanLogic s.r.l. <http://www.koanlogic.com>
00003  * All rights reserved.
00004  *
00005  * This file is part of KLone, and as such it is subject to the license stated
00006  * in the LICENSE file which you have received as part of this distribution.
00007  *
00008  * $Id: ppc_fork_child.c,v 1.10 2007/11/09 22:06:26 tat Exp $
00009  */
00010 
00011 #include "klone_conf.h"
00012 #include <string.h>
00013 #include <klone/klog.h>
00014 #include <klone/context.h>
00015 #include <klone/server.h>
00016 #include <klone/backend.h>
00017 #include <klone/ppc.h>
00018 #include <klone/ppc_cmd.h>
00019 #include <klone/server_ppc_cmd.h>
00020 #include "server_s.h"
00021 
00022 /* struct used for ppc command PPC_CMD_NOP */
00023 struct ppc_fork_child_s
00024 {
00025     int bid; /* backend id */
00026 };
00027 
00028 typedef struct ppc_fork_child_s ppc_fork_child_t;
00029 
00030 /* client function */
00031 int server_ppc_cmd_fork_child(server_t *s, backend_t *be)
00032 {
00033     ppc_fork_child_t pfc;
00034 
00035     nop_err_if (s == NULL);
00036     nop_err_if (s->ppc == NULL);
00037     nop_err_if (be == NULL);
00038 
00039     memset(&pfc, 0, sizeof(ppc_fork_child_t));
00040 
00041     pfc.bid = be->id;
00042 
00043     /* send the command request */
00044     nop_err_if(ppc_write(s->ppc, ctx->pipc, PPC_CMD_FORK_CHILD, (char*)&pfc, 
00045         sizeof(ppc_fork_child_t)) < 0);
00046 
00047     return 0;
00048 err:
00049     return ~0;
00050 }
00051 
00052 /* [parent] */
00053 int server_ppc_cb_fork_child(ppc_t *ppc, int fd, unsigned char cmd, char *data, 
00054     size_t size, void *vso)
00055 {
00056     backend_t *be = NULL;
00057     ppc_fork_child_t *ppfc;
00058 
00059     u_unused_args(ppc, fd, cmd, size, vso);
00060 
00061     dbg_err_if (data == NULL);
00062 
00063     ppfc = (void *) data;
00064 
00065     dbg_err_if(server_get_backend_by_id(ctx->server, ppfc->bid, &be) || 
00066         be == NULL);
00067 
00068     u_dbg("[parent] ppc spawn child");
00069 
00070     /* try to fork now, if we can't (resource limit or max_child exceeded) 
00071        then try later */
00072     if(server_spawn_child(ctx->server, be))
00073         be->fork_child++; /* increase # of child to spawn when possible */
00074 
00075     return 0;
00076 err:
00077     return ~0;
00078 }
00079 

←Products
Copyright © 2005-2012 - KoanLogic S.r.l. - All rights reserved