Exemple #1
0
/** main worker routine for all data reading. Returns 0 on success, -1 on error */
static int getdat(idc_handle_t fh, int ifsn, int nos, int** value, int dims_array[], int* ndims, int do_alloc)
{
        (void) isisds_type_size; // Avoid compiler warning
        (void) isisds_type_name; // Avoid compiler warning

	int stat, comm_buff_size;
	ISISDSDataType ret_type;
	int spec_nos[2] = { ifsn, nos };
	int spec_nos_dims[1] = { 2 };
	char* command = NULL;
	char comm_buffer[256];
	if (isisds_send_command(fh->s, "GETDAT", spec_nos, ISISDSInt32, spec_nos_dims, 1) <= 0)
	{
		IDCreport(0, 0, "error sending command (getdat)");
		return -1;
	};
        ret_type = ISISDSInt32;
	if (do_alloc)
	{
		stat = isisds_recv_command_alloc(fh->s, &command, (void**)value, &ret_type, dims_array, ndims);
	}
	else
	{
		comm_buff_size = sizeof(comm_buffer);
		stat = isisds_recv_command(fh->s, comm_buffer, &comm_buff_size, *value, &ret_type, dims_array, ndims);
	}
	if (stat <= 0)
	{
		IDCreport(0, 0, "error reading command (getdat)");
		return -1;
	}
	if (ret_type != ISISDSInt32)
	{
		IDCreport(0, 0, "invalid return type command (getdat)");
		return -1;
	}
/*	IDCreport(0, 0, "type %s\n", isisds_type_name[ret_type]); */
	return 0;
}
Exemple #2
0
///Get a parameter
static int IDCgetpar(idc_handle_t fh, const char* name, void** value, ISISDSDataType type,
					 int dims_array[], int* ndims, int do_alloc)
{
	int n, stat, comm_buff_size;
	ISISDSDataType ret_type;
	char* command = NULL;
	char comm_buffer[256];
	sprintf(comm_buffer, "GETPAR%s", isisds_type_code[type]);
	n = static_cast<int>(strlen(name));
	if (isisds_send_command(fh->s, comm_buffer, name, ISISDSChar, &n, 1) <= 0)
	{
		IDCreport(0, 0, "error sending command %s (getpar)", name);
		return -1;
	};
	ret_type = type;
	if (do_alloc)
	{
		stat = isisds_recv_command_alloc(fh->s, &command, value, &ret_type, dims_array, ndims);
	}
	else
	{
		comm_buff_size = sizeof(comm_buffer);
		stat = isisds_recv_command(fh->s, comm_buffer, &comm_buff_size, *value, &ret_type, dims_array, ndims);
	}
	if (stat <= 0)
	{
		IDCreport(0, 0, "error receiving command %s (getpar)", name);
		return -1;
	}
/*	IDCreport(0, 0, "type %s\n", isisds_type_name[ret_type]); */
	if (ret_type != type)
	{
	    return -1;
	}
	return 0;
}
Exemple #3
0
/*
 * client: open a socket and perform initial negotiation
 * return connected socket or INVALID_SOCKET on error
 */
SOCKET isisds_send_open(const char *host, ISISDSAccessMode access_type,
                        uint16_t port) {
  SOCKET s;
  int setkeepalive = 1;
  struct hostent *hostp;
  struct sockaddr_in address;
  char *comm, *comm_data;
  /*	int len_comm_data; */
  isisds_open_t op;
  ISISDSDataType data_type;
  int dims_array[10], ndims;

  if ((hostp = gethostbyname(host)) == NULL) {
    return INVALID_SOCKET;
  }
  memset(&address, 0, sizeof(address));
  memcpy(&(address.sin_addr.s_addr), hostp->h_addr_list[0], hostp->h_length);
  address.sin_family = AF_INET;

  address.sin_port = htons(port);
  s = socket(PF_INET, SOCK_STREAM, 0);
  if (s == INVALID_SOCKET) {
    return INVALID_SOCKET;
  }
  setsockopt(s, SOL_SOCKET, SO_KEEPALIVE, (char *)&setkeepalive,
             sizeof(setkeepalive));
  if (connect(s, (struct sockaddr *)&address, sizeof(address)) == -1) {
    closesocket(s);
    return INVALID_SOCKET;
  }

  /* socket connected */
  op.ver_major = ISISDS_MAJOR_VER;
  op.ver_minor = ISISDS_MINOR_VER;
  op.pid = 0;
  op.pad[0] = 0;
  op.access_type = access_type;
  strncpy(op.user, "faa", sizeof(op.user));
  strncpy(op.host, "localhost", sizeof(op.host));
  op.len = sizeof(op);
  if ((send(s, (char *)&op, sizeof(op), 0)) != sizeof(op)) {
    closesocket(s);
    return INVALID_SOCKET;
  }
  comm = NULL;
  if (isisds_recv_command_alloc(s, &comm, (void **)&comm_data, &data_type,
                                dims_array, &ndims) <= 0) {
    closesocket(s);
    free(comm);
    return INVALID_SOCKET;
  }
  if (comm_data != NULL) {
    free(comm_data);
  }
  if (!strcmp(comm, "OK")) {
    free(comm);
    return s;
  } else {
    free(comm);
    closesocket(s);
    return INVALID_SOCKET;
  }
}