PDA

View Full Version : hello every1, I seed a suggesting related asychron i\o. I'm write a program which us



quantt
09-11-2009, 06:04 AM
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?

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;
}

Sebastiani
09-11-2009, 06:51 AM
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?

quantt
09-11-2009, 05:16 PM
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.

Sebastiani
09-11-2009, 08:42 PM
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.

quantt
09-12-2009, 12:48 AM
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?


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...

Sebastiani
09-12-2009, 01:05 AM
And how exactly does that relate to your original question?