Eliminated a memory allocation bug
Added a sensible workaround for BSession message code packaging git-svn-id: file:///srv/svn/repos/haiku/trunk/current@4937 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
parent
e956d70682
commit
8123b61c01
@ -1,4 +1,3 @@
|
||||
#include <malloc.h>
|
||||
#include <ServerProtocol.h>
|
||||
#include "PortLink.h"
|
||||
#include "PortMessage.h"
|
||||
@ -12,7 +11,7 @@ PortLink::PortLink(port_id port)
|
||||
fReceivePort=create_port(30,"PortLink reply port");
|
||||
|
||||
fSendCode=0;
|
||||
fSendBuffer=(char*)malloc(4096);
|
||||
fSendBuffer=new char[4096];
|
||||
fSendPosition=4;
|
||||
}
|
||||
|
||||
@ -24,10 +23,15 @@ PortLink::PortLink( const PortLink &link )
|
||||
fReceivePort=create_port(30,"PortLink reply port");
|
||||
|
||||
fSendCode = 0;
|
||||
fSendBuffer = (char*)malloc(4096);
|
||||
fSendBuffer=new char[4096];
|
||||
fSendPosition = 4;
|
||||
}
|
||||
|
||||
PortLink::~PortLink(void)
|
||||
{
|
||||
delete [] fSendBuffer;
|
||||
}
|
||||
|
||||
void PortLink::SetOpCode( int32 code )
|
||||
{
|
||||
fSendCode=code;
|
||||
@ -104,7 +108,8 @@ status_t PortLink::FlushWithReply( PortMessage *msg,bigtime_t timeout=B_INFINITE
|
||||
// We got this far, so we apparently have some data
|
||||
msg->SetCode(rcode);
|
||||
msg->SetBuffer(rbuffer,rbuffersize,false);
|
||||
|
||||
msg->BSessionWorkaround();
|
||||
|
||||
return B_OK;
|
||||
}
|
||||
|
||||
@ -123,6 +128,6 @@ status_t PortLink::Attach(const void *data, size_t size)
|
||||
|
||||
void PortLink::MakeEmpty()
|
||||
{
|
||||
fSendPosition = 4;
|
||||
fSendPosition=4;
|
||||
}
|
||||
|
||||
|
@ -34,6 +34,7 @@ PortMessage::PortMessage(const int32 &code, const void *buffer, const ssize_t &b
|
||||
{
|
||||
_code=code;
|
||||
SetBuffer(buffer,buffersize,copy);
|
||||
is_session_msg=false;
|
||||
}
|
||||
|
||||
PortMessage::PortMessage(void)
|
||||
@ -42,6 +43,7 @@ PortMessage::PortMessage(void)
|
||||
_buffer=NULL;
|
||||
_buffersize=0;
|
||||
_index=NULL;
|
||||
is_session_msg=false;
|
||||
}
|
||||
|
||||
PortMessage::~PortMessage(void)
|
||||
@ -59,6 +61,7 @@ status_t PortMessage::ReadFromPort(const port_id &port, const bigtime_t &timeout
|
||||
_index=NULL;
|
||||
_buffersize=0;
|
||||
|
||||
is_session_msg=false;
|
||||
if(timeout==B_INFINITE_TIMEOUT)
|
||||
{
|
||||
_buffersize=port_buffer_size(port);
|
||||
@ -81,6 +84,7 @@ status_t PortMessage::ReadFromPort(const port_id &port, const bigtime_t &timeout
|
||||
read_port(port, &_code, _buffer, _buffersize);
|
||||
}
|
||||
_index=_buffer;
|
||||
BSessionWorkaround();
|
||||
|
||||
return B_OK;
|
||||
}
|
||||
@ -89,6 +93,7 @@ status_t PortMessage::WriteToPort(const port_id &port)
|
||||
{
|
||||
// Check port validity
|
||||
port_info pi;
|
||||
is_session_msg=false;
|
||||
if(get_port_info(port,&pi)!=B_OK)
|
||||
return B_BAD_VALUE;
|
||||
|
||||
@ -138,8 +143,7 @@ status_t PortMessage::Read(void *data, ssize_t size)
|
||||
if(!data || size<1)
|
||||
return B_BAD_VALUE;
|
||||
|
||||
if( !_buffer ||
|
||||
_buffersize<size ||
|
||||
if( !_buffer || _buffersize<size ||
|
||||
((_index+size)>(_buffer+_buffersize)) )
|
||||
return B_NO_MEMORY;
|
||||
|
||||
@ -151,6 +155,20 @@ status_t PortMessage::Read(void *data, ssize_t size)
|
||||
|
||||
void PortMessage::Rewind(void)
|
||||
{
|
||||
_index=_buffer;
|
||||
_index=(is_session_msg)?_buffer+4:_buffer;
|
||||
}
|
||||
|
||||
|
||||
void PortMessage::BSessionWorkaround(void)
|
||||
{
|
||||
// Do some stuff to work around BSession stupidity with packaging the message code as
|
||||
// the first attachment in the message's data buffer.
|
||||
if(_code==AS_SERVER_SESSION)
|
||||
{
|
||||
is_session_msg=true;
|
||||
_index+=4;
|
||||
_code=*((int32*)_buffer);
|
||||
}
|
||||
else
|
||||
is_session_msg=false;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user