Experiment with transmitting large UDP massages
This commit is contained in:
parent
ad0434c415
commit
b76e031b30
@ -19,6 +19,7 @@
|
||||
#include <stdio.h>
|
||||
#include <fcntl.h>
|
||||
#include <sys/types.h>
|
||||
#include <iostream>
|
||||
|
||||
#if !defined (WIN32) || defined(__CYGWIN__)
|
||||
#include <sys/ioctl.h>
|
||||
@ -209,6 +210,7 @@ void Broadcaster::sync( void )
|
||||
#else
|
||||
unsigned int size = sizeof( struct sockaddr_in );
|
||||
sendto( _so, (const void *)_buffer, _buffer_size, 0, (struct sockaddr *)&saddr, size );
|
||||
std::cout<<"sento("<<_buffer<<", "<<_buffer_size<<std::endl;
|
||||
#endif
|
||||
|
||||
}
|
||||
|
@ -461,7 +461,7 @@ int main( int argc, char **argv )
|
||||
arguments.getApplicationUsage()->addCommandLineOption("-o <float>","Offset angle of camera");
|
||||
|
||||
// construct the viewer.
|
||||
osgViewer::Viewer viewer;
|
||||
osgViewer::Viewer viewer(arguments);
|
||||
|
||||
|
||||
// read up the osgcluster specific arguments.
|
||||
@ -469,6 +469,13 @@ int main( int argc, char **argv )
|
||||
while (arguments.read("-m")) viewerMode = MASTER;
|
||||
while (arguments.read("-s")) viewerMode = SLAVE;
|
||||
|
||||
unsigned int messageSize = 1024;
|
||||
while (arguments.read("--size", messageSize)) {}
|
||||
|
||||
|
||||
bool readWriteFrame = false;
|
||||
while (arguments.read("--frame")) readWriteFrame = true;
|
||||
|
||||
int socketNumber=8100;
|
||||
while (arguments.read("-n",socketNumber)) ;
|
||||
|
||||
@ -549,13 +556,40 @@ int main( int argc, char **argv )
|
||||
// create the windows and run the threads.
|
||||
viewer.realize();
|
||||
|
||||
osg::ref_ptr<osg::Image> image;
|
||||
if (readWriteFrame)
|
||||
{
|
||||
osgViewer::Viewer::Windows windows;
|
||||
viewer.getWindows(windows);
|
||||
|
||||
if (windows.empty())
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
unsigned int width = windows.front()->getTraits()->width;
|
||||
unsigned int height = windows.front()->getTraits()->height;
|
||||
image = new osg::Image;
|
||||
|
||||
if (windows.front()->getTraits()->alpha)
|
||||
{
|
||||
OSG_NOTICE<<"Setting up RGBA osg::Image, width = "<<width<<", height = "<<height<<std::endl;
|
||||
image->allocateImage(width, height, 1, GL_RGBA, GL_UNSIGNED_BYTE);
|
||||
}
|
||||
else
|
||||
{
|
||||
OSG_NOTICE<<"Setting up RGB osg::Image, width = "<<width<<", height = "<<height<<std::endl;
|
||||
image->allocateImage(width, height, 1, GL_RGB, GL_UNSIGNED_BYTE);
|
||||
}
|
||||
|
||||
// if (image->getImageStepInBytes()>messageSize) messageSize = image->getImageStepInBytes();
|
||||
}
|
||||
|
||||
CameraPacket *cp = new CameraPacket;
|
||||
|
||||
|
||||
bool masterKilled = false;
|
||||
|
||||
DataConverter scratchPad(1024);
|
||||
DataConverter scratchPad(messageSize);
|
||||
|
||||
while( !viewer.done() && !masterKilled )
|
||||
{
|
||||
@ -584,10 +618,15 @@ int main( int argc, char **argv )
|
||||
|
||||
bc.setBuffer(scratchPad._startPtr, scratchPad._numBytes);
|
||||
|
||||
std::cout << "bc.sync()"<<scratchPad._numBytes<<std::endl;
|
||||
|
||||
bc.sync();
|
||||
|
||||
if (image.valid())
|
||||
{
|
||||
bc.setBuffer(image->data(), image->getImageStepInBytes());
|
||||
bc.sync();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
break;
|
||||
case(SLAVE):
|
||||
@ -595,7 +634,9 @@ int main( int argc, char **argv )
|
||||
|
||||
rc.setBuffer(scratchPad._startPtr, scratchPad._numBytes);
|
||||
|
||||
rc.sync();
|
||||
unsigned int readsize = rc.sync();
|
||||
|
||||
if (readsize) std::cout<<std::endl<<"readsize = "<<readsize<<std::endl;
|
||||
|
||||
scratchPad.reset();
|
||||
scratchPad.read(*cp);
|
||||
@ -608,6 +649,14 @@ int main( int argc, char **argv )
|
||||
// break out of while (!done) loop since we've now want to shut down.
|
||||
masterKilled = true;
|
||||
}
|
||||
|
||||
if (image)
|
||||
{
|
||||
rc.setBuffer(image->data(), image->getImageStepInBytes());
|
||||
readsize = rc.sync();
|
||||
if (readsize) std::cout<<"image readsize = "<<readsize<<std::endl;
|
||||
}
|
||||
|
||||
}
|
||||
break;
|
||||
default:
|
||||
|
@ -112,14 +112,14 @@ void Receiver::setBuffer( void *buffer, const unsigned int size )
|
||||
_buffer_size = size;
|
||||
}
|
||||
|
||||
void Receiver::sync( void )
|
||||
unsigned int Receiver::sync( void )
|
||||
{
|
||||
if(!_initialized) init();
|
||||
|
||||
if( _buffer == 0L )
|
||||
{
|
||||
fprintf( stderr, "Receiver::sync() - No buffer\n" );
|
||||
return;
|
||||
return 0;
|
||||
}
|
||||
|
||||
#if defined(__linux) || defined(__FreeBSD__) || defined( __APPLE__ ) || defined(__FreeBSD_kernel__) || defined(__GNU__)
|
||||
@ -161,5 +161,6 @@ void Receiver::sync( void )
|
||||
}
|
||||
}
|
||||
#endif
|
||||
return static_cast<unsigned int>(_buffer_size);
|
||||
}
|
||||
|
||||
|
@ -47,7 +47,7 @@ class Receiver
|
||||
void setPort( const short port );
|
||||
|
||||
// Sync does a blocking wait to recieve next message
|
||||
void sync( void );
|
||||
unsigned int sync( void );
|
||||
|
||||
private :
|
||||
bool init( void );
|
||||
|
Loading…
Reference in New Issue
Block a user