Files changed (7)
+ /// Returns the total number of bits that can still be serialized into this DataSerializer object before overflowing (which throws an exception).
+ /// Returns the total number of full bytes that can still be serialized into this DataSerializer object before overflowing (which throws an exception).
/// Starts the sending of new data. After having filled the data to send to the OverlappedTransferBuffer that is
/// returned here, commit the send by calling EndSend. If you have called BeginSend, but decide not to send any data,
+ /// @param maxBytesToSend Specifies the size of the buffer that must be returned. Specify the size (or at least an
+ /// upper limit) of the message you are sending here. Specify the actual number of bytes filled in the resulting
/// @return A transfer buffer where the data to send is to be filled in. If no new data can be sent at this time,
/// @return True if send succeeded, false otherwise. In either case, the ownership of the passed buffer send
/// is taken by this Socket and may not be accessed anymore. Discard the pointer after calling this function.
LOG(LogError, "Network::SendUDPConnectDatagram: socket.BeginSend failed! Cannot send UDP connection datagram!");
LOG(LogVerbose, "Network::SendUDPConnectDatagram: Sending UDP connect message of size %d.", (int)sendData->buffer.len);
LOG(LogVerbose, "Network::SendUDPConnectDatagram: Sending null UDP connect message of size %d.", (int)sendData->buffer.len);
- sentData->buffer.len = maxSendSize; // This is the number of bytes that the client is allowed to fill.
+ // If the buffer we pulled off was too small, free it and allocate a new one which is of the desired size.
+ return AllocateOverlappedTransferBuffer(maxBytesToSend); ///\todo In debug mode - track this pointer.
+ sentData->buffer.len = sentData->bytesAllocated; // This is the number of bytes that the client is allowed to fill.
// No previous send buffer has finished from use (or not using overlapped transfers) - allocate a new buffer.
- serializedMessages.clear(); // 'serializedMessages' is a temporary data structure used only by this member function.
+// assert(ContainerUniqueAndNoNullElements(outboundQueue)); // This precondition should always hold (but very heavy to test, uncomment to debug)
const size_t messageContentSize = msg->dataSize + encodedMsgIdLength; // 1 byte: Message ID. X bytes: Content.
const size_t totalMessageSize = messageContentSize + encodedMsgSizeLength; // 2 bytes: Content length. X bytes: Content.
- // If this message won't fit into the buffer, send out all previously gathered messages (except if there were none, then try to get the big message through).
+ overlappedTransfer = socket->BeginSend(std::max<size_t>(socket->MaxSendSize(), totalMessageSize));
+// assert(ContainerUniqueAndNoNullElements(serializedMessages)); // This precondition should always hold (but very heavy to test, uncomment to debug)
LOG(LogError, "Failed to send any messages to socket %s! (Probably next message was too big to fit in the buffer).", socket->ToString().c_str());