[omniORB] Re: Getting client IP address in server + example interceptors

Brecht Vermeulen brecht.vermeulen@rug.ac.be
Thu, 14 Feb 2002 16:11:15 +0100


so, now the cross platform version (thanks Duncan for pointing this out
!), with omni_thread class instead of pthread specific functions (this
was my first use of omnithread, so I hope it is fairly correct):

insert this in eg2_impl:

// For interceptors
#include <omniORB4/omniInterceptors.h>

// Thread specific data
#include <omnithread.h>
omni_thread::key_t key;

// Specifically for use of info in giop_s in
serverReceiveRequest_T::info_T
#include <giopStrand.h>
#include <giopStream.h>
#include <GIOP_S.h>

class clientaddress : public omni_thread::value_t {
public:
	clientaddress(const char * const client) {
		_client = new char [strlen(client)+1];
		strcpy(_client, client);
	};
	
	~clientaddress() { 
		cout << "Delete thread specific data :" << _client << endl;
		delete[] _client; };
	
	char *address() { return _client;};
private:
	char *_client;
};

CORBA::Boolean
testfunc(omni::omniInterceptors::serverReceiveRequest_T::info_T& info) {
	cout << "Operation name : " << info.giop_s.operation_name() << endl;
	cout << "Peer (client) address : " << ( (omni::giopStrand&)info.giop_s
).connection->peeraddress() << endl;
	cout << "My (server) address : " << ( (omni::giopStrand&)info.giop_s
).connection->myaddress() << endl;
	omni_thread::self()->set_value(key, new
clientaddress(((omni::giopStrand&)info.giop_s).connection->peeraddress()
));
	return true;
}


before poa_manager->activate:

key = omni_thread::allocate_key();
omniORB::getInterceptors()->serverReceiveRequest.add(&testfunc);


and in the IDL operation:
  cout << "echoString: client address : " << (
(clientaddress*)omni_thread::self()->get_value(key))->address() << endl;
 
regards,
Brecht


Duncan Grisby wrote:
> 
> On Thursday 14 February, Brecht Vermeulen wrote:
> 
> > // Thread specific data
> > pthread_key_t key;
> 
> omniORB 4's omnithread has its own support for thread-specific data,
> so you can actually implement what you want in a cross platform way.
> Look at omnithread.h for the interface.
> 
> > // This poses the question: wouldn't it be interesting to add these to
> > omni/include/omniORB4, just as
> > // omniInterceptors.h ??, now you need the source code to compile this
> > (or you have to copy these header files)
> > #include <giopStrand.h>
> [...]
> 
> I'm finally on the verge of getting autoconf support going. As part of
> that, the internal headers will be installed as something like
> include/omniORB4/internal, so they will be accessible without the
> source distribution.
> 
> Cheers,
> 
> Duncan.
> 
> --
>  -- Duncan Grisby  \  Research Engineer  --
>   -- AT&T Laboratories Cambridge          --
>    -- http://www.uk.research.att.com/~dpg1 --