2
0
mirror of https://github.com/boostorg/mysql.git synced 2026-02-14 00:42:53 +00:00

Renamed all 'errc' variables to 'code'

This commit is contained in:
ruben
2020-03-19 17:35:08 +00:00
parent afdc3bfd19
commit 4260bac19b
14 changed files with 105 additions and 106 deletions

View File

@@ -11,7 +11,7 @@ template <typename StreamType>
void close_statement(
channel<StreamType>& chan,
std::uint32_t statement_id,
error_code& errc,
error_code& code,
error_info& info
);

View File

@@ -8,7 +8,7 @@ template <typename StreamType>
void boost::mysql::detail::close_statement(
channel<StreamType>& chan,
std::uint32_t statement_id,
error_code& errc,
error_code& code,
error_info&
)
{
@@ -20,7 +20,7 @@ void boost::mysql::detail::close_statement(
// Send it. No response is sent back
chan.reset_sequence_number();
chan.write(boost::asio::buffer(chan.shared_buffer()), errc);
chan.write(boost::asio::buffer(chan.shared_buffer()), code);
}
template <typename StreamType, typename CompletionToken>

View File

@@ -306,10 +306,10 @@ boost::mysql::detail::async_handshake(
{
}
void complete(bool cont, error_code errc)
void complete(bool cont, error_code code)
{
channel_.set_current_capabilities(processor_.negotiated_capabilities());
BaseType::complete(cont, errc, std::move(info_));
BaseType::complete(cont, code, std::move(info_));
}
void operator()(

View File

@@ -32,9 +32,9 @@ public:
channel(AsyncStream& stream): next_layer_ {stream} {};
template <typename Allocator>
void read(basic_bytestring<Allocator>& buffer, error_code& errc);
void read(basic_bytestring<Allocator>& buffer, error_code& code);
void write(boost::asio::const_buffer buffer, error_code& errc);
void write(boost::asio::const_buffer buffer, error_code& code);
template <typename Allocator, typename CompletionToken>
BOOST_ASIO_INITFN_RESULT_TYPE(CompletionToken, void(error_code))

View File

@@ -77,31 +77,31 @@ template <typename AsyncStream>
template <typename Allocator>
void boost::mysql::detail::channel<AsyncStream>::read(
basic_bytestring<Allocator>& buffer,
error_code& errc
error_code& code
)
{
std::size_t transferred_size = 0;
std::uint32_t size_to_read = 0;
buffer.clear();
errc.clear();
code.clear();
do
{
boost::asio::read(
next_layer_,
boost::asio::buffer(header_buffer_),
errc
code
);
if (errc) return;
errc = process_header_read(size_to_read);
if (errc) return;
if (code) return;
code = process_header_read(size_to_read);
if (code) return;
buffer.resize(buffer.size() + size_to_read);
boost::asio::read(
next_layer_,
boost::asio::buffer(buffer.data() + transferred_size, size_to_read),
errc
code
);
if (errc) return;
if (code) return;
transferred_size += size_to_read;
} while (size_to_read == MAX_PACKET_SIZE);
}
@@ -109,7 +109,7 @@ void boost::mysql::detail::channel<AsyncStream>::read(
template <typename AsyncStream>
void boost::mysql::detail::channel<AsyncStream>::write(
boost::asio::const_buffer buffer,
error_code& errc
error_code& code
)
{
std::size_t transferred_size = 0;
@@ -128,9 +128,9 @@ void boost::mysql::detail::channel<AsyncStream>::write(
boost::asio::buffer(header_buffer_),
boost::asio::buffer(first + transferred_size, size_to_write)
},
errc
code
);
if (errc) return;
if (code) return;
transferred_size += size_to_write;
} while (transferred_size < bufsize);
}
@@ -168,7 +168,7 @@ boost::mysql::detail::channel<AsyncStream>::async_read(
}
void operator()(
error_code errc,
error_code code,
std::size_t bytes_transferred,
bool cont=true
)
@@ -185,17 +185,17 @@ boost::mysql::detail::channel<AsyncStream>::async_read(
std::move(*this)
);
if (errc)
if (code)
{
this->complete(cont, errc);
this->complete(cont, code);
yield break;
}
errc = stream_.process_header_read(size_to_read);
code = stream_.process_header_read(size_to_read);
if (errc)
if (code)
{
this->complete(cont, errc);
this->complete(cont, code);
yield break;
}
@@ -207,9 +207,9 @@ boost::mysql::detail::channel<AsyncStream>::async_read(
std::move(*this)
);
if (errc)
if (code)
{
this->complete(cont, errc);
this->complete(cont, code);
yield break;
}
@@ -258,7 +258,7 @@ boost::mysql::detail::channel<AsyncStream>::async_write(
}
void operator()(
error_code errc,
error_code code,
std::size_t bytes_transferred,
bool cont=true
)
@@ -282,9 +282,9 @@ boost::mysql::detail::channel<AsyncStream>::async_write(
std::move(*this)
);
if (errc)
if (code)
{
this->complete(cont, errc);
this->complete(cont, code);
yield break;
}

View File

@@ -352,8 +352,8 @@ inline boost::mysql::error_code boost::mysql::detail::process_error_packet(
)
{
err_packet error_packet;
auto errc = deserialize_message(error_packet, ctx);
if (errc) return errc;
auto code = deserialize_message(error_packet, ctx);
if (code) return code;
info.set_message(std::string(error_packet.error_message.value));
return make_error_code(static_cast<Error>(error_packet.error_code.value));
}

View File

@@ -29,16 +29,16 @@ inline handshake_params to_handshake_params(
template <typename Stream>
void boost::mysql::connection<Stream>::handshake(
const connection_params& params,
error_code& errc,
error_code& code,
error_info& info
)
{
errc.clear();
code.clear();
info.clear();
detail::hanshake(
channel_,
detail::to_handshake_params(params),
errc,
code,
info
);
// TODO: should we close() the stream in case of error?
@@ -49,10 +49,10 @@ void boost::mysql::connection<Stream>::handshake(
const connection_params& params
)
{
error_code errc;
error_code code;
error_info info;
handshake(params, errc, info);
detail::check_error_code(errc, info);
handshake(params, code, info);
detail::check_error_code(code, info);
}
template <typename Stream>

View File

@@ -53,11 +53,11 @@ inline boost::system::error_code make_error_code(Error error)
return boost::system::error_code(static_cast<int>(error), mysql_error_category);
}
inline void check_error_code(const error_code& errc, const error_info& info)
inline void check_error_code(const error_code& code, const error_info& info)
{
if (errc)
if (code)
{
throw boost::system::system_error(errc, info.message());
throw boost::system::system_error(code, info.message());
}
}

View File

@@ -111,24 +111,24 @@ auto boost::mysql::prepared_statement<StreamType>::async_execute(
template <typename StreamType>
void boost::mysql::prepared_statement<StreamType>::close(
error_code& errc,
error_code& code,
error_info& info
)
{
assert(valid());
errc.clear();
code.clear();
info.clear();
detail::close_statement(*channel_, id(), errc, info);
detail::close_statement(*channel_, id(), code, info);
}
template <typename StreamType>
void boost::mysql::prepared_statement<StreamType>::close()
{
assert(valid());
error_code errc;
error_code code;
error_info info;
detail::close_statement(*channel_, id(), errc, info);
detail::check_error_code(errc, info);
detail::close_statement(*channel_, id(), code, info);
detail::check_error_code(code, info);
}
template <typename StreamType>

View File

@@ -39,10 +39,10 @@ const boost::mysql::row* boost::mysql::resultset<StreamType>::fetch_one(
template <typename StreamType>
const boost::mysql::row* boost::mysql::resultset<StreamType>::fetch_one()
{
error_code errc;
error_code code;
error_info info;
const row* res = fetch_one(errc, info);
detail::check_error_code(errc, info);
const row* res = fetch_one(code, info);
detail::check_error_code(code, info);
return res;
}
@@ -97,10 +97,10 @@ std::vector<boost::mysql::owning_row> boost::mysql::resultset<StreamType>::fetch
std::size_t count
)
{
error_code errc;
error_code code;
error_info info;
auto res = fetch_many(count, errc, info);
detail::check_error_code(errc, info);
auto res = fetch_many(count, code, info);
detail::check_error_code(code, info);
return res;
}

View File

@@ -41,8 +41,8 @@ struct IntegTest : testing::Test
~IntegTest()
{
error_code errc;
conn.next_level().close(errc);
error_code code;
conn.next_level().close(code);
guard.reset();
runner.join();
}

View File

@@ -34,8 +34,8 @@ public:
const boost::mysql::connection_params& params
) override
{
return impl([&](error_code& errc, error_info& info) {
conn.handshake(params, errc, info);
return impl([&](error_code& code, error_info& info) {
conn.handshake(params, code, info);
return no_result();
});
}
@@ -44,8 +44,8 @@ public:
std::string_view query
) override
{
return impl([&](error_code& errc, error_info& info) {
return conn.query(query, errc, info);
return impl([&](error_code& code, error_info& info) {
return conn.query(query, code, info);
});
}
network_result<tcp_prepared_statement> prepare_statement(
@@ -80,8 +80,8 @@ public:
tcp_prepared_statement& stmt
) override
{
return impl([&](error_code& errc, error_info& info) {
stmt.close(errc, info);
return impl([&](error_code& code, error_info& info) {
stmt.close(code, info);
return no_result();
});
}
@@ -89,8 +89,8 @@ public:
tcp_resultset& r
) override
{
return impl([&](error_code& errc, error_info& info) {
return r.fetch_one(errc, info);
return impl([&](error_code& code, error_info& info) {
return r.fetch_one(code, info);
});
}
network_result<std::vector<owning_row>> fetch_many(
@@ -98,16 +98,16 @@ public:
std::size_t count
) override
{
return impl([&](error_code& errc, error_info& info) {
return r.fetch_many(count, errc, info);
return impl([&](error_code& code, error_info& info) {
return r.fetch_many(count, code, info);
});
}
network_result<std::vector<owning_row>> fetch_all(
tcp_resultset& r
) override
{
return impl([&](error_code& errc, error_info& info) {
return r.fetch_all(errc, info);
return impl([&](error_code& code, error_info& info) {
return r.fetch_all(code, info);
});
}
};
@@ -219,8 +219,8 @@ class async : public network_functions
template <typename R, typename Callable>
static network_result<R> impl(Callable&& cb) {
std::promise<network_result<R>> prom;
cb([&prom](error_code errc, error_info info, auto retval) {
prom.set_value(network_result<R>{errc, std::move(info), std::move(retval)});
cb([&prom](error_code code, error_info info, auto retval) {
prom.set_value(network_result<R>{code, std::move(info), std::move(retval)});
});
return prom.get_future().get();
}
@@ -228,8 +228,8 @@ class async : public network_functions
template <typename Callable>
static network_result<no_result> impl_no_result(Callable&& cb) {
std::promise<network_result<no_result>> prom;
cb([&prom](error_code errc, error_info info) {
prom.set_value(network_result<no_result>{errc, std::move(info), no_result()});
cb([&prom](error_code code, error_info info) {
prom.set_value(network_result<no_result>{code, std::move(info), no_result()});
});
return prom.get_future().get();
}

View File

@@ -21,7 +21,6 @@ struct PrepareStatementTest : public NetworkTest<>
{
};
// sync errc
TEST_P(PrepareStatementTest, OkNoParams)
{
auto stmt = GetParam()->prepare_statement(conn, "SELECT * FROM empty_table");

View File

@@ -114,7 +114,7 @@ struct MysqlChannelFixture : public Test
using MockChannel = channel<NiceMock<MockStream>>;
NiceMock<MockStream> stream;
MockChannel chan {stream};
error_code errc;
error_code code;
InSequence seq;
MysqlChannelFixture()
@@ -173,8 +173,8 @@ TEST_F(MysqlChannelReadTest, SyncRead_AllReadsSuccessful_ReadHeaderPopulatesBuff
0x03, 0x00, 0x00, 0x00,
0xfe, 0x03, 0x02
};
chan.read(buffer, errc);
EXPECT_EQ(errc, error_code());
chan.read(buffer, code);
EXPECT_EQ(code, error_code());
verify_buffer({0xfe, 0x03, 0x02});
}
@@ -188,8 +188,8 @@ TEST_F(MysqlChannelReadTest, SyncRead_MoreThan16M_JoinsPackets)
concat(bytes_to_read, std::vector<uint8_t>(0xffffff, 0x20));
concat(bytes_to_read, {0x04, 0x00, 0x00, 0x02});
concat(bytes_to_read, {0x20, 0x20, 0x20, 0x20});
chan.read(buffer, errc);
EXPECT_EQ(errc, error_code());
chan.read(buffer, code);
EXPECT_EQ(code, error_code());
verify_buffer(std::vector<uint8_t>(0xffffff * 2 + 4, 0x20));
}
@@ -198,8 +198,8 @@ TEST_F(MysqlChannelReadTest, SyncRead_EmptyPacket_LeavesBufferEmpty)
ON_CALL(stream, read_buffer)
.WillByDefault(Invoke(make_read_handler()));
concat(bytes_to_read, {0x00, 0x00, 0x00, 0x00});
chan.read(buffer, errc);
EXPECT_EQ(errc, error_code());
chan.read(buffer, code);
EXPECT_EQ(code, error_code());
verify_buffer(std::vector<uint8_t>{});
}
@@ -210,8 +210,8 @@ TEST_F(MysqlChannelReadTest, SyncRead_ShortReads_InvokesReadAgain)
.WillOnce(Invoke(buffer_copier({ 0x00, 0x00, 0x00})))
.WillOnce(Invoke(buffer_copier({0x01, 0x02})))
.WillOnce(Invoke(buffer_copier({0x03, 0x04})));
chan.read(buffer, errc);
EXPECT_EQ(errc, error_code());
chan.read(buffer, code);
EXPECT_EQ(code, error_code());
verify_buffer({0x01, 0x02, 0x03, 0x04});
}
@@ -220,8 +220,8 @@ TEST_F(MysqlChannelReadTest, SyncRead_ReadErrorInHeader_ReturnsFailureErrorCode)
auto expected_error = errc::make_error_code(errc::not_supported);
EXPECT_CALL(stream, read_buffer)
.WillOnce(Invoke(read_failer(expected_error)));
chan.read(buffer, errc);
EXPECT_EQ(errc, expected_error);
chan.read(buffer, code);
EXPECT_EQ(code, expected_error);
}
TEST_F(MysqlChannelReadTest, SyncRead_ReadErrorInPacket_ReturnsFailureErrorCode)
@@ -230,8 +230,8 @@ TEST_F(MysqlChannelReadTest, SyncRead_ReadErrorInPacket_ReturnsFailureErrorCode)
EXPECT_CALL(stream, read_buffer)
.WillOnce(Invoke(buffer_copier({0xff, 0xff, 0xff, 0x00})))
.WillOnce(Invoke(read_failer(expected_error)));
chan.read(buffer, errc);
EXPECT_EQ(errc, expected_error);
chan.read(buffer, code);
EXPECT_EQ(code, expected_error);
}
TEST_F(MysqlChannelReadTest, SyncRead_SequenceNumberMismatch_ReturnsAppropriateErrorCode)
@@ -239,8 +239,8 @@ TEST_F(MysqlChannelReadTest, SyncRead_SequenceNumberMismatch_ReturnsAppropriateE
ON_CALL(stream, read_buffer)
.WillByDefault(Invoke(make_read_handler()));
bytes_to_read = {0xff, 0xff, 0xff, 0x05};
chan.read(buffer, errc);
EXPECT_EQ(errc, make_error_code(Error::sequence_number_mismatch));
chan.read(buffer, code);
EXPECT_EQ(code, make_error_code(Error::sequence_number_mismatch));
}
TEST_F(MysqlChannelReadTest, SyncRead_SequenceNumberNotZero_RespectsCurrentSequenceNumber)
@@ -252,8 +252,8 @@ TEST_F(MysqlChannelReadTest, SyncRead_SequenceNumberNotZero_RespectsCurrentSeque
0xfe, 0x03, 0x02
};
chan.reset_sequence_number(0x21);
chan.read(buffer, errc);
EXPECT_EQ(errc, error_code());
chan.read(buffer, code);
EXPECT_EQ(code, error_code());
verify_buffer({0xfe, 0x03, 0x02});
EXPECT_EQ(chan.sequence_number(), 0x22);
}
@@ -267,8 +267,8 @@ TEST_F(MysqlChannelReadTest, SyncRead_SequenceNumberFF_SequenceNumberWraps)
0xfe, 0x03, 0x02
};
chan.reset_sequence_number(0xff);
chan.read(buffer, errc);
EXPECT_EQ(errc, error_code());
chan.read(buffer, code);
EXPECT_EQ(code, error_code());
verify_buffer({0xfe, 0x03, 0x02});
EXPECT_EQ(chan.sequence_number(), 0);
}
@@ -306,19 +306,19 @@ TEST_F(MysqlChannelWriteTest, SyncWrite_AllWritesSuccessful_WritesHeaderAndBuffe
{
ON_CALL(stream, write_buffer)
.WillByDefault(Invoke(make_write_handler()));
chan.write(buffer(std::vector<uint8_t>{0xaa, 0xab, 0xac}), errc);
chan.write(buffer(std::vector<uint8_t>{0xaa, 0xab, 0xac}), code);
verify_buffer({
0x03, 0x00, 0x00, 0x00, // header
0xaa, 0xab, 0xac // body
});
EXPECT_EQ(errc, error_code());
EXPECT_EQ(code, error_code());
}
TEST_F(MysqlChannelWriteTest, SyncWrite_MoreThan16M_SplitsInPackets)
{
ON_CALL(stream, write_buffer)
.WillByDefault(Invoke(make_write_handler()));
chan.write(buffer(std::vector<uint8_t>(2*0xffffff + 4, 0xab)), errc);
chan.write(buffer(std::vector<uint8_t>(2*0xffffff + 4, 0xab)), code);
std::vector<uint8_t> expected_buffer {0xff, 0xff, 0xff, 0x00};
concat(expected_buffer, std::vector<std::uint8_t>(0xffffff, 0xab));
concat(expected_buffer, {0xff, 0xff, 0xff, 0x01});
@@ -326,7 +326,7 @@ TEST_F(MysqlChannelWriteTest, SyncWrite_MoreThan16M_SplitsInPackets)
concat(expected_buffer, {0x04, 0x00, 0x00, 0x02});
concat(expected_buffer, std::vector<std::uint8_t>(4, 0xab));
verify_buffer(expected_buffer);
EXPECT_EQ(errc, error_code());
EXPECT_EQ(code, error_code());
}
TEST_F(MysqlChannelWriteTest, SyncWrite_EmptyPacket_WritesHeader)
@@ -334,29 +334,29 @@ TEST_F(MysqlChannelWriteTest, SyncWrite_EmptyPacket_WritesHeader)
ON_CALL(stream, write_buffer)
.WillByDefault(Invoke(make_write_handler()));
chan.reset_sequence_number(2);
chan.write(buffer(std::vector<uint8_t>{}), errc);
chan.write(buffer(std::vector<uint8_t>{}), code);
verify_buffer({0x00, 0x00, 0x00, 0x02});
EXPECT_EQ(errc, error_code());
EXPECT_EQ(code, error_code());
}
TEST_F(MysqlChannelWriteTest, SyncWrite_ShortWrites_WritesHeaderAndBuffer)
{
ON_CALL(stream, write_buffer)
.WillByDefault(Invoke(make_write_handler(2)));
chan.write(buffer(std::vector<uint8_t>{0xaa, 0xab, 0xac}), errc);
chan.write(buffer(std::vector<uint8_t>{0xaa, 0xab, 0xac}), code);
verify_buffer({
0x03, 0x00, 0x00, 0x00, // header
0xaa, 0xab, 0xac // body
});
EXPECT_EQ(errc, error_code());
EXPECT_EQ(code, error_code());
}
TEST_F(MysqlChannelWriteTest, SyncWrite_WriteErrorInHeader_ReturnsErrorCode)
{
ON_CALL(stream, write_buffer)
.WillByDefault(Invoke(write_failer(errc::broken_pipe)));
chan.write(buffer(std::vector<uint8_t>(10, 0x01)), errc);
EXPECT_EQ(errc, errc::make_error_code(errc::broken_pipe));
chan.write(buffer(std::vector<uint8_t>(10, 0x01)), code);
EXPECT_EQ(code, errc::make_error_code(errc::broken_pipe));
}
TEST_F(MysqlChannelWriteTest, SyncWrite_WriteErrorInPacket_ReturnsErrorCode)
@@ -364,8 +364,8 @@ TEST_F(MysqlChannelWriteTest, SyncWrite_WriteErrorInPacket_ReturnsErrorCode)
EXPECT_CALL(stream, write_buffer)
.WillOnce(Return(4))
.WillOnce(Invoke(write_failer(errc::broken_pipe)));
chan.write(buffer(std::vector<uint8_t>(10, 0x01)), errc);
EXPECT_EQ(errc, errc::make_error_code(errc::broken_pipe));
chan.write(buffer(std::vector<uint8_t>(10, 0x01)), code);
EXPECT_EQ(code, errc::make_error_code(errc::broken_pipe));
}
TEST_F(MysqlChannelWriteTest, SyncWrite_SequenceNumberNotZero_RespectsSequenceNumber)
@@ -373,12 +373,12 @@ TEST_F(MysqlChannelWriteTest, SyncWrite_SequenceNumberNotZero_RespectsSequenceNu
chan.reset_sequence_number(0xab);
ON_CALL(stream, write_buffer)
.WillByDefault(Invoke(make_write_handler()));
chan.write(buffer(std::vector<uint8_t>{0xaa, 0xab, 0xac}), errc);
chan.write(buffer(std::vector<uint8_t>{0xaa, 0xab, 0xac}), code);
verify_buffer({
0x03, 0x00, 0x00, 0xab, // header
0xaa, 0xab, 0xac // body
});
EXPECT_EQ(errc, error_code());
EXPECT_EQ(code, error_code());
EXPECT_EQ(chan.sequence_number(), 0xac);
}
@@ -387,12 +387,12 @@ TEST_F(MysqlChannelWriteTest, SyncWrite_SequenceIsFF_WrapsSequenceNumber)
chan.reset_sequence_number(0xff);
ON_CALL(stream, write_buffer)
.WillByDefault(Invoke(make_write_handler()));
chan.write(buffer(std::vector<uint8_t>{0xaa, 0xab, 0xac}), errc);
chan.write(buffer(std::vector<uint8_t>{0xaa, 0xab, 0xac}), code);
verify_buffer({
0x03, 0x00, 0x00, 0xff, // header
0xaa, 0xab, 0xac // body
});
EXPECT_EQ(errc, error_code());
EXPECT_EQ(code, error_code());
EXPECT_EQ(chan.sequence_number(), 0);
}