Updates to sync with (hopefully) final tweaks to messaging protocols

Implemented BSession::DropInputBuffer with code from Adi


git-svn-id: file:///srv/svn/repos/haiku/trunk/current@5013 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
DarkWyrm 2003-10-13 23:34:12 +00:00
parent fb7da50d34
commit 83f9647173
4 changed files with 33 additions and 36 deletions

View File

@ -60,7 +60,7 @@
// Local Defines ---------------------------------------------------------------
// Uncomment this to run without the registrar - used only for app_server development!
//#define RUN_WITHOUT_REGISTRAR
#define RUN_WITHOUT_REGISTRAR
// Globals ---------------------------------------------------------------------

View File

@ -38,7 +38,9 @@ PortLink::PortLink(port_id port)
fSendCode=0;
fSendBuffer=new char[4096];
fSendPosition=4;
fSendPosition=8;
fDataSize=(int32*)fSendBuffer+sizeof(int32);
*fDataSize=0;
}
PortLink::PortLink( const PortLink &link )
@ -50,7 +52,9 @@ PortLink::PortLink( const PortLink &link )
fSendCode = 0;
fSendBuffer=new char[4096];
fSendPosition = 4;
fSendPosition = 8;
fDataSize=(int32*)fSendBuffer+sizeof(int32);
*fDataSize=0;
}
PortLink::~PortLink(void)
@ -86,12 +90,13 @@ status_t PortLink::Flush(bigtime_t timeout=B_INFINITE_TIMEOUT)
return B_BAD_VALUE;
if(timeout!=B_INFINITE_TIMEOUT)
write_stat=write_port_etc(fSendPort, fSendCode, fSendBuffer,
write_stat=write_port_etc(fSendPort, AS_SERVER_PORTLINK, fSendBuffer,
fSendPosition, B_TIMEOUT, timeout);
else
write_stat=write_port(fSendPort, fSendCode, fSendBuffer, fSendPosition);
write_stat=write_port(fSendPort, AS_SERVER_PORTLINK, fSendBuffer, fSendPosition);
fSendPosition=4;
fSendPosition=8;
*fDataSize=0;
return write_stat;
}
@ -105,30 +110,12 @@ status_t PortLink::FlushWithReply( PortMessage *msg,bigtime_t timeout=B_INFINITE
Attach<int32>(fReceivePort);
// Flush the thing....FOOSH! :P
write_port(fSendPort, fSendCode, fSendBuffer, fSendPosition);
fSendPosition = 4;
write_port(fSendPort, AS_SERVER_PORTLINK, fSendBuffer, fSendPosition);
fSendPosition = 8;
*fDataSize=0;
// Now we wait for the reply
ssize_t rbuffersize;
int8 *rbuffer = NULL;
int32 rcode;
if( timeout == B_INFINITE_TIMEOUT )
rbuffersize = port_buffer_size(fReceivePort);
else
{
rbuffersize = port_buffer_size_etc( fReceivePort, 0, timeout);
if( rbuffersize == B_TIMED_OUT )
return B_TIMED_OUT;
}
if( rbuffersize > 0 )
rbuffer = new int8[rbuffersize];
read_port( fReceivePort, &rcode, rbuffer, rbuffersize);
// We got this far, so we apparently have some data
msg->SetCode(rcode);
msg->SetBuffer(rbuffer,rbuffersize,false);
msg->ReadFromPort(fReceivePort,timeout);
return B_OK;
}
@ -138,9 +125,11 @@ status_t PortLink::Attach(const void *data, size_t size)
if (size <= 0)
return B_ERROR;
if (4096 - fSendPosition > (int32)size){
if (4096 - fSendPosition > (int32)size)
{
memcpy(fSendBuffer + fSendPosition, data, size);
fSendPosition += size;
*fDataSize+=size;
return B_OK;
}
return B_NO_MEMORY;
@ -156,6 +145,7 @@ status_t PortLink::AttachString(const char *string)
void PortLink::MakeEmpty()
{
fSendPosition=4;
fSendPosition=8;
*fDataSize=0;
}

View File

@ -36,12 +36,14 @@ PortMessage::PortMessage(const int32 &code, const void *buffer, const ssize_t &b
const bool &copy)
{
_code=code;
_protocol=AS_SERVER_PORTLINK;
SetBuffer(buffer,buffersize,copy);
}
PortMessage::PortMessage(void)
{
_code=0;
_protocol=AS_SERVER_PORTLINK;
_buffer=NULL;
_buffersize=0;
_index=NULL;
@ -77,9 +79,11 @@ status_t PortMessage::ReadFromPort(const port_id &port, const bigtime_t &timeout
if(_buffersize>0)
_buffer=new uint8[_buffersize];
read_port(port, &_code, _buffer, _buffersize);
read_port(port, &_protocol, _buffer, _buffersize);
if(_buffer)
_code=*((int32*)_buffer);
_index=_buffer+4;
_index=_buffer+8;
return B_OK;
}
@ -94,7 +98,7 @@ status_t PortMessage::WriteToPort(const port_id &port)
int32 *cast=(int32*)_buffer;
*cast=_code;
write_port(port,_code, _buffer, _buffersize);
write_port(port, AS_SERVER_PORTLINK, _buffer, _buffersize);
if(_buffer && _buffersize>0)
{
@ -132,7 +136,7 @@ void PortMessage::SetBuffer(const void *buffer, const ssize_t &size, const bool
_buffersize=size;
_buffer=(uint8 *)buffer;
}
_index=_buffer+4;
_index=_buffer+8;
}
status_t PortMessage::Read(void *data, ssize_t size)
@ -152,7 +156,7 @@ status_t PortMessage::Read(void *data, ssize_t size)
void PortMessage::Rewind(void)
{
_index=_buffer+4;
_index=_buffer+8;
}
status_t PortMessage::ReadString(char **string)

View File

@ -54,7 +54,10 @@ void BSession::SetRecvPort( port_id port ){
}
//------------------------------------------------------------------------------
bool BSession::DropInputBuffer(void){
// TODO: Implement
// doesn't matter their value, they just need to be equal.
fReceiveSize = 1024;
fReceivePosition = 1024;
return true;
}
//------------------------------------------------------------------------------
void BSession::SetMsgCode(int32 code){