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

This is a discussion on hello every1, I seed a suggesting related asychron i\o. I'm write a program which us within the Linux Programming forums, part of the Platform Specific Boards category; hello every1, I seed a suggesting related asychron i\o. I'm write a program which use completion ports, but wandor how ...

  1. #1
    Registered User
    Join Date
    Jan 2009
    Posts
    77

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

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

  2. #2
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,655
    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?

  3. #3
    Registered User
    Join Date
    Jan 2009
    Posts
    77
    Quote Originally Posted by Sebastiani View Post
    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.

  4. #4
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,655
    Quote Originally Posted by quantt View Post
    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.

  5. #5
    Registered User
    Join Date
    Jan 2009
    Posts
    77
    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);
    }
    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...
    Last edited by quantt; 09-12-2009 at 12:57 AM.

  6. #6
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,655
    And how exactly does that relate to your original question?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 1
    Last Post: 03-03-2009, 03:47 PM
  2. Replies: 1
    Last Post: 10-13-2004, 12:15 PM
  3. Same seed for srand yields different results
    By codegirl in forum C++ Programming
    Replies: 3
    Last Post: 06-23-2003, 02:39 PM
  4. fopen();
    By GanglyLamb in forum C Programming
    Replies: 8
    Last Post: 11-03-2002, 11:39 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21