Skip to content

Commit

Permalink
minor indentations
Browse files Browse the repository at this point in the history
  • Loading branch information
freddy77 committed Jan 8, 2025
1 parent dcc8166 commit 8a0a808
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 33 deletions.
1 change: 1 addition & 0 deletions src/ctlib/unittests/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,5 @@
/variant
/errors
/ct_command
/timeout
/libcommon.a
54 changes: 21 additions & 33 deletions src/ctlib/unittests/timeout.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,17 @@ static const char sql[] =
"select getdate() as 'endtime'";

static int
on_interrupt(CS_CONNECTION * con TDS_UNUSED)
on_interrupt(CS_CONNECTION *con TDS_UNUSED)
{
printf("In on_interrupt, %ld seconds elapsed.\n",
(long int) (time(NULL) - start_time));
printf("In on_interrupt, %ld seconds elapsed.\n", (long int) (time(NULL) - start_time));
return CS_INT_CONTINUE;
}

static int
on_client_msg(CS_CONTEXT * ctx, CS_CONNECTION * con, CS_CLIENTMSG * errmsg)
on_client_msg(CS_CONTEXT *ctx, CS_CONNECTION *con, CS_CLIENTMSG *errmsg)
{
if (errmsg->msgnumber == 20003) { /* TDSETIME */
fprintf(stderr, "%d timeout(s) received in %ld seconds; ",
++ntimeouts, (long int) (time(NULL) - start_time));
if (errmsg->msgnumber == 20003) { /* TDSETIME */
fprintf(stderr, "%d timeout(s) received in %ld seconds; ", ++ntimeouts, (long int) (time(NULL) - start_time));
if (ntimeouts > max_timeouts) {
if (++ncancels > 1) {
fputs("could not time out cleanly;"
Expand All @@ -37,9 +35,7 @@ on_client_msg(CS_CONTEXT * ctx, CS_CONNECTION * con, CS_CLIENTMSG * errmsg)
}
fputs("lost patience;"
" cancelling (allowing 10 seconds)\n", stderr);
if (CS_FAIL == ct_con_props(con, CS_SET, CS_TIMEOUT,
&cancel_timeout, CS_UNUSED,
NULL))
if (CS_FAIL == ct_con_props(con, CS_SET, CS_TIMEOUT, &cancel_timeout, CS_UNUSED, NULL))
fputs("... but ct_con_props() failed"
" in error handler.\n", stderr);
return CS_FAIL;
Expand All @@ -51,7 +47,7 @@ on_client_msg(CS_CONTEXT * ctx, CS_CONNECTION * con, CS_CLIENTMSG * errmsg)
}

static void
test(CS_CONNECTION * con, CS_COMMAND * cmd)
test(CS_CONNECTION *con, CS_COMMAND *cmd)
{
CS_INT result_type = 0;
CS_RETCODE ret;
Expand All @@ -61,27 +57,22 @@ test(CS_CONNECTION * con, CS_COMMAND * cmd)

printf("Using %d-second query timeouts.\n", timeout_seconds);

if (CS_FAIL == ct_con_props(con, CS_SET, CS_TIMEOUT, &timeout_seconds,
CS_UNUSED, NULL)) {
fputs("Failed: ct_con_props(..., CS_SET, CS_TIMEOUT, ...).",
stderr);
if (CS_FAIL == ct_con_props(con, CS_SET, CS_TIMEOUT, &timeout_seconds, CS_UNUSED, NULL)) {
fputs("Failed: ct_con_props(..., CS_SET, CS_TIMEOUT, ...).", stderr);
exit(1);
}

/* Send something that will take a while to execute. */
printf("Issuing a query that will take 30 seconds.\n");
if (CS_SUCCEED != ct_command(cmd, CS_LANG_CMD, (void *) sql,
sizeof(sql) - 1, CS_UNUSED)) {
if (CS_SUCCEED != ct_command(cmd, CS_LANG_CMD, (void *) sql, sizeof(sql) - 1, CS_UNUSED)) {
fputs("Failed: ct_command.\n", stderr);
exit(1);
}

start_time = time(NULL); /* Track for reporting purposes. */
start_time = time(NULL); /* Track for reporting purposes. */
ntimeouts = 0;
if (CS_FAIL == ct_callback(NULL, con, CS_SET, CS_CLIENTMSG_CB,
&on_client_msg)
|| CS_FAIL == ct_callback(NULL, con, CS_SET, CS_INTERRUPT_CB,
&on_interrupt)) {
if (CS_FAIL == ct_callback(NULL, con, CS_SET, CS_CLIENTMSG_CB, &on_client_msg)
|| CS_FAIL == ct_callback(NULL, con, CS_SET, CS_INTERRUPT_CB, &on_interrupt)) {
fputs("Failed: ct_callback.\n", stderr);
exit(1);
}
Expand All @@ -93,23 +84,20 @@ test(CS_CONNECTION * con, CS_COMMAND * cmd)

ret = ct_results(cmd, &result_type);
if (ret == CS_SUCCEED) {
fprintf(stderr,
"Query unexpectedly succeeded, with result type %d.\n",
result_type);
fprintf(stderr, "Query unexpectedly succeeded, with result type %d.\n", result_type);
} else {
printf("Query failed as expected, with return code %d.\n",
ret);
printf("Query failed as expected, with return code %d.\n", ret);
}
}

int main(int argc, char** argv)
int
main(int argc, char **argv)
{
CS_CONTEXT * ctx;
CS_CONNECTION * con;
CS_COMMAND * cmd;
CS_CONTEXT *ctx;
CS_CONNECTION *con;
CS_COMMAND *cmd;

if (CS_SUCCEED != try_ctlogin_with_options(argc, argv, &ctx, &con, &cmd,
false)) {
if (CS_SUCCEED != try_ctlogin_with_options(argc, argv, &ctx, &con, &cmd, false)) {
fputs("Customary setup failed.\n", stderr);
return 1;
}
Expand Down

0 comments on commit 8a0a808

Please sign in to comment.