Admin관리자   |    Posting포스트   |    LogOut로그아웃
:+:하늘을닮은호수:+: | Trac | 블로그   |    위치로그   |    태그로그   |    방명록


하늘을 닮은 호수
http://sunsson.iptime.org
Category
전체 (966)
[Standard] (59)
[OS] (119)
[Develope] (77)
[IT Trend] (347)
[Music] (101)
[삶의 질] (262)
Tag List
trac   3GPP   IPTV   svn   2MB   VoIP   c99   PSS   mysql   RTP   memory_leak   H.263   팔봉산   FLV   awk   ffmpeg   cdn   avc   grep   손예진   gslb   libumem   egrep   SVC   ietf   fgrep   RTCP   추억   사랑   zgrep  
홀 펀칭(Hole Punching)
Date : 2008/08/11 11:33

홀 펀칭(Hole Punching)이란??

공유기 라는 녀석이 라우터의 특성도 함께 가지고 있어 Routing Table을 작성하기 위해 P2P 통신을 목적으로, 사전에 상대방과 패킷을 주고받고 하여 각자의 공유기에 Routing Table을 작성하는 것을 [홀 펀칭]이라고 한다.

    Full Cone
    Port Restricted Cone
    Restricted Cone
    Symmetric Cone

Full Cone NAT
내부에 있는 호스트들의 모든 요청은, 모두 같은 외부 ip, port로 맵된다. 더군다나
어떤 외부 호스트든 공인 IP가 맵된 패킷 보내기에 의해 내부 호스트로 패킷을 보낸다.


Restricted Cone
목적지의 주소에 따라 NAT에 맵 되는 포트가 달라진다.
홀 펀칭을 위해서는 목적지의 IP만 동일시 하여 뚫어주면 목적지의 패킷을 받을 수 있다.

Port Restricted Cone
목적지의 주소에 따라 NAT에 맵 되는 포트가 달라진다.
홀 펀칭을 위해서는 목적지의 IP와 포트를 동일시 하여 뚫어주어야만
목적지의 패킷을 받을 수 있다.

Symmetric Cone
목적지의 주소와 포트에 따라 NAT에 맵 되는 포트가 달라진다.

P2P로의 1:1 연결에서는 적어도 한 쪽이 Symmetric Cone NAT 아니거나 공인 아이피를 소유하고 있는 Peer 여야 한다.

===========================================================================================================================

홀펀칭(Hole Punching)방식은 아래와 같다.

1. Full Cone
 -> PC에서 UDP 데이터를 공유기 밖으로 보낼때 해당 PC의 IP와 포트 정보를 공유기가 기억하고 공유기의 포트와 매핑을 해줌
     공유기의 해당 포트로 데이터가 오면 출발지 IP와 포트 정보를 상관하지 않고 해당 PC에 포워딩을 해줌

2. Restricted Cone
 -> PC에서 UDP 데이터를 공유기 밖으로 보낼때 해당 PC의 IP와 포트 정보, 목적지 IP를 기억하고 공유기의 포트와 매핑을 해줌
     공유기의 해당 포트로 데이터가 오면 출발지 IP 정보를 비교하여 공유기에 기록된 목적지IP와 같으면 해당 PC에 포워딩을 해줌

3. Port Restricted Cone.
 -> PC에서 UDP 데이터를 공유기 밖으로 보낼때 해당 PC의 IP와 포트 정보, 목적지 IP, Port를 기억하고 공유기의 포트와 매핑을 해줌
     공유기의 해당 포트로 데이터가 오면 출발지 IP 정보를 비교하여 공유기에 기록된 목적지IP, Port가 같으면 해당 PC에 포워딩을 해줌

4. Symmetric NAT
 -> PC에서 UDP 데이터를 공유기 밖으로 보낼때 해당 PC의 IP와 포트 정보, 목적지 IP, Port를 기억하고 공유기의 포트와 매핑을 해줌, 만약 목적지 IP나 Port번호가 봐뀌면 새로운 포트로 매핑해줌
     공유기의 해당 포트로 데이터가 오면 출발지 IP 정보를 비교하여 공유기에 기록된 목적지IP, Port가 같으면 해당 PC에 포워딩을 해줌

UDP 서버 ( 랑데뷰 피어 )로 클라이언트가 UDP 패킷을 전송
서버에 클라이언트의 IP와 Port정보가 남는다.
이 정보를 바탕으로 현재 서버에 연결된 소켓에 접속할 IP와 포트 정보만
상대방 IP와 포트 정보를 넣고 상호간에 데이터 전송 시도하면 Cone 방식은 UDP 홀펀칭이 성공한다.
100%가 아닐까 싶다...(나의 소망)

간혹 Symmetric NAT방식의 공유기가 있는데
이공유기 같은 경우에는 같은 소켓을 써도 UDP 데이터를 외부로 쏠때 목적지 IP나 포트 정보가 변경되면 공유기에서는 새로운 포트를 할당해 준다. 고로 나가는것은 되나 들어오는것이 안됨..
한쪽이 Symmetric NAT방식이라면 상관 없는데 양쪽이 Symmetric NAT방식이라면 낭패;
UDP 릴레이 서버를 거치던지 다른 방법을 써야 한다.

한쪽이 Symmetric NAT방식이라면 반대쪽에서는 Symmetric NAT쪽의 데이터를 받을수 있다.
이 데이터를 받을때 IP와 포트 번호를 알아 낼수있다.
알아낸 IP와 포트번호로 데이터 전송하면 됨
고로 통신이 가능함.

크리에이티브 커먼즈 라이센스
Creative Commons License
이올린에 북마크하기(0) 이올린에 추천하기(0)

"[Develope] / Network" 분류의 다른 글

TCP State Diagram2008/07/28
posix proactor library test2008/07/01
posix proactor library2008/07/01
netstat2008/03/17
Aptana2008/02/21
2008/08/11 11:33 2008/08/11 11:33
Top

블로그코리아에 블UP하기
TCP State Diagram
Date : 2008/07/28 11:16

출처 : http://en.wikipedia.org/wiki/Image:Tcp_state_diagram.svg

사용자 삽입 이미지


크리에이티브 커먼즈 라이센스
Creative Commons License
이올린에 북마크하기(0) 이올린에 추천하기(0)

"[Develope] / Network" 분류의 다른 글

홀 펀칭(Hole Punching)2008/08/11
posix proactor library test2008/07/01
posix proactor library2008/07/01
netstat2008/03/17
Aptana2008/02/21
2008/07/28 11:16 2008/07/28 11:16
Top

블로그코리아에 블UP하기
posix proactor library test
Date : 2008/07/01 18:15

++++++++++++++++++++++++++
* Source File
++++++++++++++++++++++++++

posix proactor library를 테스트할 수 있는 코드.

#include <stdio.h>
#include <string.h>     //strerror()
#include <sys/types.h> //getpid()
#include <unistd.h>
#include <errno.h>
#include <stdlib.h>

#include "../posix_proactor.h"
#include "test_posix_proactor.h"

//#include "mp4file_reader_file.h" //by sunsson for parsing hintmdat


#define BLKSIZE 11

void *hndlr_ftn(void* data)
{
    printf("media's handler function\n");
    return 0;
}
int main(void)
{
    int fd0, fd1, size;
    volatile char buf0[11];
    volatile char buf1[11];
   
    ///posix proactor initiate       
    if(posix_proactor_init(3) != 0)     //paramete : max_aio_operation!!
        fprintf(stderr,"[Error]posix proactor init\n");

    if((fd0 = open("0.txt", O_RDONLY)) == -1){
        fprintf(stderr, "[Error]Could not open %s: %s\n", "0.txt", strerror(errno));
        return(-1);
    }
    if((fd1 = open("1.txt", O_RDONLY)) == -1){
        fprintf(stderr, "[Error]Could not open %s: %s\n", "1.txt", strerror(errno));
        return(-1);
    }

    size = BLKSIZE - 1;
    if(si_read_req(fd0, size, 0, buf0, (void *)NULL, (void *)hndlr_ftn, 0,  READ) < 0)
        printf("issue_aio_calls error\n");

    if(si_read_req(fd1, size, 0, buf1, (void *)NULL, (void *)hndlr_ftn, 0,  READ) < 0)
        printf("issue_aio_calls error\n");
 
    while(1)
        ;
}

++++++++++++++++++++++++++
* Makefile
++++++++++++++++++++++++++

.SUFFIXES: .c .o

CC= gcc
CFLAGS= -Wall -c -g
AR= ar
export CC AR CFLAGS

LIB_INC= -L..
LIBS= -lsys_i
LFLAGS= -lrt

OBJS= test_posix_proactor.o
SRCS= $(OBJS : .o = .c)
INCLUDE= -I../

#SUBDIRS= general MP4F MP4W

TARGET= test_posix_proactor

all: $(TARGET)

$(TARGET): $(OBJS)
    $(CC) -o $(TARGET) $(OBJS) $(LIB_INC) $(LIBS) $(LFLAGS)

clean:
    $(RM) -rf *.o *.a

new:
    $(MAKE) clean
    $(MAKE)
   
subdirs :
    @for i in $(SUBDIRS) ; do ( cd $$i && $(MAKE) ) ; done

.c.o:
    $(CC) $(INCLUDE) $(CFLAGS) $<

ctags:
    ctags -R .

++++++++++++++++++++++++++
* Input Data
++++++++++++++++++++++++++


0.txt와 1.txt에서 차례대로 10개의 문자를 읽어들인다.

0.txt
0000000000

1.txt
1111111111

++++++++++++++++++++++++++
* Result Data
++++++++++++++++++++++++++

issue_aio_calls
aiocblist_free_index found : 1
aio_call excuted..
ret_val from execute_aio_calls : 0
issue_aio_calls
aiocblist_free_index found : 2
aio_call excuted..
ret_val from execute_aio_calls : 0


rtsig_handler
handle_event called
[Info] aiocb_index : 2
get_result_status
nbytes : 10
0000000000
application_specific_code
media's handler function
get_result_status
nbytes : 10
1111111111
application_specific_code
media's handler function
handle_event end

크리에이티브 커먼즈 라이센스
Creative Commons License
이올린에 북마크하기(0) 이올린에 추천하기(0)

"[Develope] / Network" 분류의 다른 글

홀 펀칭(Hole Punching)2008/08/11
TCP State Diagram2008/07/28
posix proactor library2008/07/01
netstat2008/03/17
Aptana2008/02/21
2008/07/01 18:15 2008/07/01 18:15
Top

블로그코리아에 블UP하기
posix proactor library
Date : 2008/07/01 18:07

++++++++++++++++++++++++++
+ Header File
++++++++++++++++++++++++++


// posix_proactor.h, v 0.1 2005/05/19
// ============================================================================
/**
 *
 *   
 *
 * @file    posix_proactor.h
 *
 * @brief  posix_proactor which use RT Signal.
 *
 * struct aiocb
 *       int             aio_fildes;     //file descriptor
 *      volatile void   *aio_buf;   //buffer allocation
 *      size_t          aio_nbytes; //length of transfer
 *      off_t           aio_offet;      //file offset. starting position
 *      int             aio_reqprio;  //request priority offset(_POSIX_PRIORITIZED_IO and _POSIX_PRORITY_SCHEDULING
 *      struct sigevent aio_sigevent;   //signal number and offset
 *      int             aio_lio_opcode; //listio operation
 *
 *  @author sunsson <sunsson@varovision.com>
 */
// ============================================================================
#ifndef __POSIX_PROACTOR__
#define __POSIX_PROACTOR__

#include <signal.h>
#include <time.h>
#include <aio.h>

#define AIOCB_MAX_SIZE 2048      //서버가 지원하는 최대 클라이언트 수(1024) * 클라이언트 당 요청한 파일의 미디어 수(평균 2)
#define PROACTOR_DEBUG 1

#ifdef __cplusplus
extern "C" {
#endif//__cplusplus

//typedef void (*SIGNAL_C_FUNC)(int, siginfo_t *, void *);

/**
 *  posix asynchronous result
 *  <BR>
 *  asynchronous reqeust를 요청한 곳 ( handler, data ) 에 요청된 결과가 처리되었을 때
 *  알리기 위한 구조
 */
typedef struct posix_asynch_result{

    /// allocated aiocb
    struct aiocb *aiocb;

    /// file description
    int fd;
   
    /// Bytes transferred by this operation.
    size_t size;

    /**
      * This really make sense only when doing file I/O.
      *
      * @@ On POSIX4-Unix, offset_high should be supported using
      *     aiocb64.
      *
      */
    unsigned long offset;
    unsigned long offset_high;

    /// Priority of the operation.
    int priority;

    /**
    * POSIX4 realtime signal number to be used for the
    * operation. <signal_number> ranges from SIGRTMIN to SIGRTMAX. By
    * default, SIGRTMIN is used to issue <aio_> calls.
    */
    int signal_number;
   
    /// Success indicator.
    int success;
   
    /// Error if operation failed.
    unsigned long error;

    /// on receiving signal in signal_hander, to call media's handler function
    void * (*hndlr)(void *);

    /// on receiving signal in signal_hander, to give a parameter to media's handler function
    void * data;

}posix_asynch_result;
/**
 * aiocb에 대한 요청이 READ인지, WRITE인지를 나타내는 값
 */
typedef enum{
  READ = 1,
  WRITE = 2
}Opcode;

/// number of aiocb
struct aiocb **aiocb_list;  //AIOCB_MAX_SIZE만큼
posix_asynch_result **result_list;

/// signal set
static sigset_t RT_completion_signal;

/// To maintain the maximum size of the array (list).
size_t aiocb_list_max_size;
/// To maintain the current size of the array (list).
size_t aiocb_list_cur_size;
/// Number of posix_asynch_result's waiting for start
/// i.e. deferred AIOs
size_t num_deferred_aiocb;
/// Number active,i.e. running requests
size_t num_started_aio;


/////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////PROACTOR INIT////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////
/**
 * @author 박학선
 * @param max_aio_operations System Interface에서 사용할 aiocb_list의 최대 갯수
 * @retval -1 proactor init error
 * @retval 0 proactor init ok
 * @brief System Interface이 초기화될 때 posix_proactor를 초기화
 *            하면서 시그널 세팅!!
 */
int
posix_proactor_init(size_t max_aio_operations);

/**
 * @author 박학선
 * @param
 * @retval
 * @brief System의 max aio size를 체크!!
 */
void
check_max_aio_num();

/**
 * @author 박학선
 * @param
 * @retval 0 result create ok
 * @brief System이 관리할 aiocb_list, result_list를 만듬
 */
int
create_result_aiocb_list();

/**
 * @author 박학선
 * @param
 * @retval -1 setup signal init or setup signal_hanlder fail
 * @retval 0 setup signal init(handler) success
 * @brief System이 사용할 signal(RTSIG_MIN) set up!!
 */
int
signal_init();

/**
 * @author 박학선
 * @param signal_number signal handler를 띄울 RTSIG
 * @retval -1 setup signal handler fail
 * @retval 0 setup signal handler success
 * @brief System Interface이 초기화될 때 시그널 핸들러 세팅!!
 */
int
setup_signal_handler(int signal_number);


/////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////CALLBACK/////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////
/**
 * @author 박학선
 * @param signal_number signal handler를 깨운 signal
 * @param info signal과 연관된 정보들(aiocb_list의 index)
 * @param context 사용한 바 없음.
 * @retval
 * @brief 요청된 read를 수행한 후에 호출되는 signal_handler
 */
void
rtsig_handler (int signal_number, siginfo_t* info, void* context);

/**
 * @author 박학선
 * @param
 * @retval -1 handler event error
 * @retval 0   run_event_loop complete
 * @brief loop을 돌면서 완료된 aiocb_list가 있는지 검사
 */
 int
run_event_loop();

/**
 * @author 박학선
 * @param
 * @retval -1 sigtimedwait error
 * @retval 0   handler_event complete
 * @brief 요청된 read를 수행한 후에 호출되는 signal_handler
 *      ====> signal_handler에서 signal을 감지했을 때완료된 요청이 있는지 검사
 */
int
handle_event(void);


//posix_asynch_result *
//find_completed_aio(int *error_status, size_t *transfer_count, size_t index, size_t count);

/**
 * @author 박학선
 * @param aiocb
 * @param error_status
 * @param transfer_count
 * @retval 1  AIO completed
 * @retval 0  not completed yet
 * @brief AIO가 completed되었는지를 체크
 */
int
get_result_status (struct aiocb *aiocb, int *error_status, size_t *transfer_count);

/**
 * @author 박학선
 * @param idx
 * @param transfer_count
 * @param error_status
 * @brief completed된 aiocb_list의 callback handler를 호출
 */
void
application_specific_code(size_t idx, int transfer_count, int error_status);


/////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////REQEUEST////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////
/**
 * @author 박학선
 * @param file_fd
 * @param size
 * @param offset
 * @param buf
 * @param data
 * @param hndlr_ftn
 * @param priority
 * @param op
 * @brief media에서 asynchronous read를 요청하기 위해 호출하는 함수.
 *           실제로는 이 파일안에 정의되어 있지는 않음. 단지 테스트를 위해서...
 */
 int
si_read_req(int file_fd, int size, int offset, void *buf, void *data, void *hndlr_ftn, int priority, Opcode op);

/**
 * @author 박학선
 * @param result
 * @param op
 * @retval 0 started OK
 * @retval 1 OS AIO queue overflow
 * @retval -1 do not started
 * @brief System Interface(si_read_req())에서 Proactor에
 *       read를 요청하기 위해 사용!!
 */
int
issue_aio_calls (posix_asynch_result *result, Opcode op);

/**
 * @author 박학선
 * @param aiocb
 * @retval 0 AIO was started successfully
 * @retval 1 AIO was not started, OS AIO queue overflow
 * @retval -1 AIO was not started, other errors
 * @brief 파일의 미디어 트랙에서 aio_read, aio_write를 실행!!
 */
int
execute_aio_calls (struct aiocb * aiocb);

/**
 * @author 박학선
 * @param aiocb
 * @retval retval > 0 allocated aiocb_list's slot
 * @retval -1   no free slot
 * @brief  이 시스템에서 관리하는 aiocb_list의 free slot을 반환한다.
 */
ssize_t
allocate_aio_slot(struct aiocb * aiocb);

#ifdef __cplusplus
}
#endif//__cplusplus


#endif //__POSIX_PROACTOR__

++++++++++++++++++++++++++
+ Source File
++++++++++++++++++++++++++

// posix_proactor.c, v 0.1 2005/05/19
// ============================================================================
/**
 *
 *   
 *
 * @file    posix_proactor.c
 *
 * posix_proactor which use RT Signal.
 *
 * struct aiocb
 *       int             aio_fildes;     //file descriptor
 *      volatile void   *aio_buf;   //buffer allocation
 *      size_t          aio_nbytes; //length of transfer
 *      off_t           aio_offet;      //file offset. starting position
 *      int             aio_reqprio;  //request priority offset(_POSIX_PRIORITIZED_IO and _POSIX_PRORITY_SCHEDULING
 *      struct sigevent aio_sigevent;   //signal number and offset
 *      int             aio_lio_opcode; //listio operation
 *
 *  @author sunsson <sunsson@varovision.com>
 */
// ============================================================================

#include "posix_proactor.h"
#include "test/test_posix_proactor.h"

#include <unistd.h>
#include <stdlib.h>
#include <fcntl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/resource.h>       //getrlimit, strlimit : control maximum resource consumption
#include <signal.h>
#include <string.h>
#include <errno.h>
#include <stdio.h>
#include <limits.h>
#include <aio.h>
#include <time.h>
#include <assert.h>


/////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////PROACTOR INIT////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////
/**
 * @author 박학선
 * @param max_aio_operations System Interface에서 사용할 aiocb_list의 최대 갯수
 * @retval -1 proactor init error
 * @retval 0 proactor init ok
 * @brief System Interface이 초기화될 때 posix_proactor를 초기화
 *            하면서 시그널 세팅!!
 */
int
posix_proactor_init(size_t max_aio_operations)
{
    aiocb_list = 0;
    result_list = 0;
    aiocb_list_max_size = max_aio_operations;
    aiocb_list_cur_size = 0;
    num_deferred_aiocb = 0;
    num_started_aio = 0;

    check_max_aio_num();
    if(create_result_aiocb_list() != 0){
        fprintf(stderr, "aiocb list make error\n");
        return -1;
    }
    if(signal_init() != 0){
        fprintf(stderr, "signal init error\n");
        return -1;
    }
    ///run_event_loop에서 완료된 sigset이 있는지 체크..
    //run_event_loop();
    return 0;
}

/**
 * @author 박학선
 * @param
 * @retval
 * @brief System의 max aio size를 체크!!
 */
void
check_max_aio_num()
{
    long max_aio_num;
    int max_num_files, r;
    struct rlimit rl;

    max_aio_num = sysconf (_SC_AIO_MAX);
        if (max_aio_num > 0 &&  aiocb_list_max_size > (unsigned long) max_aio_num)
            aiocb_list_max_size = max_aio_num;

    if (aiocb_list_max_size <= 0 || aiocb_list_max_size > AIOCB_MAX_SIZE)
        aiocb_list_max_size = AIOCB_MAX_SIZE;


#if defined (RLIM_INFINITY)
    r = getrlimit (RLIMIT_NOFILE, &rl);
    if (r == 0 && rl.rlim_cur != RLIM_INFINITY)
       max_num_files =  rl.rlim_cur;
#endif //RLIM_INFINITY

    if (max_num_files > 0 && aiocb_list_max_size > (unsigned long) max_num_files){
#if defined (RLIM_INFINITY)
    rl.rlim_cur = max_num_files;
    r = setrlimit (RLIMIT_NOFILE, &rl);
    if (r == 0 && rl.rlim_cur != RLIM_INFINITY)
#endif //RLIM_INFINITY
        aiocb_list_max_size = max_num_files;
    }
}

/**
 * @author 박학선
 * @param
 * @retval 0 result create ok
 * @brief System이 관리할 aiocb_list, result_list를 만듬
 */
int create_result_aiocb_list()
{
    size_t ai;
   
    if (aiocb_list != 0)
      return 0;

    aiocb_list = (struct aiocb**)malloc(sizeof(struct aiocb *[aiocb_list_max_size]));
    result_list = (posix_asynch_result **)malloc(sizeof(posix_asynch_result * [aiocb_list_max_size]));

    for (ai = 0; ai < aiocb_list_max_size; ai++){
        aiocb_list[ai] = 0;
        result_list[ai] = 0;
    }
    return 0;
}

/**
 * @author 박학선
 * @param
 * @retval -1 setup signal init or setup signal_hanlder fail
 * @retval 0 setup signal init(handler) success
 * @brief System이 사용할 signal(RTSIG_MIN) set up!!
 */
int signal_init()
{
    int ret_val;
    /// Get full set
    if(sigemptyset(&RT_completion_signal) == -1)
        fprintf(stderr, "[Error] Couldnt empty signal set\n");
   
    if(sigaddset(&RT_completion_signal, SIGRTMIN) == -1)
        fprintf(stderr, "[Error] Couldnt init the RT completion signal set\n");

    ///block the signal
    if(sigprocmask(SIG_BLOCK, &RT_completion_signal, 0) == -1) {
        fprintf(stderr, "Could not block SIGRTMAX or SIGRTMAX-1");
        return -1;
    }

     ret_val = setup_signal_handler(SIGRTMIN);

    ///unblock the signal
    //if(sigprocmask(SIG_UNBLOCK, &newact.sa_mask, NULL) == -1){
    if(sigprocmask(SIG_UNBLOCK, &RT_completion_signal, 0) == -1) {
        fprintf(stderr, "Could not unblock SIGRTMAX or SIGRTMAX-1");
        return -1;
    }

    return ret_val;
}

/**
 * @author 박학선
 * @param signal_number signal handler를 띄울 RTSIG
 * @retval -1 setup signal handler fail
 * @retval 0 setup signal handler success
 * @brief System Interface이 초기화될 때 시그널 핸들러 세팅!!
 */
int
setup_signal_handler(int signal_number)
{
    struct sigaction newact;
    int sigaction_return;

    sigemptyset(&newact.sa_mask);   //Nothing else to mask
    newact.sa_flags = SA_SIGINFO;    // Realtime flag.
    newact.sa_sigaction = rtsig_handler ;  //set up "null_handler"
    sigaction_return = sigaction (signal_number, &newact, 0);  //specify the action to be associated with a specific signal
    if(sigaction_return == -1){
        fprintf(stderr, "[Error]couldnt do sigaction for the RT SIGNAL\n");
        return -1;
    }
    return 0;
}


/////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////CALLBACK/////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////
/**
 * @author 박학선
 * @param signal_number signal handler를 깨운 signal
 * @param info signal과 연관된 정보들(aiocb_list의 index)
 * @param context 사용한 바 없음.
 * @retval
 * @brief 요청된 read를 수행한 후에 호출되는 signal_handler
 */
void
rtsig_handler (int signal_number, siginfo_t* info, void* context)
{
    int result = 0;
//    struct timespec timeout;

#if 0
    fprintf(stderr, "[info]Signal number %d\n", signal_number);
    if(query_aio_completions() < 0)
        fprintf(stderr, "null handler error\n");
    else
        fprintf(stdout, "rtsig_handler\n");
#else//0

#ifdef PROACTOR_DEBUG
    fprintf(stdout, "\n\nrtsig_handler\n");
#endif//PROACTOR_DEBUG
    result = handle_event ();
    if (result != 0 || errno == ETIME)
        perror("handle_event \n");
#endif//0
 exit(1);
}

/**
 * @author 박학선
 * @param
 * @retval -1 handler event error
 * @retval 0   run_event_loop complete
 * @brief loop을 돌면서 완료된 aiocb_list가 있는지 검사
 */
int run_event_loop()
{
    int ret_val;
    // Run the event loop.
    for (;;){
       ret_val = handle_event();
       if(ret_val == -1)
        break;
    }
    return 0;
}

/**
 * @author 박학선
 * @param
 * @retval -1 sigtimedwait error
 * @retval 0   handler_event complete
 * @brief 요청된 read를 수행한 후에 호출되는 signal_handler
 *      ====> signal_handler에서 signal을 감지했을 때완료된 요청이 있는지 검사
 */
int
handle_event (void)
{
    int sig_return = 0, error_status = 0;
    int ret_aio, ret_val;
    size_t aiocb_index = 0, transfer_count = 0, count = 1, idx;;
    posix_asynch_result* asynch_result;
   
    ///To get back the signal info.
    siginfo_t sig_info;
    struct