Skip to content

Commit fe2711b

Browse files
committed
Merge remote-tracking branch 'origin/main' into CURA-11622_conan_v2
2 parents fd280fe + 168725a commit fe2711b

File tree

5 files changed

+24
-11
lines changed

5 files changed

+24
-11
lines changed

Diff for: conandata.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
version: "5.4.0-alpha.0"
1+
version: "5.4.1"

Diff for: include/Arcus/Error.h

+3
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ enum class ErrorCode
1919
BindFailedError, ///< Bind to IP and port failed.
2020
AcceptFailedError, ///< Accepting an incoming connection failed.
2121
SendFailedError, ///< Sending a message failed.
22+
MessageTooBigError, ///< Sending a message failed because it was too big.
2223
ReceiveFailedError, ///< Receiving a message failed.
2324
UnknownMessageTypeError, ///< Received a message with an unknown message type.
2425
ParseFailedError, ///< Parsing the received message failed.
@@ -27,6 +28,8 @@ enum class ErrorCode
2728
InvalidStateError, ///< Socket is in an invalid state.
2829
InvalidMessageError, ///< Message being handled is a nullptr or otherwise invalid.
2930
Debug, // Debug messages
31+
32+
// When changing this list, don't forget to apply the same changes on pyArcus/python/Error.sip
3033
};
3134

3235
/**

Diff for: include/Arcus/Socket.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ class Socket
114114
/**
115115
* Send a message across the socket.
116116
*/
117-
virtual void sendMessage(MessagePtr message);
117+
virtual bool sendMessage(MessagePtr message);
118118

119119
/**
120120
* Remove and return the next pending message from the queue with condition blocking.

Diff for: src/Socket.cpp

+10-2
Original file line numberDiff line numberDiff line change
@@ -203,21 +203,29 @@ void Socket::close()
203203
delete d->thread;
204204
d->thread = nullptr;
205205
}
206+
206207
// Notify all in case of closing because the waiting threads need to know
207208
// that this socket has been closed and they should not wait any more.
208209
d->message_received_condition_variable.notify_all();
209210
}
210211

211-
void Socket::sendMessage(MessagePtr message)
212+
bool Socket::sendMessage(MessagePtr message)
212213
{
213214
if (! message)
214215
{
215216
d->error(ErrorCode::InvalidMessageError, "Message cannot be nullptr");
216-
return;
217+
return false;
218+
}
219+
220+
if (message->ByteSizeLong() > Private::message_size_maximum)
221+
{
222+
d->error(ErrorCode::MessageTooBigError, "Message is too big to be sent");
223+
return false;
217224
}
218225

219226
std::lock_guard<std::mutex> lock(d->sendQueueMutex);
220227
d->sendQueue.push_back(message);
228+
return true;
221229
}
222230

223231
MessagePtr Socket::takeNextMessage()

Diff for: src/Socket_p.h

+9-7
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
#define VERSION_MINOR 0
4444

4545
#define ARCUS_SIGNATURE 0x2BAD
46-
#define SIG(n) (((n)&0xffff0000) >> 16)
46+
#define SIG(n) (((n) & 0xffff0000) >> 16)
4747

4848
#define SOCKET_CLOSE 0xf0f0f0f0
4949

@@ -338,33 +338,35 @@ void Socket::Private::run()
338338
// Send a message to the connected socket.
339339
void Socket::Private::sendMessage(const MessagePtr& message)
340340
{
341-
uint32_t header = (ARCUS_SIGNATURE << 16) | (VERSION_MAJOR << 8) | (VERSION_MINOR);
341+
const uint32_t header = (ARCUS_SIGNATURE << 16) | (VERSION_MAJOR << 8) | (VERSION_MINOR);
342342
if (platform_socket.writeUInt32(header) == -1)
343343
{
344344
error(ErrorCode::SendFailedError, "Could not send message header");
345345
return;
346346
}
347347

348-
uint32_t message_size = message->ByteSizeLong();
348+
const uint32_t message_size = message->ByteSizeLong();
349349
if (platform_socket.writeUInt32(message_size) == -1)
350350
{
351351
error(ErrorCode::SendFailedError, "Could not send message size");
352352
return;
353353
}
354354

355-
uint32_t type_id = message_types.getMessageTypeId(message);
355+
const uint32_t type_id = message_types.getMessageTypeId(message);
356356
if (platform_socket.writeUInt32(type_id) == -1)
357357
{
358358
error(ErrorCode::SendFailedError, "Could not send message type");
359359
return;
360360
}
361361

362-
std::string data = message->SerializeAsString();
362+
const std::string data = message->SerializeAsString();
363363
if (platform_socket.writeBytes(data.size(), data.data()) == -1)
364364
{
365365
error(ErrorCode::SendFailedError, "Could not send message data");
366+
return;
366367
}
367-
DEBUG(std::string("Sending message of type ") + std::to_string(type_id) + " and size " + std::to_string(message_size));
368+
369+
DEBUG(std::string("Sent message of type ") + std::to_string(type_id) + " and size " + std::to_string(message_size));
368370
}
369371

370372
// Handle receiving data until we have a proper message.
@@ -571,4 +573,4 @@ void Socket::Private::checkConnectionState()
571573
}
572574
} // namespace Arcus
573575

574-
#endif // SOCKET_P_H
576+
#endif // SOCKET_P_H

0 commit comments

Comments
 (0)