[Develope]/Network

posix proactor library test

하늘을닮은호수M 2008. 7. 1. 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

반응형

'[Develope] > Network' 카테고리의 다른 글

홀 펀칭(Hole Punching)  (1) 2008.08.11
TCP State Diagram  (0) 2008.07.28
posix proactor library  (0) 2008.07.01
netstat  (0) 2008.03.17
Aptana  (0) 2008.02.21