diff --git a/src/client/libdistren.c b/src/client/libdistren.c --- a/src/client/libdistren.c +++ b/src/client/libdistren.c @@ -22,31 +22,27 @@ */ #include "common/config.h" +#include "common/options.h" +#include "common/remoteio.h" #include "libdistren.h" #include #include +#include -/** - @todo needs to read configuration in - */ -int distren_init_mf(distren_t *handle, distren_malloc_t mymalloc, distren_free_t myfree) +int distren_init(distren_t *handle) { - if(!handle - || !mymalloc - || !myfree) - { - fprintf(stderr, "distren_init_mf passed NULL pointers\n"); - return 1; - } + int tmp; - *handle = (*mymalloc)(sizeof(struct distren)); + if(!handle) + return 1; + + *handle = malloc(sizeof(struct distren)); if(!*handle) return 1; - (*handle)->malloc = mymalloc; - (*handle)->free = myfree; + memset(*handle, 0, sizeof(struct distren)); /* now the environment is ready for general use */ if(_distren_getoptions(*handle)) @@ -55,33 +51,41 @@ int distren_init_mf(distren_t *handle, d distren_free(*handle); return 1; } - - /** - @todo open a connection to the server now and return error if we can't - connect. - */ + + tmp = remoteio_open_server(&(*handle)->rem, + (*handle)->options->remoteio, + (remoteio_read_handle_func_t)&libdistren_remoteio_read_handle, + *handle, + (remoteio_close_handle_func_t)&libdistren_remoteio_close_handle, + (*handle)->server); + if(tmp) + { + fprintf(stderr, "error: unable to connect to server\n"); + + (*handle)->rem = NULL; + distren_free(*handle); + return 1; + } + + multiio_poll((*handle)->multiio, 2000); + multiio_poll((*handle)->multiio, 2000); + multiio_poll((*handle)->multiio, 2000); return 0; } -int distren_init(distren_t *handle) -{ - return distren_init_mf(handle, &malloc, &free); -} - /** - @todo Stub + * @todo Stub */ int distren_submit_file(distren_t handle, distren_job_t *job, const char *filename) { return 1; } -/** - - */ int distren_free(distren_t handle) { + if(handle->rem) + remoteio_close(handle->rem); free(handle); return 0; }