C Board  

Go Back   C Board > Platform Specific Boards > Linux Programming

Reply
 
LinkBack Thread Tools Display Modes
Old 09-11-2009, 06:04 AM   #1
Registered User
 
Join Date: Jan 2009
Posts: 71
hello every1, I seed a suggesting related asychron i\o. I'm write a program which us

hello every1,
I seed a suggesting related asychron i\o. I'm write a program which use completion ports, but wandor how avoiding loops like for(; below...
i.e I want parse proto with count in first and then computing some quantity of pieces.
how that make with aio?
Code:
void parse(void *buf, int buflen, struct sockaddr_in sin){
struct piece {
uint32 id[2];
uint32 stuffing[10]
};
struct head {
int count_of_pieces[2];
struct piece p;
};
for(;;){
 
}
 
}
void sig_handler(int signo, siginfo_t *info, void *context ){
        int ret;
        char *buf;
        struct sockaddr_in sin;
        struct aiocb *req;
        if (info->si_signo == SIGIO) {
                req = (struct aiocb *)info->si_value.sival_ptr;
                if (aio_error( req ) == 0) {
                        ret = aio_return( req );
                        (char*)(req->aio_buf+ret);
                        parse(req->aio_buf,ret,sin.sin_addr.s_addr);
                }
        }
        return;
}
quantt is offline   Reply With Quote
Old 09-11-2009, 06:51 AM   #2
Guest
 
Sebastiani's Avatar
 
Join Date: Aug 2001
Posts: 4,923
Your question doesn't make any sense. You don't want to use a loop? Or you don't know how to set up a loop? Or what?
Sebastiani is offline   Reply With Quote
Old 09-11-2009, 05:16 PM   #3
Registered User
 
Join Date: Jan 2009
Posts: 71
Quote:
Originally Posted by Sebastiani View Post
Your question doesn't make any sense. You don't want to use a loop? Or you don't know how to set up a loop? Or what?
yes, I don't want to use a loop.
quantt is offline   Reply With Quote
Old 09-11-2009, 08:42 PM   #4
Guest
 
Sebastiani's Avatar
 
Join Date: Aug 2001
Posts: 4,923
Quote:
Originally Posted by quantt View Post
yes, I don't want to use a loop.
Alright then, so why not? You're not going to get much done without one...writing a program without a loops is about as useful as cooking without a fire.
Sebastiani is offline   Reply With Quote
Old 09-12-2009, 12:48 AM   #5
Registered User
 
Join Date: Jan 2009
Posts: 71
no, I can seeking the buffer and also getting necessary information...
p.len= cb.buf[2];
p.id= cb.buf[1]+2;
p.payload= cb.buf[p.len]+3;
but if i not use in a global sock(handle of socket) I can't reply, I seems, or not?
Code:
void calling_aio(int sock){
	struct aiocb a_read;
	struct sigaction sig_act;
	int ret;
	memset(&a_read,0,sizeof(a_read));
	a_read.aio_buf = (struct aiocb *) calloc(1,MAX_TRANSPORT_LENTH+1);
        if (!a_read.aio_buf) err("calloc");

        a_read.aio_fildes = sock;
        a_read.aio_nbytes = MAX_TRANSPORT_LENTH;
        a_read.aio_offset = 0;


        a_read.aio_sigevent.sigev_notify = SIGEV_SIGNAL;
        a_read.aio_sigevent.sigev_signo = SIGIO;
        a_read.aio_sigevent.sigev_value.sival_ptr = &a_read;

        sigemptyset(&sig_act.sa_mask);
        sig_act.sa_flags = SA_SIGINFO;
        sig_act.sa_sigaction = sig_handler;

        const struct aiocb *cblist[MAX_LIST] = {&a_read,NULL,NULL,NULL,NULL};
        sigaction( SIGIO, &sig_act, NULL );

        ret = aio_read( &a_read );
        while ( aio_suspend( cblist, MAX_LIST, NULL ) == 0)
        {
            ret = aio_read( &a_read );
        };

}

int main(void){
int sock = list_socket(h,p);
calling_aio(sock);
}
if you see, I can't call in again calling_aio? perhaps I need to call another func so as to write to sock, meanwhile into sig_handler I can't call func for writing, but I seems it's so ugly. i want architect suggestion how that make...

Last edited by quantt; 09-12-2009 at 12:57 AM.
quantt is offline   Reply With Quote
Old 09-12-2009, 01:05 AM   #6
Guest
 
Sebastiani's Avatar
 
Join Date: Aug 2001
Posts: 4,923
And how exactly does that relate to your original question?
Sebastiani is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Calling a program within a program within a program with redirected io streams sean Linux Programming 1 03-03-2009 04:47 PM
How to write program for Serial and USB which connect to external hardware? gogo C Programming 1 10-13-2004 12:15 PM
Same seed for srand yields different results codegirl C++ Programming 3 06-23-2003 02:39 PM
fopen(); GanglyLamb C Programming 8 11-03-2002 12:39 PM


All times are GMT -6. The time now is 03:41 AM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.0 RC2

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22