LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   real-time application (https://www.linuxquestions.org/questions/programming-9/real-time-application-754387/)

quantt 09-11-2009 06:18 AM

real-time application
 
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;
}


paulsm4 09-12-2009 12:41 AM

Q: What does your "for" loop do?

If it polls for input available .... doesn't that kind of defeat the whole purpose of using "asynchronous input" in the first place?

Just wondering...

quantt 09-12-2009 06:48 AM

ok, that's perfect, you're understanding me;)
I mean how did it without 'for' loop's...
for instance, I use synchronisation by aio_suspend...
Code:

const struct aiocb *list[2] = {&a_read,NULL};
        while ( aio_suspend( list, 2 NULL ) == 0){
            ret = aio_read( &a_read );
                        puts(a_read.aio_buf);

        };

but, I'm little bit confused how I can write and read meanwhile...
i.e. if I got something necessary there a_read.aio_buf, I want to write here something like reply message.
actually, I use it with socket handle.

quantt 09-12-2009 08:27 PM

paulsm4, how I can reply on received messages?
because standard i\o doesn't work here....
Code:

char *buf;
// whatever
static const struct aiocb *list[MAX_LIST] = {&a_read,NULL,NULL,NULL,NULL};
        ret = aio_read( &a_read );
        while (aio_suspend( list, MAX_LIST, NULL ) == 0){
                ret = aio_read( &a_read );
                buf[10]="1234567\n";
                write(sock, buf, 11);

        };


paulsm4 09-13-2009 12:28 PM

Hi -

Frankly, I would stick with normal, blocking I/O unless:

1) my application *needed* asynchronous I/O
<= In this case, the application's requirements would dictate your design
... OR ...
2) I simply wanted to learn a i/o
<= I suspect this is your case

In the case of "learning", I would suggest the following (all from Google):

http://www.ibm.com/developerworks/li...brary/l-async/
http://www-aix.informatik.uni-tuebin..._io_subsys.htm
http://www.informit.com/articles/art...07373&seqNum=1

and finally

http://davmac.org/davpage/linux/async-io.html
Quote:

The POSIX asynchronous I/O interface, which is documented in the GNU libc manual, would seem to be almost ideal for performing asynchronous I/O. After all, that's what it was designed for. But if you think that this is the case, you're in for bitter disappointment....
Quote:

The documentation in the GNU libc manual (v2.3.1) is not complete...
Quote:

But there's a much more significant problem: The POSIX AIO API is totally screwed. The people who came up with it were on drugs or something. Really. I'll go through various issues, starting with the ones that aren't so bad and ending with the rool doozies....

quantt 09-15-2009 09:15 AM

hm, there not contains information how avoid loops.
I've got a buffer which have a format...
number of pieces
and some quantity of pieces
how I can to receive information from everyone pieces and avoid loops usage?
i.e. usually I do..
for(p;p<quantity;p++){

}

quantt 09-15-2009 03:58 PM

I seems use `for` itn's good with aio, more over not good use superfluous loops.
usually I did it by this way, perhaps it's so funky use for loop with aio?
Code:

struct piece {
uint32 id[2];
uint32 stuffing[10]
};
int quantity=7;
struct piece *pc[quantity+1];
// memory allocation
void buffer;
for(p;p<quantity;p++){
 pc[p]->id[2]=buffer[2];
pc[p]->stuffing[10]=buffer[2]+2;
}



All times are GMT -5. The time now is 09:05 PM.