# HG changeset patch # User Matti Hamalainen # Date 1455238997 -7200 # Node ID 0b81e5fdc7b5ec30aa88cda0e1bba1934b56c31f # Parent 0c94af18f55ec36e1a03f060e42940c5b145a4b5 Use the new io context API. diff -r 0c94af18f55e -r 0b81e5fdc7b5 main.c --- a/main.c Fri Feb 12 03:02:12 2016 +0200 +++ b/main.c Fri Feb 12 03:03:17 2016 +0200 @@ -612,7 +612,7 @@ } -void nn_ioctx_errfunc(th_ioctx_t *ctx, int err, const char *msg) +void nn_ioctx_errfunc(th_ioctx *ctx, const int err, const char *msg) { (void) err; errorMsg("[%s:%d] %s", @@ -620,7 +620,7 @@ } -void nn_ioctx_msgfunc(th_ioctx_t *ctx, const char *msg) +void nn_ioctx_msgfunc(th_ioctx *ctx, const int level, const char *msg) { (void) ctx; printMsgConst(NULL, LOG_STAMP | LOG_WINDOW | LOG_FILE, msg); @@ -1266,35 +1266,37 @@ { (void) conn; (void) buf; - th_ioctx_t ctx; + th_ioctx *ctx = NULL; #ifndef TH_PLAT_WINDOWS int cfgfd = -1; #endif - if (!th_ioctx_init(&ctx, setConfigFile, nn_ioctx_errfunc, nn_ioctx_msgfunc)) + if ((ctx = th_io_new(&th_stdio_io_ops, setConfigFile)) == NULL) { printMsgQ(currWin, "Could not initialize I/O context for configuration file writing!\n"); goto error; } -#ifdef __WIN32 - if ((ctx.fp = fopen(setConfigFile, "w")) == NULL) + th_io_set_handlers(ctx, nn_ioctx_errfunc, nn_ioctx_msgfunc); + +#ifdef TH_PLAT_WINDOWS + if ((ctx->fp = fopen(ctx->filename, "w")) == NULL) #else - if ((cfgfd = open(setConfigFile, O_CREAT | O_TRUNC | O_WRONLY, S_IRUSR | S_IWUSR)) == -1 || - (ctx.fp = fdopen(cfgfd, "w")) == NULL) + if ((cfgfd = open(ctx->filename, O_CREAT | O_TRUNC | O_WRONLY, S_IRUSR | S_IWUSR)) == -1 || + (ctx->data = (void *) fdopen(cfgfd, "w")) == NULL) #endif { int err = th_get_error(); printMsgQ(currWin, "Could not create configuration to file '%s', %d: %s\n", - setConfigFile, err, th_error_str(err)); + ctx->filename, err, th_error_str(err)); goto error; } printMsgQ(currWin, "Configuration saved in file '%s', res=%d\n", - setConfigFile, th_cfg_write(&ctx, cfg)); + ctx->filename, th_cfg_write(ctx, cfg)); error: - th_ioctx_close(&ctx); + th_io_free(ctx); return 0; } @@ -2050,15 +2052,17 @@ if (setConfigDir != NULL) { - th_ioctx_t ctx; - setConfigFile = th_strdup_printf("%s%c%s", setConfigDir, SET_DIR_SEPARATOR, SET_CONFIG_FILE); - - THMSG(0, "Reading configuration from '%s'.\n", setConfigFile); + th_ioctx *ctx; - if (th_ioctx_open(&ctx, setConfigFile, "r", nn_ioctx_errfunc, nn_ioctx_msgfunc)) + setConfigFile = th_strdup_printf("%s%c%s", setConfigDir, SET_DIR_SEPARATOR, SET_CONFIG_FILE); + if ((ctx = th_io_fopen(&th_stdio_io_ops, setConfigFile, "r")) != NULL) { - th_cfg_read(&ctx, cfg); - th_ioctx_close(&ctx); + th_io_set_handlers(ctx, nn_ioctx_errfunc, nn_ioctx_msgfunc); + + THMSG(0, "Reading configuration from '%s'.\n", setConfigFile); + + th_cfg_read(ctx, cfg); + th_io_close(ctx); } }