LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 09-11-2009, 06:18 AM   #1
quantt
Member
 
Registered: Aug 2008
Posts: 62

Rep: Reputation: 15
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;
}
 
Old 09-12-2009, 12:41 AM   #2
paulsm4
LQ Guru
 
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,863
Blog Entries: 1

Rep: Reputation: Disabled
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...
 
Old 09-12-2009, 06:48 AM   #3
quantt
Member
 
Registered: Aug 2008
Posts: 62

Original Poster
Rep: Reputation: 15
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.

Last edited by quantt; 09-12-2009 at 08:23 PM.
 
Old 09-12-2009, 08:27 PM   #4
quantt
Member
 
Registered: Aug 2008
Posts: 62

Original Poster
Rep: Reputation: 15
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);

	};
 
Old 09-13-2009, 12:28 PM   #5
paulsm4
LQ Guru
 
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,863
Blog Entries: 1

Rep: Reputation: Disabled
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....
 
Old 09-15-2009, 09:15 AM   #6
quantt
Member
 
Registered: Aug 2008
Posts: 62

Original Poster
Rep: Reputation: 15
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++){

}
 
Old 09-15-2009, 03:58 PM   #7
quantt
Member
 
Registered: Aug 2008
Posts: 62

Original Poster
Rep: Reputation: 15
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;
}
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Real Time Clock & Real Time Timer jiramak Linux - Newbie 1 09-05-2007 06:43 PM
LXer: Real-time garbage collection with Real-time Java LXer Syndicated Linux News 0 05-05-2007 12:16 PM
Help with deciding Linux capability for Real-Time application anantvemuri Linux - Kernel 3 03-04-2007 01:44 PM
LXer: Real-time Linux gains real-time JVM LXer Syndicated Linux News 0 10-12-2006 10:54 AM
LXer: Developing a real-time Linux data acquisition application LXer Syndicated Linux News 0 08-21-2006 11:54 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 07:09 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration