forked from trilogy-libraries/trilogy
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support setting server options dynamically
This will be particularly useful for enabling/disabling multi statements on the fly, after a connection has already been initialized.
- Loading branch information
1 parent
e2b4c7d
commit ff04c1c
Showing
7 changed files
with
261 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
#include <errno.h> | ||
#include <poll.h> | ||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include <string.h> | ||
|
||
#include "../test.h" | ||
|
||
#include "trilogy/blocking.h" | ||
#include "trilogy/client.h" | ||
#include "trilogy/error.h" | ||
|
||
#define do_connect(CONN) \ | ||
do { \ | ||
int err = trilogy_init(CONN); \ | ||
ASSERT_OK(err); \ | ||
err = trilogy_connect(CONN, get_connopt()); \ | ||
ASSERT_OK(err); \ | ||
} while (0) | ||
|
||
TEST test_set_option_send() | ||
{ | ||
trilogy_conn_t conn; | ||
|
||
do_connect(&conn); | ||
|
||
const uint16_t option = 1; | ||
|
||
int err = trilogy_set_option_send(&conn, option); | ||
while (err == TRILOGY_AGAIN) { | ||
err = wait_writable(&conn); | ||
ASSERT_OK(err); | ||
|
||
err = trilogy_flush_writes(&conn); | ||
} | ||
ASSERT_OK(err); | ||
|
||
trilogy_free(&conn); | ||
PASS(); | ||
} | ||
|
||
TEST test_set_option_send_closed_socket() | ||
{ | ||
trilogy_conn_t conn; | ||
|
||
do_connect(&conn); | ||
|
||
close_socket(&conn); | ||
|
||
const uint16_t option = 1; | ||
|
||
int err = trilogy_set_option_send(&conn, option); | ||
ASSERT_ERR(TRILOGY_SYSERR, err); | ||
|
||
trilogy_free(&conn); | ||
PASS(); | ||
} | ||
|
||
TEST test_set_option_recv() | ||
{ | ||
trilogy_conn_t conn; | ||
|
||
do_connect(&conn); | ||
|
||
const uint16_t option = 0; | ||
|
||
int err = trilogy_set_option_send(&conn, option); | ||
while (err == TRILOGY_AGAIN) { | ||
err = wait_writable(&conn); | ||
ASSERT_OK(err); | ||
|
||
err = trilogy_flush_writes(&conn); | ||
} | ||
ASSERT_OK(err); | ||
|
||
err = trilogy_set_option_recv(&conn); | ||
while (err == TRILOGY_AGAIN) { | ||
err = wait_readable(&conn); | ||
ASSERT_OK(err); | ||
|
||
err = trilogy_set_option_recv(&conn); | ||
} | ||
|
||
printf("%d %s\n", conn.error_code, conn.error_message); | ||
|
||
ASSERT_OK(err); // TODO: Figure out why this assertion fails... | ||
|
||
trilogy_free(&conn); | ||
PASS(); | ||
} | ||
|
||
TEST test_set_option_recv_closed_socket() | ||
{ | ||
trilogy_conn_t conn; | ||
|
||
do_connect(&conn); | ||
|
||
const uint16_t option = 1; | ||
|
||
int err = trilogy_set_option_send(&conn, option); | ||
while (err == TRILOGY_AGAIN) { | ||
err = wait_writable(&conn); | ||
ASSERT_OK(err); | ||
|
||
err = trilogy_flush_writes(&conn); | ||
} | ||
ASSERT_OK(err); | ||
|
||
close_socket(&conn); | ||
|
||
err = trilogy_set_option_recv(&conn); | ||
ASSERT_ERR(TRILOGY_SYSERR, err); | ||
|
||
trilogy_free(&conn); | ||
PASS(); | ||
} | ||
|
||
int client_set_option_test() | ||
{ | ||
RUN_TEST(test_set_option_send); | ||
RUN_TEST(test_set_option_send_closed_socket); | ||
RUN_TEST(test_set_option_recv); | ||
RUN_TEST(test_set_option_recv_closed_socket); | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include <string.h> | ||
|
||
#include "../../test.h" | ||
|
||
#include "trilogy/error.h" | ||
#include "trilogy/protocol.h" | ||
|
||
TEST test_build_set_option_packet() | ||
{ | ||
trilogy_builder_t builder; | ||
trilogy_buffer_t buff; | ||
|
||
int err = trilogy_buffer_init(&buff, 1); | ||
ASSERT_OK(err); | ||
|
||
err = trilogy_builder_init(&builder, &buff, 0); | ||
ASSERT_OK(err); | ||
|
||
const uint16_t option = 1; | ||
|
||
err = trilogy_build_set_option_packet(&builder, option); | ||
ASSERT_OK(err); | ||
|
||
static const uint8_t expected[] = {0x03, 0x00, 0x00, 0x00, 0x1a, 0x01, 0x00}; | ||
|
||
ASSERT_MEM_EQ(buff.buff, expected, buff.len); | ||
|
||
trilogy_buffer_free(&buff); | ||
PASS(); | ||
} | ||
|
||
int build_set_option_packet_test() | ||
{ | ||
RUN_TEST(test_build_set_option_packet); | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters