2012-09-18 2 views
0

data_completion_t, string_completion_t과 같은 콜백 서명을 발견했습니다. 그러나 사육사가 비동기 API에서 이러한 함수를 어떻게 호출하는지 궁금합니다.사육사가 비동기 API에서 함수 완료 기능을 수행하는 방법

동물원에서 응답을 받기 위해 단일 스레드를 사용합니까? 그래서 콜백에 user_data을 보호하기 위해 뮤텍스를 추가해야합니다. 또는 다른 asyn API가 호출 될 때마다 콜백을 확인합니까?

답변

1

나는 Cmt 라이브러리를 테스트 한 결과, 사육사가 IO 및 완료를 위해 또 다른 2 개의 스레드를 생성했음을 발견했다. 완성 함수에서 완료 함수가 호출되어 이러한 함수를 순차적으로 호출해야한다. 3000

int main() 
    { 

    zoo_set_debug_level(ZOO_LOG_LEVEL_DEBUG); 

    const char* host = "127.0.0.1:3000"; 

    zhandle_t *zh; 
    clientid_t myid; 
    zh = zookeeper_init(host, NULL, 5000, &myid, NULL, 0); 

    struct Stat stat; 
    const char* line = "/test"; 
    const char* ptr = "hello, world"; 
    int ret = zoo_set2(zh, line, ptr, strlen(ptr), -1, &stat); 
    printf("zoo_set2: %s\n", zerror(ret)); 

    } 

는 사실이 문서에 설명되어 있습니다 :

2012-10-09 15:35:36,904:60028(0x7fff7d0f7180):[email protected][email protected]: Initiating client connection, host=127.0.0.1:3000 sessionTimeout=5000 watcher=0x0 sessionId=0 sessionPasswd=<null> context=0x0 flags=0 
2012-10-09 15:35:36,904:60028(0x7fff7d0f7180):[email protected][email protected]: starting threads... 
2012-10-09 15:35:36,905:60028(0x10af45000):[email protected][email protected]: started completion thread 
2012-10-09 15:35:36,905:60028(0x10aec2000):[email protected][email protected]: started IO thread 
2012-10-09 15:35:36,905:60028(0x7fff7d0f7180):[email protected][email protected]: Sending request xid=0x5073d3c9 for path [/mm/mmidc] to 127.0.0.1:3000 
2012-10-09 15:35:36,905:60028(0x10aec2000):[email protected][email protected]: initiated connection to server [127.0.0.1:3000] 
2012-10-09 15:35:36,909:60028(0x10aec2000):[email protected][email protected]: session establishment complete on server [127.0.0.1:3000], sessionId=0x13a43632d85000f, negotiated timeout=5000 
2012-10-09 15:35:36,909:60028(0x10aec2000):[email protected][email protected]: Calling a watcher for a ZOO_SESSION_EVENT and the state=ZOO_CONNECTED_STATE 
2012-10-09 15:35:36,909:60028(0x10af45000):[email protected][email protected]: Calling a watcher for node [], type = -1 event=ZOO_SESSION_EVENT 
2012-10-09 15:35:36,910:60028(0x10aec2000):[email protected][email protected]: Processing sync_completion with type=1 xid=0x5073d3c9 rc=-101 
zoo_set2: no node 

테스트에 대한 매우 간단한 코드는 사육사 서버는 독립 청취 localhost입니다. http://zookeeper.apache.org/doc/r3.1.2/zookeeperProgrammers.html

C

The C binding has a single-threaded and multi-threaded library. The multi-threaded library is easiest to use and is most similar to the Java API. This library will create an IO thread and an event dispatch thread for handling connection maintenance and callbacks. The single-threaded library allows ZooKeeper to be used in event driven applications by exposing the event loop used in the multi-threaded library.

바인딩
관련 문제