210 likes | 347 Views
OpenSource Network Library HalfNetwork. 임영기 javawork93@gmail.com. HalfNetwork 란. ACE 를 이용하여 만든 C++ 네트워크 라이브러리 Half-Sync / Half- Async (POSA2) 패턴의 구현물. ACE. Open source object-oriented framework Socket / Thread / Lock / Buffer 여러 패턴의 집약체 Wrapper Façade Adaptor Composite. ACE 컴파일.
E N D
OpenSourceNetwork LibraryHalfNetwork 임영기 javawork93@gmail.com
HalfNetwork란 • ACE를 이용하여 만든 C++ 네트워크 라이브러리 • Half-Sync / Half-Async(POSA2) 패턴의구현물
ACE • Open source object-oriented framework • Socket / Thread / Lock / Buffer • 여러 패턴의 집약체 • Wrapper Façade • Adaptor • Composite
ACE 컴파일 • $ACE_ROOT : ACE_wrappers폴더 • $ACE_ROOT/ace/config.h생성 • #define ACE_HAS_STANDARD_CPP_LIBRARY 1 • #define ACE_USES_WCHAR 1 • #include "ace/config-win32.h“ • $ACE_ROOT/ace/ace_Static.sln 컴파일 • aces.lib acesd.lib • ACE_AS_STATIC_LIBS 선언
Half-Sync / Half-Async Pattern Library Queue Application
Message_Block의기능 #1 버퍼 관리 0 ReadPtr WritePtr Size Size = block.size(); // Size Length = block.length(); // WritePtr – ReadPtr Space = block.space(); // Size – WritePtr
Block에서 읽어오기 memcpy(buffer, block.rd_ptr(), block.length()); block.rd_ptr(block.length());
Block에 쓰기 block.copy(buffer, write_length);
Message_Block의 기능 #2Chained Message_Block Block Next • Head만 넘기면 됨 • 데이터 복사를 줄여준다 • Composite 패턴
Queue에서 꺼냈을 때(PopMessage) Command Block Payload Block
패킷 처리 코드 ACE_Message_Block* commandBlock = NULL; NetworkFacade->PopMessage(queue_id, &commandBlock, -1); ... switch(postee.command) { caseMessageHeader::ESTABLISH: ... break; caseMessageHeader::READ: ... break; caseMessageHeader::CLOSE: ... break; }
Queue에서 꺼냈을 때(PopAllMessage) Command Block Payload Block
초기화 코드 NetworkFacade->Create( newProactorFactory); NetworkFacade->AddAcceptor( ip, port, queue_id); NetworkFacade->Open();
설정관련 함수들 NetworkFacade->SetWorkerThreadCount(count); NetworkFacade->SetSendMode(DIRECT_SEND); NetworkFacade->SetReceiveBufferLen(1024*4); NetworkFacade->SetIntervalSendTerm(20);
동작관련 함수들 NetworkFacade->Connect(ip,port,queue_id); NetworkFacade->SendRequest(streamID,block); NetworkFacade->CloseStream(streamID); NetworkFacade->PopAllMessage(block); NetworkFacade->SuspendAcceptor(port); NetworkFacade->ResumeAcceptor(port); NetworkFacade->Dump();
Packet Generator Packet Generator YAML 정의 파일 C++ 소스 파일
참고 • ACE 다운로드 : http://download.dre.vanderbilt.edu/ • HalfNetwork다운로드 : https://sourceforge.net/projects/halfnetwork/ • HalfNetwork한국어 위키: http://halfnetwork.springnote.com/ • Blog: http://javawork.egloos.com/