Removed fixed attachment limit
git-svn-id: file:///srv/svn/repos/haiku/trunk/current@2870 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -5,10 +5,7 @@
|
|||||||
#include <OS.h>
|
#include <OS.h>
|
||||||
#include <SupportDefs.h>
|
#include <SupportDefs.h>
|
||||||
#include <Rect.h>
|
#include <Rect.h>
|
||||||
|
#include <List.h>
|
||||||
#ifndef _PORTLINK_BUFFERSIZE
|
|
||||||
#define _PORTLINK_MAX_ATTACHMENTS 50
|
|
||||||
#endif
|
|
||||||
|
|
||||||
class PortLinkData;
|
class PortLinkData;
|
||||||
|
|
||||||
@@ -47,9 +44,8 @@ protected:
|
|||||||
port_id target, replyport;
|
port_id target, replyport;
|
||||||
int32 opcode;
|
int32 opcode;
|
||||||
uint32 bufferlength,capacity;
|
uint32 bufferlength,capacity;
|
||||||
int num_attachments;
|
|
||||||
bool port_ok;
|
bool port_ok;
|
||||||
PortLinkData *attachments[_PORTLINK_MAX_ATTACHMENTS];
|
BList *attachlist;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
+37
-88
@@ -27,7 +27,7 @@ capacity - contains the storage capacity of the target port.
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <malloc.h>
|
#include <malloc.h>
|
||||||
|
|
||||||
#define PLDEBUG
|
//#define PLDEBUG
|
||||||
//#define PLD_DEBUG
|
//#define PLD_DEBUG
|
||||||
|
|
||||||
//#define CAPACITY_CHECKING
|
//#define CAPACITY_CHECKING
|
||||||
@@ -66,10 +66,10 @@ printf("PortLink(%lu)\n",port);
|
|||||||
capacity=pi.capacity;
|
capacity=pi.capacity;
|
||||||
|
|
||||||
// We start out without any data attached to the port message
|
// We start out without any data attached to the port message
|
||||||
num_attachments=0;
|
|
||||||
opcode=0;
|
opcode=0;
|
||||||
bufferlength=0;
|
bufferlength=0;
|
||||||
replyport=create_port(30,"PortLink reply port");
|
replyport=create_port(30,"PortLink reply port");
|
||||||
|
attachlist=new BList(0);
|
||||||
#ifdef PLDEBUG
|
#ifdef PLDEBUG
|
||||||
printf("\tPort valid: %s\n",(port_ok)?"true":"false");
|
printf("\tPort valid: %s\n",(port_ok)?"true":"false");
|
||||||
printf("\tReply port: %lu\n",replyport);
|
printf("\tReply port: %lu\n",replyport);
|
||||||
@@ -91,9 +91,8 @@ printf("PortLink(PortLink*)\n");
|
|||||||
port_ok=link.port_ok;
|
port_ok=link.port_ok;
|
||||||
capacity=link.capacity;
|
capacity=link.capacity;
|
||||||
bufferlength=0;
|
bufferlength=0;
|
||||||
num_attachments=0;
|
|
||||||
replyport=create_port(30,"PortLink reply port");
|
replyport=create_port(30,"PortLink reply port");
|
||||||
|
attachlist=new BList(0);
|
||||||
#ifdef PLDEBUG
|
#ifdef PLDEBUG
|
||||||
printf("\tOpcode: %lu\n",opcode);
|
printf("\tOpcode: %lu\n",opcode);
|
||||||
printf("\tTarget port: %lu\n",target);
|
printf("\tTarget port: %lu\n",target);
|
||||||
@@ -113,11 +112,10 @@ printf("~PortLink()\n");
|
|||||||
// free the memory used by the attachments. We do not flush the queue
|
// free the memory used by the attachments. We do not flush the queue
|
||||||
// because the port may no longer be valid in cases such as the app
|
// because the port may no longer be valid in cases such as the app
|
||||||
// is in the process of quitting
|
// is in the process of quitting
|
||||||
if(num_attachments || bufferlength)
|
if(attachlist->CountItems()>0)
|
||||||
MakeEmpty();
|
MakeEmpty();
|
||||||
|
|
||||||
//TODO: Inline the MakeEmpty call in a way such that it ignores num_attachments
|
delete attachlist;
|
||||||
// and deletes all non-NULL pointers, setting them to NULL afterward.
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void PortLink::SetOpCode(int32 code)
|
void PortLink::SetOpCode(int32 code)
|
||||||
@@ -174,7 +172,7 @@ printf("\tFlush(): invalid port\n");
|
|||||||
return B_BAD_VALUE;
|
return B_BAD_VALUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(num_attachments>0)
|
if(attachlist->CountItems()>0)
|
||||||
{
|
{
|
||||||
#ifdef PLDEBUG
|
#ifdef PLDEBUG
|
||||||
printf("\tFlush(): flushing %d attachments\n",num_attachments);
|
printf("\tFlush(): flushing %d attachments\n",num_attachments);
|
||||||
@@ -208,14 +206,6 @@ int8* PortLink::FlushWithReply(int32 *code, status_t *status, ssize_t *buffersiz
|
|||||||
#ifdef PLDEBUG
|
#ifdef PLDEBUG
|
||||||
printf("PortLink::FlushWithReply(int32*,status_t*,ssize_t*,bigtime_t)\n");
|
printf("PortLink::FlushWithReply(int32*,status_t*,ssize_t*,bigtime_t)\n");
|
||||||
#endif
|
#endif
|
||||||
if(num_attachments>=_PORTLINK_MAX_ATTACHMENTS)
|
|
||||||
{
|
|
||||||
#ifdef PLDEBUG
|
|
||||||
printf("PortLink::FlushWithReply(): too many attachments\n");
|
|
||||||
#endif
|
|
||||||
*status=B_ERROR;
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(!port_ok)
|
if(!port_ok)
|
||||||
{
|
{
|
||||||
@@ -250,9 +240,9 @@ printf("PortLink::FlushWithReply(): bad port\n");
|
|||||||
size+=pld->buffersize;
|
size+=pld->buffersize;
|
||||||
|
|
||||||
// attach everything else
|
// attach everything else
|
||||||
for(int i=0;i<num_attachments;i++)
|
for(int i=0;i<attachlist->CountItems();i++)
|
||||||
{
|
{
|
||||||
pld=attachments[i];
|
pld=(PortLinkData*)attachlist->ItemAt(i);
|
||||||
memcpy(bufferindex, pld->buffer, pld->buffersize);
|
memcpy(bufferindex, pld->buffer, pld->buffersize);
|
||||||
bufferindex += pld->buffersize;
|
bufferindex += pld->buffersize;
|
||||||
size+=pld->buffersize;
|
size+=pld->buffersize;
|
||||||
@@ -302,14 +292,6 @@ printf("PortLink::FlushWithReply(ReplyData*,bigtime_t)\n");
|
|||||||
|
|
||||||
// Effectively, an Attach() call inlined for changes
|
// Effectively, an Attach() call inlined for changes
|
||||||
|
|
||||||
if(num_attachments>=_PORTLINK_MAX_ATTACHMENTS)
|
|
||||||
{
|
|
||||||
#ifdef PLDEBUG
|
|
||||||
printf("\tFlushWithReply(): too many attachments\n");
|
|
||||||
#endif
|
|
||||||
return B_ERROR;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(!port_ok)
|
if(!port_ok)
|
||||||
{
|
{
|
||||||
#ifdef PLDEBUG
|
#ifdef PLDEBUG
|
||||||
@@ -344,9 +326,9 @@ printf("\tFlushWithReply(): unable to assign reply port to data\n");
|
|||||||
size+=pld->buffersize;
|
size+=pld->buffersize;
|
||||||
|
|
||||||
// attach everything else
|
// attach everything else
|
||||||
for(int i=0;i<num_attachments;i++)
|
for(int i=0;i<attachlist->CountItems();i++)
|
||||||
{
|
{
|
||||||
pld=attachments[i];
|
pld=(PortLinkData*)attachlist->ItemAt(i);
|
||||||
memcpy(bufferindex, pld->buffer, pld->buffersize);
|
memcpy(bufferindex, pld->buffer, pld->buffersize);
|
||||||
bufferindex += pld->buffersize;
|
bufferindex += pld->buffersize;
|
||||||
size+=pld->buffersize;
|
size+=pld->buffersize;
|
||||||
@@ -390,14 +372,6 @@ printf("Attach(%p,%ld)\n",data,size);
|
|||||||
// to the end of the list.
|
// to the end of the list.
|
||||||
|
|
||||||
// Prevent parameter problems
|
// Prevent parameter problems
|
||||||
if(num_attachments>=_PORTLINK_MAX_ATTACHMENTS)
|
|
||||||
{
|
|
||||||
#ifdef PLDEBUG
|
|
||||||
printf("\tAttach(): too many attachments\n");
|
|
||||||
#endif
|
|
||||||
return B_ERROR;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(size==0)
|
if(size==0)
|
||||||
{
|
{
|
||||||
#ifdef PLDEBUG
|
#ifdef PLDEBUG
|
||||||
@@ -420,8 +394,7 @@ printf("\tAttach(): bufferlength+size > port capacity\n");
|
|||||||
PortLinkData *pld=new PortLinkData;
|
PortLinkData *pld=new PortLinkData;
|
||||||
if(pld->Set(data,size)==B_OK)
|
if(pld->Set(data,size)==B_OK)
|
||||||
{
|
{
|
||||||
num_attachments++;
|
attachlist->AddItem(pld);
|
||||||
attachments[num_attachments-1]=pld;
|
|
||||||
bufferlength+=size;
|
bufferlength+=size;
|
||||||
#ifdef PLDEBUG
|
#ifdef PLDEBUG
|
||||||
printf("\tAttach(): successful\n");
|
printf("\tAttach(): successful\n");
|
||||||
@@ -435,6 +408,7 @@ printf("\t\tAttach(): buffer length is %lu\n", bufferlength);
|
|||||||
printf("\tAttach(): Couldn't assign data to PortLinkData object\n");
|
printf("\tAttach(): Couldn't assign data to PortLinkData object\n");
|
||||||
#endif
|
#endif
|
||||||
delete pld;
|
delete pld;
|
||||||
|
return B_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
return B_OK;
|
return B_OK;
|
||||||
@@ -448,10 +422,6 @@ status_t PortLink::Attach(int32 data)
|
|||||||
#ifdef PLDEBUG
|
#ifdef PLDEBUG
|
||||||
printf("Attach(%ld)\n",data);
|
printf("Attach(%ld)\n",data);
|
||||||
#endif
|
#endif
|
||||||
// Prevent parameter problems
|
|
||||||
if(num_attachments>=_PORTLINK_MAX_ATTACHMENTS)
|
|
||||||
return B_ERROR;
|
|
||||||
|
|
||||||
int32 size=sizeof(int32);
|
int32 size=sizeof(int32);
|
||||||
|
|
||||||
#ifdef CAPACITY_CHECKING
|
#ifdef CAPACITY_CHECKING
|
||||||
@@ -463,13 +433,13 @@ printf("Attach(%ld)\n",data);
|
|||||||
PortLinkData *pld=new PortLinkData;
|
PortLinkData *pld=new PortLinkData;
|
||||||
if(pld->Set(&data,size)==B_OK)
|
if(pld->Set(&data,size)==B_OK)
|
||||||
{
|
{
|
||||||
num_attachments++;
|
attachlist->AddItem(pld);
|
||||||
attachments[num_attachments-1]=pld;
|
|
||||||
bufferlength+=size;
|
bufferlength+=size;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
delete pld;
|
delete pld;
|
||||||
|
return B_ERROR;
|
||||||
}
|
}
|
||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
@@ -479,10 +449,6 @@ status_t PortLink::Attach(int16 data)
|
|||||||
#ifdef PLDEBUG
|
#ifdef PLDEBUG
|
||||||
printf("Attach(%d)\n",data);
|
printf("Attach(%d)\n",data);
|
||||||
#endif
|
#endif
|
||||||
// Prevent parameter problems
|
|
||||||
if(num_attachments>=_PORTLINK_MAX_ATTACHMENTS)
|
|
||||||
return B_ERROR;
|
|
||||||
|
|
||||||
int32 size=sizeof(int16);
|
int32 size=sizeof(int16);
|
||||||
|
|
||||||
#ifdef CAPACITY_CHECKING
|
#ifdef CAPACITY_CHECKING
|
||||||
@@ -494,13 +460,13 @@ printf("Attach(%d)\n",data);
|
|||||||
PortLinkData *pld=new PortLinkData;
|
PortLinkData *pld=new PortLinkData;
|
||||||
if(pld->Set(&data,size)==B_OK)
|
if(pld->Set(&data,size)==B_OK)
|
||||||
{
|
{
|
||||||
num_attachments++;
|
attachlist->AddItem(pld);
|
||||||
attachments[num_attachments-1]=pld;
|
|
||||||
bufferlength+=size;
|
bufferlength+=size;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
delete pld;
|
delete pld;
|
||||||
|
return B_ERROR;
|
||||||
}
|
}
|
||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
@@ -510,10 +476,6 @@ status_t PortLink::Attach(int8 data)
|
|||||||
#ifdef PLDEBUG
|
#ifdef PLDEBUG
|
||||||
printf("Attach(%d)\n",data);
|
printf("Attach(%d)\n",data);
|
||||||
#endif
|
#endif
|
||||||
// Prevent parameter problems
|
|
||||||
if(num_attachments>=_PORTLINK_MAX_ATTACHMENTS)
|
|
||||||
return B_ERROR;
|
|
||||||
|
|
||||||
int32 size=sizeof(int8);
|
int32 size=sizeof(int8);
|
||||||
|
|
||||||
#ifdef CAPACITY_CHECKING
|
#ifdef CAPACITY_CHECKING
|
||||||
@@ -525,13 +487,13 @@ printf("Attach(%d)\n",data);
|
|||||||
PortLinkData *pld=new PortLinkData;
|
PortLinkData *pld=new PortLinkData;
|
||||||
if(pld->Set(&data,size)==B_OK)
|
if(pld->Set(&data,size)==B_OK)
|
||||||
{
|
{
|
||||||
num_attachments++;
|
attachlist->AddItem(pld);
|
||||||
attachments[num_attachments-1]=pld;
|
|
||||||
bufferlength+=size;
|
bufferlength+=size;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
delete pld;
|
delete pld;
|
||||||
|
return B_ERROR;
|
||||||
}
|
}
|
||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
@@ -541,10 +503,6 @@ status_t PortLink::Attach(float data)
|
|||||||
#ifdef PLDEBUG
|
#ifdef PLDEBUG
|
||||||
printf("Attach(%f)\n",data);
|
printf("Attach(%f)\n",data);
|
||||||
#endif
|
#endif
|
||||||
// Prevent parameter problems
|
|
||||||
if(num_attachments>=_PORTLINK_MAX_ATTACHMENTS)
|
|
||||||
return B_ERROR;
|
|
||||||
|
|
||||||
int32 size=sizeof(float);
|
int32 size=sizeof(float);
|
||||||
|
|
||||||
#ifdef CAPACITY_CHECKING
|
#ifdef CAPACITY_CHECKING
|
||||||
@@ -556,13 +514,13 @@ printf("Attach(%f)\n",data);
|
|||||||
PortLinkData *pld=new PortLinkData;
|
PortLinkData *pld=new PortLinkData;
|
||||||
if(pld->Set(&data,size)==B_OK)
|
if(pld->Set(&data,size)==B_OK)
|
||||||
{
|
{
|
||||||
num_attachments++;
|
attachlist->AddItem(pld);
|
||||||
attachments[num_attachments-1]=pld;
|
|
||||||
bufferlength+=size;
|
bufferlength+=size;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
delete pld;
|
delete pld;
|
||||||
|
return B_ERROR;
|
||||||
}
|
}
|
||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
@@ -572,9 +530,6 @@ status_t PortLink::Attach(bool data)
|
|||||||
#ifdef PLDEBUG
|
#ifdef PLDEBUG
|
||||||
printf("Attach(%s)\n",(data)?"true":"false");
|
printf("Attach(%s)\n",(data)?"true":"false");
|
||||||
#endif
|
#endif
|
||||||
// Prevent parameter problems
|
|
||||||
if(num_attachments>=_PORTLINK_MAX_ATTACHMENTS)
|
|
||||||
return B_ERROR;
|
|
||||||
|
|
||||||
int32 size=sizeof(bool);
|
int32 size=sizeof(bool);
|
||||||
|
|
||||||
@@ -587,13 +542,13 @@ printf("Attach(%s)\n",(data)?"true":"false");
|
|||||||
PortLinkData *pld=new PortLinkData;
|
PortLinkData *pld=new PortLinkData;
|
||||||
if(pld->Set(&data,size)==B_OK)
|
if(pld->Set(&data,size)==B_OK)
|
||||||
{
|
{
|
||||||
num_attachments++;
|
attachlist->AddItem(pld);
|
||||||
attachments[num_attachments-1]=pld;
|
|
||||||
bufferlength+=size;
|
bufferlength+=size;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
delete pld;
|
delete pld;
|
||||||
|
return B_ERROR;
|
||||||
}
|
}
|
||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
@@ -603,10 +558,6 @@ status_t PortLink::Attach(BRect data)
|
|||||||
#ifdef PLDEBUG
|
#ifdef PLDEBUG
|
||||||
printf("Attach(BRect(%f,%f,%f,%f))\n",data.left,data.top,data.right,data.bottom);
|
printf("Attach(BRect(%f,%f,%f,%f))\n",data.left,data.top,data.right,data.bottom);
|
||||||
#endif
|
#endif
|
||||||
// Prevent parameter problems
|
|
||||||
if(num_attachments>=_PORTLINK_MAX_ATTACHMENTS)
|
|
||||||
return B_ERROR;
|
|
||||||
|
|
||||||
int32 size=sizeof(BRect);
|
int32 size=sizeof(BRect);
|
||||||
|
|
||||||
#ifdef CAPACITY_CHECKING
|
#ifdef CAPACITY_CHECKING
|
||||||
@@ -618,13 +569,13 @@ printf("Attach(BRect(%f,%f,%f,%f))\n",data.left,data.top,data.right,data.bottom)
|
|||||||
PortLinkData *pld=new PortLinkData;
|
PortLinkData *pld=new PortLinkData;
|
||||||
if(pld->Set(&data,size)==B_OK)
|
if(pld->Set(&data,size)==B_OK)
|
||||||
{
|
{
|
||||||
num_attachments++;
|
attachlist->AddItem(pld);
|
||||||
attachments[num_attachments-1]=pld;
|
|
||||||
bufferlength+=size;
|
bufferlength+=size;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
delete pld;
|
delete pld;
|
||||||
|
return B_ERROR;
|
||||||
}
|
}
|
||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
@@ -634,10 +585,6 @@ status_t PortLink::Attach(BPoint data)
|
|||||||
#ifdef PLDEBUG
|
#ifdef PLDEBUG
|
||||||
printf("Attach(BPoint(%f,%f))\n",data.x,data.y);
|
printf("Attach(BPoint(%f,%f))\n",data.x,data.y);
|
||||||
#endif
|
#endif
|
||||||
// Prevent parameter problems
|
|
||||||
if(num_attachments>=_PORTLINK_MAX_ATTACHMENTS)
|
|
||||||
return B_ERROR;
|
|
||||||
|
|
||||||
int32 size=sizeof(BPoint);
|
int32 size=sizeof(BPoint);
|
||||||
|
|
||||||
#ifdef CAPACITY_CHECKING
|
#ifdef CAPACITY_CHECKING
|
||||||
@@ -649,13 +596,13 @@ printf("Attach(BPoint(%f,%f))\n",data.x,data.y);
|
|||||||
PortLinkData *pld=new PortLinkData;
|
PortLinkData *pld=new PortLinkData;
|
||||||
if(pld->Set(&data,size)==B_OK)
|
if(pld->Set(&data,size)==B_OK)
|
||||||
{
|
{
|
||||||
num_attachments++;
|
attachlist->AddItem(pld);
|
||||||
attachments[num_attachments-1]=pld;
|
|
||||||
bufferlength+=size;
|
bufferlength+=size;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
delete pld;
|
delete pld;
|
||||||
|
return B_ERROR;
|
||||||
}
|
}
|
||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
@@ -680,9 +627,10 @@ printf("PortLink::FlattenData: bufferlength<1\n");
|
|||||||
PortLinkData *pld;
|
PortLinkData *pld;
|
||||||
*size=0;
|
*size=0;
|
||||||
|
|
||||||
for(int i=0;i<num_attachments;i++)
|
int32 count=attachlist->CountItems();
|
||||||
|
for(int i=0;i<count;i++)
|
||||||
{
|
{
|
||||||
pld=attachments[i];
|
pld=(PortLinkData*)attachlist->ItemAt(i);
|
||||||
memcpy(bufferindex, pld->buffer, pld->buffersize);
|
memcpy(bufferindex, pld->buffer, pld->buffersize);
|
||||||
bufferindex += pld->buffersize;
|
bufferindex += pld->buffersize;
|
||||||
*size+=pld->buffersize;
|
*size+=pld->buffersize;
|
||||||
@@ -695,14 +643,15 @@ void PortLink::MakeEmpty(void)
|
|||||||
printf("PortLink::MakeEmpty\n");
|
printf("PortLink::MakeEmpty\n");
|
||||||
#endif
|
#endif
|
||||||
// Nukes all the attachments currently held by the PortLink class
|
// Nukes all the attachments currently held by the PortLink class
|
||||||
if(num_attachments!=0)
|
PortLinkData *pld;
|
||||||
|
int32 count=attachlist->CountItems();
|
||||||
|
for(int32 i=0; i<count; i++)
|
||||||
{
|
{
|
||||||
for(int i=0; i<num_attachments; i++)
|
pld=(PortLinkData*)attachlist->ItemAt(i);
|
||||||
{
|
if(pld)
|
||||||
delete attachments[i];
|
delete pld;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
num_attachments=0;
|
attachlist->MakeEmpty();
|
||||||
bufferlength=0;
|
bufferlength=0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user