problem with real-time

hello everyone,
i'm very hope so anyone ere have experience with lib rt like aio linux based.
I've a problem with receiving data from aio_buf, i.e. I have received it, but if the next data size less then pervious I've got a noise from a socket.
I've tried to fix it by different ways, but unfortunately still didn't.
1
2
3
4
5
6
7
8
9
10
11
	while ( aio_suspend( list, MAX_LIST, NULL ) == 0)
	{
	    ret = aio_read( &a_read );
		//(char*)(&a_read.aio_buf[0]+ret) == '\0';
		//printf("START | %s,%d | END",a_read.aio_buf,ret);
		//if(strcmp(a_read.aio_buf,"ttttt\n")){
		puts(&a_read.aio_buf[0]);
		//printf("G");
		//}

	};

first

second

third


fourth

fourth an half

five
h an half

Are you calling aio_return() to get the number of bytes read by the last aio_read() operation?
did you mean what I can't use it without signalling? actually I'm avoiding it...
Assuming that aio_buf is a char array, it looks a lot like you aren't null terminating the string
before printing it, and aio_read is not doing that for you.

I assume that aio_read returns the number of bytes read (or -1 on error), so to fix you
probably need to

 
a_read.aio_buf[ ret ] = 0;


before printing.

1
2
3
4
5
6
7
	while (aio_suspend( list, MAX_LIST, NULL ) == 0){
	ret = aio_read( &a_read );
	if (aio_error( &a_read ) == 0) {
		ret = aio_return(&a_read);
	}
	printf("AIO operation returned %d %s\n", ret,a_read.aio_buf );
	};


AIO operation returned 0 cccccccccc

AIO operation returned 0 vvvv
ccccc

it's a misstake
a_read.aio_buf[ ret ] = 0

but if i did it...
a_read.aio_buf = 0

AIO operation returned 0 (null)
If an error condition is detected that prevents the read request from being enqueued, aio_read() returns -1 and sets errno to indicate the cause of the failure. Once the read operation has been successfully enqueued, an aio_error() and aio_return() function referencing the aiocb referred to by aiocbp must be used to determine its status and any error conditions, including those normally reported by read(). The request remains enqueued and consumes process and system resources until aio_return() is called.

http://docs.hp.com/en/B9106-90009/aio_read.2.html

It looks like you've started an async read, but started to use the results before they're ready. The point of async I/O is to allow I/O to run concurrently with any processing you have to do without spawning a thread to do it. You still have to wait for the I/O to actually complete.
Last edited on
AIO operation returned 0 BB
A

AIO operation returned 0 C

A

hm, anyway it didn't.
1
2
3
4
5
	while (aio_suspend( list, 1, NULL ) == 0){
	ret = aio_read( &a_read );
while ((ret = aio_error( &a_read) ) == EINPROGRESS);
	printf("AIO operation returned %d %s\n", ret, (char *)a_read.aio_buf );
	};

but, I did send by this sequence...
AAAA
BB
C

and this while eating cpu....
Last edited on
What does aio_read return? Is a_read initialised correctly? How many bytes have you asked it to read? What does aio_return return?
ok, if I did...
1
2
3
4
5
6
7
8
9
10
11
while(1){
do {
ret = aio_read( &a_read );
if (aio_suspend( list, 1, NULL ) == 0) {
	if (aio_error( &a_read ) == 0) {
		ret = aio_return(&a_read);
	printf("AIO operation returned %d %s\n", ret, (char *)a_read.aio_buf );
	}
}
} while ((ret = aio_error( &a_read) ) == EINPROGRESS);
}


AIO operation returned 2 d
dddddddd

AIO operation returned 27 ffffffffffffffffffffffffff

AIO operation returned 3 rr
fffffffffffffffffffffff
Last edited on
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?
1
2
3
4
5
6
7
8
9
10
11
12
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;
}
Topic archived. No new replies allowed.