Skip to content

Commit 50173cc

Browse files
committed
Adapt to new protobuf version and fix number conversions
1 parent d83dbaf commit 50173cc

8 files changed

Lines changed: 26 additions & 26 deletions

File tree

conandata.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
version: "5.11.0"
1+
version: "5.11.1"

conanfile.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ def layout(self):
9393
def requirements(self):
9494
super().requirements()
9595

96-
self.requires("protobuf/3.21.12", transitive_headers=True, transitive_libs=True)
96+
self.requires("protobuf/6.33.5", transitive_headers=True, transitive_libs=True)
9797

9898
def validate(self):
9999
super().validate()
@@ -115,7 +115,6 @@ def validate(self):
115115

116116
def build_requirements(self):
117117
self.test_requires("standardprojectsettings/[>=0.2.0]")
118-
self.tool_requires("protobuf/3.21.12")
119118

120119
def generate(self):
121120
tc = CMakeToolchain(self)

include/Arcus/Socket.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,15 +91,15 @@ class Socket
9191
* \param address The IP address to connect to.
9292
* \param port The port to connect to.
9393
*/
94-
virtual void connect(const std::string& address, int port);
94+
virtual void connect(const std::string& address, uint16_t port);
9595

9696
/**
9797
* Listen for connections on an address and port.
9898
*
9999
* \param address The IP address to listen on.
100100
* \param port The port to listen on.
101101
*/
102-
virtual void listen(const std::string& address, int port);
102+
virtual void listen(const std::string& address, uint16_t port);
103103

104104
/**
105105
* Close the connection and stop handling any messages.

src/MessageTypeStore.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@ using namespace Arcus;
1919
* of std::hash differs between compilers, we need to make sure we use the same
2020
* implementation everywhere.
2121
*/
22-
uint32_t hash(const std::string& input)
22+
uint32_t hash(const std::string_view& input)
2323
{
24-
const char* data = input.c_str();
25-
uint32_t length = input.size();
24+
const char* data = input.data();
25+
size_t length = input.size();
2626
uint32_t result = static_cast<uint32_t>(2166136261UL);
2727
for (; length; --length)
2828
{
@@ -39,7 +39,8 @@ class ErrorCollector : public google::protobuf::compiler::MultiFileErrorCollecto
3939
{
4040
}
4141

42-
void AddError(const std::string& filename, int line, int column, const std::string& message) override
42+
void RecordError(absl::string_view filename, int line, int column,
43+
absl::string_view message) override
4344
{
4445
_stream << "[" << filename << " (" << line << "," << column << ")] " << message << std::endl;
4546
_error_count++;

src/PlatformSocket.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ void initializeWSA()
4242
#endif
4343

4444
// Create a sockaddr_in structure from an address and port.
45-
sockaddr_in createAddress(const std::string& address, int port)
45+
sockaddr_in createAddress(const std::string& address, uint16_t port)
4646
{
4747
sockaddr_in a;
4848
a.sin_family = AF_INET;
@@ -72,14 +72,14 @@ bool Arcus::Private::PlatformSocket::create()
7272
return _socket_id != -1;
7373
}
7474

75-
bool Arcus::Private::PlatformSocket::connect(const std::string& address, int port)
75+
bool Arcus::Private::PlatformSocket::connect(const std::string& address, uint16_t port)
7676
{
7777
auto address_data = createAddress(address, port);
7878
int result = ::connect(_socket_id, reinterpret_cast<sockaddr*>(&address_data), sizeof(address_data));
7979
return result == 0;
8080
}
8181

82-
bool Arcus::Private::PlatformSocket::bind(const std::string& address, int port)
82+
bool Arcus::Private::PlatformSocket::bind(const std::string& address, uint16_t port)
8383
{
8484
auto address_data = createAddress(address, port);
8585
int result = ::bind(_socket_id, reinterpret_cast<sockaddr*>(&address_data), sizeof(address_data));

src/PlatformSocket_p.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ class PlatformSocket
5050
*
5151
* \return true if the connection was successful, false if not.
5252
*/
53-
bool connect(const std::string& address, int port);
53+
bool connect(const std::string& address, uint16_t port);
5454
/**
5555
* Bind the socket to an address and port.
5656
*
@@ -59,7 +59,7 @@ class PlatformSocket
5959
*
6060
* \return true if successful, false if not.
6161
*/
62-
bool bind(const std::string& address, int port);
62+
bool bind(const std::string& address, uint16_t port);
6363
/**
6464
* Mark the socket as listening for new connections.
6565
*

src/Socket.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ void Socket::removeListener(SocketListener* listener)
113113
d->listeners.erase(itr);
114114
}
115115

116-
void Socket::connect(const std::string& address, int port)
116+
void Socket::connect(const std::string& address, uint16_t port)
117117
{
118118
if (d->state != SocketState::Initial || d->thread != nullptr)
119119
{
@@ -146,7 +146,7 @@ void Socket::reset()
146146
clearError();
147147
}
148148

149-
void Socket::listen(const std::string& address, int port)
149+
void Socket::listen(const std::string& address, uint16_t port)
150150
{
151151
if (d->state != SocketState::Initial || d->thread != nullptr)
152152
{

src/Socket_p.h

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ class Socket::Private
8686
bool received_close;
8787

8888
std::string address;
89-
uint port;
89+
uint16_t port;
9090

9191
std::thread* thread;
9292

@@ -346,8 +346,8 @@ void Socket::Private::sendMessage(const MessagePtr& message)
346346
return;
347347
}
348348

349-
const uint32_t message_size = message->ByteSizeLong();
350-
if (platform_socket.writeUInt32(message_size) == -1)
349+
const size_t message_size = message->ByteSizeLong();
350+
if (platform_socket.writeUInt32(static_cast<uint32_t>(message_size)) == -1)
351351
{
352352
error(ErrorCode::SendFailedError, "Could not send message size");
353353
return;
@@ -373,7 +373,7 @@ void Socket::Private::sendMessage(const MessagePtr& message)
373373
// Handle receiving data until we have a proper message.
374374
void Socket::Private::receiveNextMessage()
375375
{
376-
int result = 0;
376+
socket_size result = 0;
377377

378378
if (! current_message)
379379
{
@@ -397,9 +397,9 @@ void Socket::Private::receiveNextMessage()
397397
return;
398398
}
399399

400-
int signature = (header & 0xffff0000) >> 16;
401-
int major_version = (header & 0x0000ff00) >> 8;
402-
int minor_version = header & 0x000000ff;
400+
uint32_t signature = (header & 0xffff0000) >> 16;
401+
uint32_t major_version = (header & 0x0000ff00) >> 8;
402+
uint32_t minor_version = header & 0x000000ff;
403403

404404
if (signature != ARCUS_SIGNATURE)
405405
{
@@ -496,7 +496,7 @@ void Socket::Private::receiveNextMessage()
496496
}
497497
else
498498
{
499-
current_message->received_size = current_message->received_size + result;
499+
current_message->received_size = current_message->received_size + static_cast<uint32_t>(result);
500500

501501
DEBUG("Received " + std::to_string(result) + " bytes data");
502502

@@ -532,7 +532,7 @@ void Socket::Private::handleMessage(const std::shared_ptr<WireMessage>& wire_mes
532532

533533
MessagePtr message = message_types.createMessage(wire_message->type);
534534

535-
google::protobuf::io::ArrayInputStream array(wire_message->data, wire_message->size);
535+
google::protobuf::io::ArrayInputStream array(wire_message->data, static_cast<int>(wire_message->size));
536536
google::protobuf::io::CodedInputStream stream(&array);
537537
stream.SetTotalBytesLimit(message_size_maximum);
538538
if (! message->ParseFromCodedStream(&stream))
@@ -563,7 +563,7 @@ void Socket::Private::checkConnectionState()
563563

564564
if (diff.count() > keep_alive_rate)
565565
{
566-
int32_t keepalive = 0;
566+
constexpr uint32_t keepalive = 0;
567567
if (platform_socket.writeUInt32(keepalive) == -1)
568568
{
569569
error(ErrorCode::ConnectionResetError, "Connection reset by peer");

0 commit comments

Comments
 (0)