Esempio n. 1
0
File: ggsock.c Progetto: INNOAUS/gsl
MODULE reply_connect_ok_result (THREAD *thread)
{
    struct_smtsock_connect_ok
        *connect_reply;
    SOCK_HANDLE_ITEM
        *socket;
    char
        *error_text;

    tcb = thread-> tcb;                 /*  Point to thread's context        */

    get_smtsock_connect_ok (thread-> event-> body, & connect_reply);

    socket = memt_alloc (NULL, sizeof (SOCK_HANDLE_ITEM));
    socket-> links     = 0;
    socket-> handle    = connect_reply-> socket;
    socket-> error_msg = NULL;

    assign_pointer (& tcb-> result-> value, & sock_handle_class, socket);

    free_smtsock_connect_ok (& connect_reply);

    if (store_module_error (tcb-> gsl_thread,
                            tcb-> context,
                            tcb-> error,
                            NULL,
                            &error_text))
        lsend_ggcode_call_error (& tcb-> gsl_thread-> queue-> qid, NULL,
                                 NULL, NULL, NULL, 0,
                                 NULL, 0,
                                 error_text);
    else
        lsend_ggcode_call_ok (& tcb-> gsl_thread-> queue-> qid, NULL,
                              NULL, NULL, NULL, 0);
}
Esempio n. 2
0
File: ggsock.c Progetto: INNOAUS/gsl
MODULE reply_ok_result (THREAD *thread)
{
    SOCK_HANDLE_ITEM
        *socket;
    char
        *error_text;
    int
        rc;

    tcb = thread-> tcb;                 /*  Point to thread's context        */

    /*  We rely here on tcb-> handle being the master socket for an accept   */
    /*  and zero for any other request.                                      */
    if (tcb-> handle)
      {
        socket = memt_alloc (NULL, sizeof (SOCK_HANDLE_ITEM));
        socket-> links     = 0;
        socket-> handle    = accept_socket (tcb-> handle);
        socket-> error_msg = NULL;

        assign_pointer (& tcb-> result-> value, & sock_handle_class, socket);
      }

    if (tcb-> sock_handle)
        rc = store_sock_error (tcb-> sock_handle,
                               tcb-> gsl_thread,
                               tcb-> context,
                               tcb-> error,
                               NULL,
                               &error_text);
    else
        rc = store_module_error (tcb-> gsl_thread,
                                 tcb-> context,
                                 tcb-> error,
                                 NULL,
                                 &error_text);

    if (rc)
        lsend_ggcode_call_error (& tcb-> gsl_thread-> queue-> qid, NULL,
                                 NULL, NULL, NULL, 0,
                                 NULL, 0,
                                 error_text);
    else
        lsend_ggcode_call_ok (& tcb-> gsl_thread-> queue-> qid, NULL,
                              NULL, NULL, NULL, 0);
}
Esempio n. 3
0
File: ggsock.c Progetto: INNOAUS/gsl
static int
sock_passive (int argc, RESULT_NODE **argv, void *item, RESULT_NODE *result, THREAD *gsl_thread)
{
    RESULT_NODE *service = argc > 0 ? argv [0] : NULL;
    RESULT_NODE *error   = argc > 1 ? argv [1] : NULL;

    if (! service)
      {
        strcpy (object_error, "Missing argument: service");
        return -1;
      }
    if (service-> value. type == TYPE_UNDEFINED)
      {
        result-> culprit = service-> culprit;
        service-> culprit = NULL;
        return 0;
      }

  {
    SOCK_HANDLE_ITEM
        *socket;
    sock_t
        handle;
    SOCK_CONTEXT
        *context = item;
    const char
        *error_msg;
    char
        *error_text;

    if (start_socket_agent ())
        return -1;

    handle = passive_TCP (string_value (& service-> value),
                          QUEUE_LENGTH);
    if (handle != INVALID_SOCKET)       /*  Success  */
      {
        socket = memt_alloc (NULL, sizeof (SOCK_HANDLE_ITEM));
        socket-> links     = 0;
        socket-> handle    = handle;
        socket-> error_msg = NULL;

        assign_pointer (& result-> value, & sock_handle_class, socket);

        error_msg = NULL;
      }
    else
        error_msg = connect_errlist [connect_error ()];

    if (store_module_error (gsl_thread,
                            context,
                            error,
                            error_msg,
                            &error_text))

      {
        strncpy (object_error, error_text, LINE_MAX);
        return -1;
      }
    else
        return 0;
  }
        
    return 0;  /*  Just in case  */
}
Esempio n. 4
0
File: lorenz.c Progetto: Stray/CBofN
int main(int argc, char **argv)
{
  extern int plot_mag;
  extern int plot_inverse;
  int i, j, k;

  /* SSZ is the size of the buffers, while SI is the current index. */
  int ssz, si;

  /* Variables used to calculate the time evolution of the system. */
  double x, y, z;

  /* Buffers to store delay values of all three variables. */
  double *buffer[3];

  /* Pointers into the buffers that always refer to the current,
   * and once delayed values. 
   */
  double *delays[3][2];

  /* Pointers to the pointers that refer what is to be plotted. */
  double **ppx, **ppy;

  /* Variables used to compute auto-scaling. */
  double xmin, xmax, ymin, ymax;

  /* Values that are to be plotted. */
  double px, py, pxx = 0, pyy = 0, temp;

  get_options(argc, argv, options, help_string);

  /* Set up the pointers so that they refer to the proper values to
   * plot with respect to. */
  assign_pointer(&ppx, delays, xp);
  assign_pointer(&ppy, delays, yp);

  if(!data) {
    plot_mag = mag;
    plot_inverse = invert;
    plot_init(width, height, 2, term);
    plot_set_all(0);
  }
  
  /* Initialize the buffer space. */
  ssz = delta + 1;
  for(i = 0; i < 3; i++)
    buffer[i] = xmalloc(sizeof(double) * ssz);
  si = 0;

  /* Initialize the system. */
  x = xx0; y = yy0; z = zz0;

  /* Set insane minimum and maximum guesses. */
  xmin = ymin = 10e10;
  xmax = ymax = -10e10;

  /* For all points (plus the skip and delay values. */
  for(i = 0; i < points + skip + ssz; i++) {

    /* Compute the time evolution of the system. */
    euler(dt, &x, &y, &z);

    /* Save the state so that we can remember delayed values. */
    buffer[0][si] = x; buffer[1][si] = y; buffer[2][si] = z;

    /* For each state value ... , and for each delay value ... */
    for(j = 0; j < 3; j++)
      for(k = 0; k < 2; k++)
        /* Adjust the pointers to refer to the proper delays. */
        delays[j][k] = &buffer[j][(si + ssz - k * delta) % ssz];

    si = (si + 1) % ssz;

    if(data) {
      if(i >= skip + ssz)
        printf("%f\t%f\t%f\n", x, y, z);
    }
    else {
      /* Get the point that we want to plot. */
      px = **ppx; py = **ppy;

      /* If we are still skipping points, adjust the best guesses for
       * the minimum and maximums.
       */
      if(i <= skip + ssz) {
        xmin = (px < xmin) ? px : xmin; xmax = (px > xmax) ? px : xmax;
        ymin = (py < ymin) ? py : ymin; ymax = (py > ymax) ? py : ymax;
      }
      
      /* If this is the last point to be skipped, reset the plotting
       * range based on the minimum and maximums.
       */
      if(i == skip + ssz) {
        temp = (xmax - xmin) * factor; xmin -= temp; xmax += temp;
        temp = (ymax - ymin) * factor; ymin -= temp; ymax += temp;
        plot_set_range(xmin, xmax, ymin, ymax);
      }

      /* Plot a line from the last point to the current point. */
      if(i >= skip + ssz)
        plot_line(pxx, pyy, px, py, 1);

      /* Save the last point. */
      pxx = px; pyy = py;
    }
  }

  if(!data) plot_finish();
  exit(0);
}