示例#1
0
/*****************************************************************************
 *  Periodic handler to send RPC messages.
 *****************************************************************************/
static int
periodic_event(INKCont contp, INKEvent event, void *e)
{
    /*************************************************************************
     *  Note: Event subsystem always calls us with 'node_status_mutex' held.
     *************************************************************************/
  int n, size, ret;

  INKClusterRPCMsg_t *rmsg;
  hello_msg_t hello_msg;
  struct in_addr in;

  if (clusterRPC_plugin_shutdown) {
    shutdown();
    INKContDestroy(contp);
    return 0;
  }
    /*************************************************************************
     *  Send a hello message to all online nodes.
     *************************************************************************/
  for (n = 1; n <= MAX_CLUSTER_NODES; ++n) {
    if (nodes[n]) {
      INKNodeHandleToIPAddr(&nodes[n], &in);

      hello_msg.hm_version = HELLO_MSG_VERSION;
      hello_msg.hm_source_handle = my_node_handle;
      hello_msg.hm_dest_handle = nodes[n];
      hello_msg.hm_instance = msg_instance++;

      size = random() % (1 * 1024 * 1024);
      if (size < sizeof(hello_msg_t)) {
        size = sizeof(hello_msg_t);
      }
      rmsg = INKAllocClusterRPCMsg(&rpc_wireless_f10_handle, size);
      hello_msg.hm_data_size = size;
            /******************************************************************
 	     *  Marshal data into message.
	     *****************************************************************/
      memcpy(rmsg->m_data, (char *) &hello_msg, sizeof(hello_msg));
      fill_data(rmsg->m_data +
                sizeof(hello_msg) - sizeof(hello_msg.hm_data_size),
                size - sizeof(hello_msg) + sizeof(hello_msg.hm_data));

      INKDebug(PLUGIN_DEBUG_TAG,
               "Sending hello to [%u.%u.%u.%u] instance %d bytes %d\n",
               DOT_SEPARATED(in.s_addr), hello_msg.hm_instance, size);

      ret = INKSendClusterRPC(&nodes[n], rmsg);
      if (ret) {
        INKDebug(PLUGIN_DEBUG_ERR_TAG, "INKSendClusterRPC failed\n");
      }
    }
  }
  periodic_event_action = INKContSchedule(periodic_event_cont, (1 * 1000) /* 1 sec */ );
  return 0;
}
示例#2
0
static void
clusterRPC_init()
{
  int ret;

    /***********************************************************************
     *  Create plugin mutex
     ***********************************************************************/
  node_status_mutex = INKMutexCreate();
  if (!node_status_mutex) {
    INKDebug(PLUGIN_DEBUG_ERR_TAG, "INKMutexCreate for node_status failed\n");
    return;
  }
  if (!INKMutexTryLock(node_status_mutex)) {
    /* Should never fail */
    INKDebug(PLUGIN_DEBUG_ERR_TAG, "INKMutexTryLock failed\n");
  }
    /***********************************************************************
     *  Register our RPC handler.
     ***********************************************************************/
  ret = INKAddClusterRPCFunction(RPC_API_WIRELESS_F10, rpc_wireless_f10_func, &rpc_wireless_f10_handle);
  if (ret) {
    INKDebug(PLUGIN_DEBUG_ERR_TAG, "INKAddClusterRPCFunction failed\n");
    return;
  }
    /***********************************************************************
     *  Subscribe to cluster node status callouts.
     ***********************************************************************/
  ret = INKAddClusterStatusFunction(status_callout, node_status_mutex, &status_callout_handle);
  if (ret) {
    INKDebug(PLUGIN_DEBUG_ERR_TAG, "INKAddClusterStatusFunction failed\n");
    return;
  }
    /***********************************************************************
     *  Perform node status initializations.
     ***********************************************************************/
  INKGetMyNodeHandle(&my_node_handle);

    /***********************************************************************
     *  Enable cluster node status callouts.
     ***********************************************************************/
  INKEnableClusterStatusCallout(&status_callout_handle);

    /***********************************************************************
     *  Establish the periodic event.
     ***********************************************************************/
  periodic_event_cont = INKContCreate(periodic_event, node_status_mutex);
  if (!periodic_event_cont) {
    INKDebug(PLUGIN_DEBUG_ERR_TAG, "INKContCreate for periodic_event failed\n");
    return;
  }
  periodic_event_action = INKContSchedule(periodic_event_cont, (1 * 1000) /* 1 sec */ );
  INKMutexUnlock(node_status_mutex);
}
示例#3
0
/* Verification code for: INKqa06643 */
static int
EventHandler(INKCont contp, INKEvent event, void *eData)
{
  INKHttpTxn txn = (INKHttpTxn) eData;
  int iVal;
  time_t tVal;

  if (time(&tVal) != (time_t) (-1)) {
    INKDebug("tag_sched6643", "INKContSchedule: EventHandler: called at %s\n", ctime(&tVal));
  }

  iVal = (int) INKContDataGet(contp);

  INKDebug("tag_sched6643", "INKContSchedule: handler called with value %d\n", iVal);

  switch (event) {

  case INK_EVENT_HTTP_OS_DNS:
    INKDebug("tag_sched6643", "INKContSchedule: Seed event %s\n", "INK_EVENT_HTTP_OS_DNS");
    break;

  case INK_EVENT_TIMEOUT:
    INKDebug("tag_sched6643", "INKContSchedule: TIMEOUT event\n");
    break;

  default:
    INKDebug("tag_sched6643", "INKContSchedule: Error: default event\n");
    break;
  }

  iVal += 100;                  /* seed + timeout val */
  INKContDataSet(contp, (void *) iVal);
  INKContSchedule(contp, iVal);

  /* INKHttpTxnReenable(txn, INK_EVENT_HTTP_CONTINUE); */
}