00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include "TOutputObjectSocket.hh"
00025 #include "TStreamableObject.hh"
00026 #include "TOutputObjectFilter.hh"
00027
00028 TOutputObjectSocket::TOutputObjectSocket( const Tstring& hostname, Tint port )
00029 : TObjectSocket( port ), TOutputObjectStream( tSocketStream ),
00030 theServerName( hostname ), theHostInformation( 0 )
00031 {
00032 initialize();
00033 }
00034
00035 TOutputObjectSocket::TOutputObjectSocket( Tint port )
00036 : TObjectSocket( port ), TOutputObjectStream( tSocketStream ),
00037 theServerName( "localhost" ), theHostInformation( 0 )
00038 {
00039 initialize();
00040 }
00041
00042 TOutputObjectSocket::TOutputObjectSocket( TOutputObjectFilter* filter, const Tstring& hostname, Tint port )
00043 : TObjectSocket( port ), TOutputObjectStream( filter, tSocketStream ),
00044 theServerName( hostname ), theHostInformation( 0 )
00045 {
00046 initialize();
00047 }
00048
00049 TOutputObjectSocket::TOutputObjectSocket( TOutputObjectFilter* filter, Tint port )
00050 : TObjectSocket( port ), TOutputObjectStream( filter, tSocketStream ),
00051 theServerName( "localhost" ), theHostInformation( 0 )
00052 {
00053 initialize();
00054 }
00055
00056 TOutputObjectSocket::~TOutputObjectSocket()
00057 {
00058 CloseServer();
00059 }
00060
00061 Tvoid TOutputObjectSocket::initialize()
00062 {
00063 theHostInformation = gethostbyname( theServerName.c_str() );
00064 if ( theHostInformation == 0 ) {
00065 perror( "TOutputObjectSocket::initialize" );
00066 exit( -errno );
00067 }
00068 theAddress.sin_family = PF_INET;
00069 theAddress.sin_port = htons( (TUshort)thePortNumber );
00070 theAddress.sin_addr.s_addr =
00071 *( (unsigned long *)( *( theHostInformation -> h_addr_list ) ) );
00072
00073 OpenServer();
00074 Tsocklen_t len = (Tsocklen_t)( Tsizeof( theAddress ) );
00075
00076 if ( connect( theServerDescriptor, (struct sockaddr *)&theAddress, len ) == -1 )
00077 perror( "TOutputObjectSocket::initialize" );
00078
00079
00080 return;
00081 }
00082
00083 Tint TOutputObjectSocket::Write( TStreamableObject& object )
00084 {
00085 if ( HasFilter() ) {
00086 return theObjectFilter -> Filtering( object, this );
00087 }
00088
00089 theLastDataSize = theDataSize;
00090 theDataSize = 0;
00091 theDataSize = object.Record( this );
00092 theTotalDataSize += theDataSize;
00093
00094 return theDataSize;
00095 }
00096
00097 #ifdef __CLDAQ_ROOT_DLL
00098 ClassImp(TOutputObjectSocket)
00099 #endif