示例#1
0
static IDL_VPTR IDL_CDECL IDL_mg_fdtr(int argc, IDL_VPTR *argv) {
  double a, b, x;
  a = IDL_DoubleScalar(argv[0]);
  b = IDL_DoubleScalar(argv[1]);
  x = IDL_DoubleScalar(argv[2]);
  return IDL_GettmpDouble(cephes_fdtr(a, b, x));
}
示例#2
0
文件: mg_net.c 项目: jiezhou87/mglib
/*
  out = MG_NET_SELECT(sockets[], timeout)

  Checks to see if there is data waiting to be read or a connection has been
  requested for a list of sockets. The return value is -1 on error, scalar 0
  if no sockets are ready or returns a list of the sockets which are ready.
  The routine waits the number of seconds specified by the timeout argument
  for sockets to become ready. A timeout value of 0 results in a poll of the
  sockets.
*/
static IDL_VPTR IDL_CDECL mg_net_select(int argc, IDL_VPTR argv[], char *argk) {
  struct timeval timeval;
  fd_set rfds;

  IDL_LONG i, j;
  IDL_LONG n, num;

  float	fWait;
  IDL_LONG *piSocks,iNum;
  IDL_VPTR vpSocks;

  vpSocks = IDL_CvtLng(1, &(argv[0]));
  IDL_VarGetData(vpSocks, &iNum, (char **) &piSocks, 1);
  fWait = (float) IDL_DoubleScalar(argv[1]);

  num = -1;
  FD_ZERO(&rfds);

  for (j = 0; j < iNum; j++) {
    i = piSocks[j];
    if ((i < 0) || (i >= MAX_SOCKETS)) {
      if (vpSocks != argv[0]) IDL_Deltmp(vpSocks);
      return (IDL_GettmpLong(-1));
    }
    if (net_list[i].iState != NET_UNUSED) {
      FD_SET(net_list[i].socket, &rfds);
      if (net_list[i].socket > (SOCKET) num) num = net_list[i].socket;
    }
  }
  while (fWait >= 0.0) {
    if (fWait >= 2.0) {
      timeval.tv_sec = 2;
      timeval.tv_usec = 0;
    } else {
      timeval.tv_sec = (long) fWait;
      fWait = fWait - timeval.tv_sec;
      timeval.tv_usec = (long) (fWait * 1000000);
    }
    n = select(num + 1, &rfds, NULL, NULL, &timeval);
    if (n == -1) fWait = -1.0;
    if (n > 0) fWait = -1.0;
    fWait -= 2.0;
    if (IDL_BailOut(IDL_FALSE)) {
      n = -1;
      fWait = -1.0;
    }
  }

  if (n > 0) {
    IDL_LONG *pOut;
    IDL_VPTR vpTmp;

    pOut = (IDL_LONG *) IDL_MakeTempVector(IDL_TYP_LONG,
					   n, IDL_ARR_INI_NOP, &vpTmp);
    for (j = 0; j < iNum; j++) {
      i = piSocks[j];
      if (net_list[i].iState != NET_UNUSED) {
	if (FD_ISSET(net_list[i].socket, &rfds)){
	  *pOut++ = i;
	}
      }
    }
    if (vpSocks != argv[0]) IDL_Deltmp(vpSocks);
    return (vpTmp);
  }

  if (vpSocks != argv[0]) IDL_Deltmp(vpSocks);

  return (IDL_GettmpLong(n));
}