BSession no longer a parent class
Removed deprecated reply functions Global protocol change - reply port attached last, not first Still uses BSession-style messaging (msg code attached to buffer followed by attachement data) git-svn-id: file:///srv/svn/repos/haiku/trunk/current@4935 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
+54
-145
@@ -1,180 +1,87 @@
|
|||||||
#include <malloc.h>
|
#include <malloc.h>
|
||||||
|
#include <ServerProtocol.h>
|
||||||
#include "PortLink.h"
|
#include "PortLink.h"
|
||||||
#include "PortMessage.h"
|
#include "PortMessage.h"
|
||||||
|
|
||||||
PortLink::PortLink( port_id port)
|
PortLink::PortLink(port_id port)
|
||||||
: BSession( 0, 0, true )
|
|
||||||
{
|
{
|
||||||
|
port_info pi;
|
||||||
|
port_ok = (get_port_info(port, &pi)==B_OK)? true: false;
|
||||||
|
|
||||||
port_info pi;
|
fSendPort=port;
|
||||||
port_ok = (get_port_info(port, &pi) == B_OK)? true: false;
|
fReceivePort=create_port(30,"PortLink reply port");
|
||||||
|
|
||||||
fSendPort = port;
|
fSendCode=0;
|
||||||
fReceivePort = create_port(30,"PortLink reply port");
|
fSendBuffer=(char*)malloc(4096);
|
||||||
|
fSendPosition=4;
|
||||||
fSendCode = 0;
|
|
||||||
fSendBuffer = NULL;
|
|
||||||
fSendPosition = 4;
|
|
||||||
|
|
||||||
fReceiveBuffer = NULL;
|
|
||||||
fReceiveSize = 0;
|
|
||||||
fReceivePosition = 0;
|
|
||||||
|
|
||||||
fSendBuffer = (char*)malloc(4096);
|
|
||||||
//fReceiveBuffer = (char*)malloc(4096);
|
|
||||||
}
|
}
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
PortLink::PortLink( const PortLink &link )
|
PortLink::PortLink( const PortLink &link )
|
||||||
: BSession( 0, 0, true )
|
|
||||||
{
|
{
|
||||||
port_ok = link.port_ok;
|
port_ok=link.port_ok;
|
||||||
|
|
||||||
fSendPort = link.fSendPort;
|
fSendPort=link.fSendPort;
|
||||||
fReceivePort = create_port(30,"PortLink reply port");
|
fReceivePort=create_port(30,"PortLink reply port");
|
||||||
|
|
||||||
fSendCode = 0;
|
fSendCode = 0;
|
||||||
fSendBuffer = NULL;
|
|
||||||
fSendPosition = 4;
|
|
||||||
|
|
||||||
fReceiveBuffer = NULL;
|
|
||||||
fReceiveSize = 0;
|
|
||||||
fReceivePosition = 0;
|
|
||||||
|
|
||||||
fSendBuffer = (char*)malloc(4096);
|
fSendBuffer = (char*)malloc(4096);
|
||||||
//fReceiveBuffer = (char*)malloc(4096);
|
fSendPosition = 4;
|
||||||
|
}
|
||||||
|
|
||||||
|
void PortLink::SetOpCode( int32 code )
|
||||||
|
{
|
||||||
|
fSendCode=code;
|
||||||
|
int32 *cast=(int32*)fSendBuffer;
|
||||||
|
*cast=code;
|
||||||
}
|
}
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
void PortLink::SetOpCode( int32 code ){
|
void PortLink::SetPort( port_id port )
|
||||||
fSendCode = code;
|
{
|
||||||
}
|
port_info pi;
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
void PortLink::SetPort( port_id port ){
|
|
||||||
port_info pi;
|
|
||||||
|
|
||||||
fSendPort = port;
|
fSendPort=port;
|
||||||
port_ok = (get_port_info(port, &pi) == B_OK)? true: false;
|
port_ok=(get_port_info(port, &pi) == B_OK)? true: false;
|
||||||
}
|
}
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
port_id PortLink::GetPort(){
|
port_id PortLink::GetPort()
|
||||||
|
{
|
||||||
return fSendPort;
|
return fSendPort;
|
||||||
}
|
}
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
status_t PortLink::Flush( bigtime_t timeout = B_INFINITE_TIMEOUT ){
|
status_t PortLink::Flush(bigtime_t timeout=B_INFINITE_TIMEOUT)
|
||||||
|
{
|
||||||
status_t write_stat;
|
status_t write_stat;
|
||||||
|
|
||||||
if(!port_ok) {
|
if(!port_ok)
|
||||||
return B_BAD_VALUE;
|
return B_BAD_VALUE;
|
||||||
}
|
|
||||||
|
|
||||||
if( timeout != B_INFINITE_TIMEOUT )
|
|
||||||
write_stat = write_port_etc(fSendPort, fSendCode, fSendBuffer + 4,
|
|
||||||
fSendPosition - 4 , B_TIMEOUT, timeout);
|
|
||||||
else
|
|
||||||
write_stat = write_port( fSendPort, fSendCode, fSendBuffer + 4,
|
|
||||||
fSendPosition - 4 );
|
|
||||||
|
|
||||||
fSendPosition = 4;
|
if(timeout!=B_INFINITE_TIMEOUT)
|
||||||
|
write_stat=write_port_etc(fSendPort, AS_SERVER_SESSION, fSendBuffer,
|
||||||
|
fSendPosition, B_TIMEOUT, timeout);
|
||||||
|
else
|
||||||
|
write_stat=write_port(fSendPort, AS_SERVER_SESSION, fSendBuffer, fSendPosition);
|
||||||
|
|
||||||
|
fSendPosition=4;
|
||||||
|
|
||||||
return write_stat;
|
return write_stat;
|
||||||
}
|
}
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
int8* PortLink::FlushWithReply(int32 *code, status_t *status, ssize_t *buffersize,
|
|
||||||
bigtime_t timeout=B_INFINITE_TIMEOUT)
|
|
||||||
{
|
|
||||||
if(!port_ok){
|
|
||||||
*status = B_BAD_VALUE;
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
// attach our port_id first
|
status_t PortLink::FlushWithReply( PortMessage *msg,bigtime_t timeout=B_INFINITE_TIMEOUT )
|
||||||
*((int32*)fSendBuffer) = fReceivePort;
|
|
||||||
|
|
||||||
// Flush the thing....FOOSH! :P
|
|
||||||
write_port(fSendPort, fSendCode, fSendBuffer, fSendPosition);
|
|
||||||
fSendPosition = 4;
|
|
||||||
|
|
||||||
// Now we wait for the reply
|
|
||||||
int8 *buffer = NULL;
|
|
||||||
if( timeout == B_INFINITE_TIMEOUT )
|
|
||||||
{
|
|
||||||
*buffersize = port_buffer_size(fReceivePort);
|
|
||||||
if( *buffersize > 0 )
|
|
||||||
buffer = new int8[*buffersize];
|
|
||||||
read_port( fReceivePort, code, buffer, *buffersize);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
*buffersize = port_buffer_size_etc( fReceivePort, 0, timeout);
|
|
||||||
if( *buffersize == B_TIMED_OUT )
|
|
||||||
{
|
|
||||||
*status = *buffersize;
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
if( *buffersize > 0 )
|
|
||||||
buffer = new int8[*buffersize];
|
|
||||||
read_port(fReceivePort, code, buffer, *buffersize);
|
|
||||||
}
|
|
||||||
|
|
||||||
// We got this far, so we apparently have some data
|
|
||||||
*status = B_OK;
|
|
||||||
return buffer;
|
|
||||||
}
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
status_t PortLink::FlushWithReply( PortLink::ReplyData *data,
|
|
||||||
bigtime_t timeout=B_INFINITE_TIMEOUT )
|
|
||||||
{
|
|
||||||
if(!port_ok || !data)
|
|
||||||
return B_BAD_VALUE;
|
|
||||||
|
|
||||||
// attach our port_id first
|
|
||||||
*((int32*)fSendBuffer) = fReceivePort;
|
|
||||||
|
|
||||||
// Flush the thing....FOOSH! :P
|
|
||||||
write_port(fSendPort, fSendCode, fSendBuffer, fSendPosition);
|
|
||||||
fSendPosition = 4;
|
|
||||||
|
|
||||||
// Now we wait for the reply
|
|
||||||
if( timeout == B_INFINITE_TIMEOUT )
|
|
||||||
{
|
|
||||||
data->buffersize = port_buffer_size(fReceivePort);
|
|
||||||
if( data->buffersize > 0 )
|
|
||||||
data->buffer = new int8[data->buffersize];
|
|
||||||
read_port( fReceivePort, &(data->code), data->buffer, data->buffersize);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
data->buffersize = port_buffer_size_etc( fReceivePort, 0, timeout);
|
|
||||||
if( data->buffersize == B_TIMED_OUT )
|
|
||||||
return B_TIMED_OUT;
|
|
||||||
|
|
||||||
if( data->buffersize > 0 )
|
|
||||||
data->buffer = new int8[data->buffersize];
|
|
||||||
read_port( fReceivePort, &(data->code), data->buffer, data->buffersize);
|
|
||||||
}
|
|
||||||
|
|
||||||
// We got this far, so we apparently have some data
|
|
||||||
return B_OK;
|
|
||||||
}
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
status_t PortLink::FlushWithReply( PortMessage *msg,
|
|
||||||
bigtime_t timeout=B_INFINITE_TIMEOUT )
|
|
||||||
{
|
{
|
||||||
if(!port_ok || !msg)
|
if(!port_ok || !msg)
|
||||||
return B_BAD_VALUE;
|
return B_BAD_VALUE;
|
||||||
|
|
||||||
// attach our port_id first
|
// attach our reply port_id at the end
|
||||||
*((int32*)fSendBuffer) = fReceivePort;
|
Attach<int32>(fReceivePort);
|
||||||
|
|
||||||
// Flush the thing....FOOSH! :P
|
// Flush the thing....FOOSH! :P
|
||||||
write_port(fSendPort, fSendCode, fSendBuffer, fSendPosition);
|
write_port(fSendPort, fSendCode, fSendBuffer, fSendPosition);
|
||||||
fSendPosition = 4;
|
fSendPosition = 4;
|
||||||
|
|
||||||
// Now we wait for the reply
|
// Now we wait for the reply
|
||||||
ssize_t rbuffersize;
|
ssize_t rbuffersize;
|
||||||
int8 *rbuffer = NULL;
|
int8 *rbuffer = NULL;
|
||||||
int32 rcode;
|
int32 rcode;
|
||||||
|
|
||||||
if( timeout == B_INFINITE_TIMEOUT )
|
if( timeout == B_INFINITE_TIMEOUT )
|
||||||
{
|
{
|
||||||
@@ -190,7 +97,7 @@ status_t PortLink::FlushWithReply( PortMessage *msg,
|
|||||||
return B_TIMED_OUT;
|
return B_TIMED_OUT;
|
||||||
|
|
||||||
if( rbuffersize > 0 )
|
if( rbuffersize > 0 )
|
||||||
rbuffer = new int8[rbuffersize];
|
rbuffer = new int8[rbuffersize];
|
||||||
read_port( fReceivePort, &rcode, rbuffer, rbuffersize);
|
read_port( fReceivePort, &rcode, rbuffer, rbuffersize);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -200,8 +107,9 @@ status_t PortLink::FlushWithReply( PortMessage *msg,
|
|||||||
|
|
||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
status_t PortLink::Attach(const void *data, size_t size){
|
status_t PortLink::Attach(const void *data, size_t size)
|
||||||
|
{
|
||||||
if (size <= 0)
|
if (size <= 0)
|
||||||
return B_ERROR;
|
return B_ERROR;
|
||||||
|
|
||||||
@@ -212,8 +120,9 @@ status_t PortLink::Attach(const void *data, size_t size){
|
|||||||
}
|
}
|
||||||
return B_NO_MEMORY;
|
return B_NO_MEMORY;
|
||||||
}
|
}
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
void PortLink::MakeEmpty(){
|
void PortLink::MakeEmpty()
|
||||||
|
{
|
||||||
fSendPosition = 4;
|
fSendPosition = 4;
|
||||||
}
|
}
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
|
|||||||
Reference in New Issue
Block a user