![]() |
| |||||||
![]() |
| | LinkBack | Thread Tools | Display Modes |
| | #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 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 | |
| | #2 |
| Guest 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 | |
| | #3 |
| Registered User Join Date: Jan 2009
Posts: 71
| |
| quantt is offline | |
| | #4 |
| Guest Join Date: Aug 2001
Posts: 4,923
| |
| Sebastiani is offline | |
| | #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);
}
Last edited by quantt; 09-12-2009 at 12:57 AM. |
| quantt is offline | |
| | #6 |
| Guest Join Date: Aug 2001
Posts: 4,923
| And how exactly does that relate to your original question? |
| Sebastiani is offline | |
![]() |
| Thread Tools | |
| Display Modes | |
|
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 |