free(ctx);
}
-canl_io_handler canl_create_io_handler(canl_ctx cc)
+int canl_create_io_handler(canl_ctx cc, canl_io_handler *io)
{
io_handler *new_io_h = NULL;
glb_ctx *g_cc = cc;
int err = 0;
- if (!g_cc)
- return NULL;
+ if (!g_cc || io == NULL)
+ return EINVAL;
/*create io handler*/
new_io_h = (io_handler *) calloc(1, sizeof(*new_io_h));
- if (!new_io_h){
- set_error(g_cc, ENOMEM, posix_error, "Not enough memory ");
- return NULL;
- }
+ if (!new_io_h)
+ return set_error(g_cc, ENOMEM, posix_error, "Not enough memory");
/* allocate memory and initialize io content*/
if ((err = init_io_content(g_cc ,new_io_h))){
- goto end;
+ free(new_io_h);
+ return err;
}
-end:
- if (err) {
- update_error(g_cc,"cannot create canl_io_handler");
- if ((err = canl_io_destroy(cc, (canl_io_handler)new_io_h)))
- update_error(g_cc, "cannot destroy canl_ctx");
- new_io_h = NULL;
- }
- return new_io_h;
+ *io = new_io_h;
+ return 0;
}
static int init_io_content(glb_ctx *cc, io_handler *io)
canl_ctx canl_create_ctx();
void canl_free_ctx(canl_ctx cc);
-canl_io_handler canl_create_io_handler(canl_ctx cc);
+int canl_create_io_handler(canl_ctx, canl_io_handler*);
int canl_io_connect(canl_ctx cc, canl_io_handler io, const char *host, const char *service,
int port, gss_OID_set auth_mechs, int flags, struct timeval *timeout);
goto end;
}
- my_io_h = canl_create_io_handler(my_ctx);
- if (!my_io_h) {
+ err = canl_create_io_handler(my_ctx, &my_io_h);
+ if (err) {
printf("io handler cannot be created: %s\n",
canl_get_error_message(my_ctx));
goto end;
timeout.tv_sec = 150;
timeout.tv_usec = 0;
- err = canl_io_connect(my_ctx, my_io_h, p_server, port, 0, NULL, &timeout);
+ err = canl_io_connect(my_ctx, my_io_h, p_server, NULL, port, NULL, 0, &timeout);
if (err) {
printf("[CLIENT] connection to %s cannot be established: %s\n",
p_server, canl_get_error_message(my_ctx));
{
canl_ctx my_ctx;
canl_io_handler my_io_h = NULL;
- canl_io_handler my_new_io_h;
int err = 0;
int opt, port = 4321;
char *serv_cert = NULL;
return -1;
}
- my_io_h = canl_create_io_handler(my_ctx);
- if (!my_io_h) {
- printf("[SERVER] io handler cannot be created: %s\n",
- canl_get_error_message(my_ctx));
- goto end;
- }
-
- my_new_io_h = canl_create_io_handler(my_ctx);
- if (!my_new_io_h) {
+ err = canl_create_io_handler(my_ctx, &my_io_h);
+ if (err) {
printf("[SERVER] io handler cannot be created: %s\n",
canl_get_error_message(my_ctx));
goto end;