Пример #1
0
void
__indirect_glGetIntegerv(GLenum val, GLint * i)
{
   const GLenum origVal = val;
   __GLX_SINGLE_DECLARE_VARIABLES();
   xGLXSingleReply reply;

   val = RemapTransposeEnum(val);

   __GLX_SINGLE_LOAD_VARIABLES();
   __GLX_SINGLE_BEGIN(X_GLsop_GetIntegerv, 4);
   __GLX_SINGLE_PUT_LONG(0, val);
   __GLX_SINGLE_READ_XREPLY();
   __GLX_SINGLE_GET_SIZE(compsize);

   if (compsize == 0) {
      /*
       ** Error occured; don't modify user's buffer.
       */
   }
   else {
      GLintptr data;

      /*
       ** We still needed to send the request to the server in order to
       ** find out whether it was legal to make a query (it's illegal,
       ** for example, to call a query between glBegin() and glEnd()).
       */

      if (get_client_data(gc, val, &data)) {
         *i = (GLint) data;
      }
      else {
         /*
          ** Not a local value, so use what we got from the server.
          */
         if (compsize == 1) {
            __GLX_SINGLE_GET_LONG(i);
         }
         else {
            __GLX_SINGLE_GET_LONG_ARRAY(i, compsize);
            if (val != origVal) {
               /* matrix transpose */
               TransposeMatrixi(i);
            }
         }
      }
   }
   __GLX_SINGLE_END();
}
Пример #2
0
static int
accept_clients(int sd)
{
  int retcode = 0;                 /* function return value */
  int nsd;                         /* new socket descriptor for accept */
  struct sockaddr_in from_client;  /* socket address of connected client */
  unsigned int from_client_len;    /* size of socket address structure */
  struct client_data *from_info;   /* info for each connected client */
  pthread_t thread_id;
  pthread_attr_t thread_attr;

  pthread_attr_init(&thread_attr);
  pthread_attr_setdetachstate(&thread_attr, PTHREAD_CREATE_DETACHED);
  server_running = TRUE;
  /*
   * Repeatedly call accept to receive the next request from a client,
   * and create a new slave process to handle the response.
   */
  while (server_running == TRUE) {
    /*
     * Have we exceeded our limit of active threads? If so, wait for
     * an active thread to finish.
     */
    pthread_mutex_lock(&slave_thread_info.mutex);
    while (slave_thread_info.num_active == MAX_NUM_THREADS) {
      pthread_cond_wait(&slave_thread_info.thread_exit_cv, &slave_thread_info.mutex);
    } /* end while */
    slave_thread_info.num_active++;
    pthread_mutex_unlock(&slave_thread_info.mutex);

    /*
     * Accept creates a new connected socket and allocates
     * a new file descriptor for the new socket, which is
     * returned to nsd.
     */
    from_client_len = sizeof from_client;
    nsd = accept(sd, (struct sockaddr *)&from_client, &from_client_len);
    if (nsd < 0) {
      if (errno == EINTR) {
	continue;
      } /* end if */
      perror("ERROR: server accept() ");
      server_running = FALSE;
      retcode = 1;
    } else {
      from_info = (struct client_data *)malloc(sizeof(struct client_data));
      if (from_info == NULL) {
	fprintf(stderr, "ERROR: malloc\n");
	server_running = FALSE;
	retcode = 1;
      } else {
        from_info->sd = nsd;
	get_client_data(from_client, from_info);
	pthread_create(&thread_id, &thread_attr, slave_thread, from_info);
      } /* end if */
    } /* end if */
  } /* end while */

  pthread_attr_destroy(&thread_attr);

  return retcode;
} /* end of accept_client */