7 #define ISISDS_MAJOR_VER 1
8 #define ISISDS_MINOR_VER 1
11 #define closesocket close
15 #include <sys/socket.h>
17 #include <netinet/in.h>
18 #include <arpa/inet.h>
55 n = recv(s, buffer, len, flags);
70 static char buffer[100000];
71 struct timeval timeout = { 0, 0 };
78 if ( (select(FD_SETSIZE, &fds, NULL, NULL, &timeout) > 0) && FD_ISSET(s, &fds) )
80 recv(s, buffer,
sizeof(buffer), 0);
95 struct hostent *hostp;
96 struct sockaddr_in address;
98 char *comm, *comm_data;
102 int dims_array[10], ndims;
104 if ( (hostp = gethostbyname(host)) == NULL )
108 memset(&address, 0,
sizeof(address));
109 memcpy(&(address.sin_addr.s_addr), hostp->h_addr_list[0], hostp->h_length);
110 address.sin_family = AF_INET;
112 s = socket(PF_INET, SOCK_STREAM, 0);
117 setsockopt(s, SOL_SOCKET, SO_KEEPALIVE, (
char*)&setkeepalive,
sizeof(setkeepalive));
118 if (connect(s, (
struct sockaddr*)&address,
sizeof(address)) == -1)
128 strncpy(op.
user,
"faa",
sizeof(op.
user));
129 strncpy(op.
host,
"localhost",
sizeof(op.
host));
131 if ( (n = send(s, (
char*)&op,
sizeof(op), 0)) !=
sizeof(op) )
141 if (comm_data != NULL)
145 if (!strcmp(comm,
"OK"))
164 if ( (n =
recv_all(s, (
char*)&op,
sizeof(op), 0)) !=
sizeof(op) )
168 if ( op.
len !=
sizeof(op) )
189 memset(&comm, 0,
sizeof(comm));
190 if (dims_array == NULL)
200 for(i=0; i<ndims; i++)
202 len_data *= dims_array[i];
207 comm.
len =
sizeof(comm) + len_data;
211 n = send(s, (
char*)&comm,
sizeof(comm), 0);
212 if ( (n ==
sizeof(comm)) && (data != NULL) && (len_data > 0) )
214 n = send(s, data, len_data, 0);
222 int n, len_data, size_in, i;
224 n =
recv_all(s, (
char*)&comm,
sizeof(comm), 0);
225 if (n !=
sizeof(comm))
229 *command = (
char*)malloc(
sizeof(comm.
command) + 1);
231 (*command)[
sizeof(comm.
command)] =
'\0';
232 len_data = comm.
len -
sizeof(comm);
237 else if (len_data == 0)
247 *data = malloc(len_data + 1);
248 ((
char*)(*data))[len_data] =
'\0';
253 for(i=0; i < *ndims; i++)
255 size_in *= dims_array[i];
258 if (size_in < len_data)
262 if (size_in > len_data)
264 ((
char*)(*data))[len_data] =
'\0';
267 n =
recv_all(s, *data, len_data, 0);
276 if ( do_alloc || (*ndims != comm.
ndims) )
280 if ( do_alloc || (*type != comm.
type) )
284 for(i=0; i < comm.
ndims; i++)
294 int t_dims[8] = { 1, 0, 0, 0, 0, 0, 0, 0 };
297 char* command_temp = NULL;
302 if ( dims_array == NULL || ndims == NULL || (*ndims <= 1 && dims_array[0] <= 1) )
306 if ( (t_ndims != 1) || (t_dims[0] != 1) )
315 strncpy(command, command_temp, *len_command);
316 *len_command = strlen(command_temp);
324 if (ndims == NULL || dims_array == NULL || type == NULL)
328 if (data == NULL || command == NULL)
351 printf(
"ISISDS: %d %d %s\n", status, code, message);
359 char* message = (
char*)malloc(1024);
360 va_start(ap, format);
361 vsprintf(message, format, ap);
363 (*status_reporter)(status, code, message);
static void clear_replies(SOCKET s)
static int isisds_recv_command_helper(SOCKET s, char **command, void **data, ISISDSDataType *type, int dims_array[], int *ndims, int do_alloc)
static isisds_error_report_t status_reporter
int isisds_report(int status, int code, const char *format,...)
int isisds_send_command(SOCKET s, const char *command, const void *data, ISISDSDataType type, const int dims_array[], int ndims)
int isisds_recv_command(SOCKET s, char *command, int *len_command, void *data, ISISDSDataType *type, int dims_array[], int *ndims)
static void default_status_reporter(int status, int code, const char *message)
void(* isisds_error_report_t)(int status, int code, const char *messsage)
int isisds_send_close(SOCKET s)
int isisds_set_report_func(isisds_error_report_t report_func)
static const char * isisds_type_name[]
static int isisds_type_size[]
int isisds_recv_open(SOCKET s, ISISDSAccessMode *access_type)
SOCKET isisds_send_open(const char *host, ISISDSAccessMode access_type)
static int recv_all(SOCKET s, char *buffer, int len, int flags)
int isisds_recv_command_alloc(SOCKET s, char **command, void **data, ISISDSDataType *type, int dims_array[], int *ndims)