Changed the meaning of the second parameter in AttachString(): it's now the maximum

length, not the length of the string.
Introduced a maximal string length that may be sent at once.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@14799 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Axel Dörfler
2005-11-09 18:28:13 +00:00
parent 88ccb61ad5
commit f46e077c5f
2 changed files with 11 additions and 3 deletions
+1 -1
View File
@@ -31,7 +31,7 @@ class LinkSender {
status_t Flush(bigtime_t timeout = B_INFINITE_TIMEOUT, bool needsReply = false);
status_t Attach(const void *data, size_t size);
status_t AttachString(const char *string, int32 length = -1);
status_t AttachString(const char *string, int32 maxLength = -1);
template <class Type> status_t Attach(const Type& data)
{
return Attach(&data, sizeof(Type));
+10 -2
View File
@@ -28,6 +28,7 @@
# define STRACE(x) ;
#endif
static const size_t kMaxStringSize = 4096;
static const size_t kWatermark = kInitialBufferSize - 24;
// if a message is started after this mark, the buffer is flushed automatically
@@ -160,8 +161,15 @@ LinkSender::AttachString(const char *string, int32 length)
if (string == NULL)
string = "";
if (length == -1)
length = strlen(string);
size_t maxLength = strlen(string);
if (length == -1) {
length = (int32)maxLength;
// we should report an error here
if (maxLength > kMaxStringSize)
length = 0;
} else if (length > (int32)maxLength)
length = maxLength;
status_t status = Attach<int32>(length);
if (status < B_OK)