ADAPTIVECommunicationEnvironmentDouglasC.Schmidtschmidt@cs.wustl.edu(314)935-7538Smile,yfang76@hotmail.comACEACEUNIXWin32ACE11.1MFCGUIOCXsocketsTLIXwindowsSunRPCAPIsocketsTLIOO1.2recurringReactorActiveObjectfamiliesOO2ACE3ACEC++ACE4ACE52ACEOOACEACEOOwrappersACElllll/lACE1ACEACEwrapperswrappersACE3ACEACEBoochA2.1ACEACE85,000C++9,000ACElllll2.2ACEOOWrappersACElIPCSAPIPCSAPsocketsTLIUNIXFIFOsSTREAMWin32lACECONNECTORACCEPTORlACElACElCORBAACECORBAOrbixOOwrappersOOC++JavaC++ACEwrapper2.3ACEACEOSwrappersACElReactorACEReactorlServiceConfiguratorACEServiceConfiguratorlStreamsACEstreams2.4ACEwrappersACEACEACEIPCwrappersReactorServiceConfiguratorServiceInitialization,Concurrency,MemoryManagement,andStreamscomponents;OOACE3ACE3.1IPC_SAP:IPCACEIPCSAPIPCSAPI/OIPC3SOCKSAPTLISAPSPIPESAPFIFOSAPInternetUNIXl3ACE_AddrOOCstructsockaddrlSOCKAcceptorsocketsocketbindlistenlIPCIPClIPCOSOOfcntlioctlIPCSAP3.1.1SOCKSAPSOCKSAPInternerUNIX4SOCKSAPInternetUNIXsocketACE_SOCK*InternetACE_LSOCK*UNIX41*Dgram*ACE_STREAM2ACE_*ACCEPTOR*STREAMOOwrapperssocket123ACE_SOCK_Dgram_BcastLANintmain(intargc,char*argv[]){ACE_SOCK_Dgram_Bcastb_sap(sap_any);char*msg;unsignedshortb_port;msg=argc1?argv[1]:helloworld\n;b_port=argc2?atoi(argv[2]):12345;if(b_sap.send(msg,strlen(msg),b_port)==-1)perror(can’tsendbroadcast),exit(1);exit(0);}Csocket3.1.2TLISAPTLISAPSystemVTLIOOTLISAPSOCKSAPTLITLISAPUNIXTLIwin32C++tirdwrSTREAMS/C++IPC4.1ACE_Event_HandlertemplateclassPEER_STREAM,classADDRclassLogging_Handler:publicACE_Event_Handler{public:Logging_Handler(void);virtual˜Logging_Handler(void);virtualinthandle_input(ACE_HANDLE);virtualACE_HANDLEget_handle(void)const{returnthis-peer_stream_.get_handle();}protected:PEER_STREAMpeer_stream_;};ClientHandlerSOCKSAPTLISAP/*Loggingapplication*/classLogging_Handler#ifdefined(MT_SAFE_SOCKETS):publicLogging_HandlerACE_SOCK_Stream,ACE_INET_Addr#else:publicLogging_HandlerACE_TLI_Stream,ACE_INET_Addr#endif/*MT_SAFE_SOCKETS*/{/*...*/};SunOSSunOS5.2thread-safeTLISunOS4.xTLISAPTLIC++acceptTLISAPSOCKSAP3.1.3SPIPESAPSPIPESAPIPCOOwrapperWin32SPIPESAPNamedPipesWin32NamedPipesIPCsocketUNIXSPIPESAPSTREAMconnldSunOS5.xfattachUNIXconnldSTREAMmountedI/OSPIPESAPSOCKSAPTLISAPSOCKSAPACE_LSOCK*SunOS5.xSPIPESAPACE_LSOCK*STREAMSPIPESAPSPIPESAP3.1.4FIFOSAPFIFOSAPUNIXSTREAMSunOS5.xSTREAMSSunOS4.xSunOS4.xACEFIFOSAPlogicSunOS5.x3.1.5I/OACESystemVUNIXIPCOOwrappers.ACE_Mem_MapWin32UNIXmmapOOOSI/O/Win32UNIXbookkeepingACE_Mem_MapOOwrapperACE_Mem_MapOOwrappersstaticvoidputline(constchar*s){while(putchar(*s++)!=’\n’)continue;}intmain(intargc,char*argv[]){char*filename=argv[1];char*file_p;Mem_Mapmmap(filename);if(mmap(file_p)!=-1){size_tsize=mmap.size()-1;if(file_p[size]==’\0’)file_p[size]=’\n’;while(--size=0)if(file_p[size]==’\n’)putline(file_p+size+1);putline(file_p);return0;}elsereturn1;}SystemVIPCSunOSUNIXSystemVIPCSunOSUNIXmmapSTREAMSystemVIPCUNIXSystemVIPCSystemVIPCACESystemVIPCwrapperACEOOwrapperSystemVIPCwaitsignal/typedefACE_SV_Semaphore_SimpleSEMA;SEMAprod(1,SEMA::CREATE,1);SEMAcons(2,SEMA::CREATE,0);voidproducer(void){for(;;){prod.wait();//produceresource...cons.signal();}}voidconsumer(void){for(;;){cons.wait();//consumeresource...prod.signal();}3.2ReactorI/O:publicACE_Event_Handler{public:Ping_Pong(char*b):len(min(strlen(b)+1,BUFSIZ)){strncpy(this-buf,b,BUFSIZ);}virtualinthandle_input(ACE_HANDLEhandle){returnread(handle,this-buf,BUFSIZ);}virtualinthandle_output(ACE_HANDLEhandle){returnwrite(handle,this-buf,this-len);}virtualinthandle_signal(intsignum){this-finished=1;}virtualinthandle_timeout(constTime_Value&,constvoid*){this-finished=1;}booldone(void){returnthis-finished==1;}private:sig_atomic_tfinished;charbuf[BUFSIZ];size_tlen;};SVR4UNIXSTREAMstaticintinit_handles(ACE_HANDLEhandles[]){if(pipe(handles)==-1)LM_ERROR((LOG_ERROR,%p\n%a,pipe,1));//Enablemessage-orientedmodeinsteadof//bytestreammode.intarg=RMSGN;if(ioctl(handles[0],I_SRDOPT,arg)==-1||ioctl(handles[1],I_SRDOPT,arg)==-1)return-1;}Ping_PongcallbackACE_ReactorinstanceI/Ocallbackintmain(intargc,char*argv[]){ACE_HANDLEhandles[2];ACE_Reactorreactor;init_handles(handles);pid_tpid=fork();Ping_Pongcallback(argv[1]);//RegisterI/O-basedeventhandlerreactor.register_handler(handles[pid==0],&callback,ACE_Event_Handler::READ_MASK|ACE_Event_Handler::WRITE_MASK);//Registersignal-basedeventhandlerreactor.register_handler(SIGINT,&callback);//Registertimer-basedeventhandlerreactor.schedule_timer(&callback,0,10);/*Maineventloop(runineachprocess)*/while(callback.done()==false)reactor.handle_events()