Changeset afa113a315cc3a8540fbd86ca2667b9be278dd0b

Show
Ignore:
Timestamp:
03/16/10 19:26:52 (23 months ago)
Author:
D.J. Capelis <dev@…>
Parents:
fc4ae5ac4c3000ecb26d84ab72fe84f304e4bad5
Children:
ba815f017780c3a855c8afda37cd204684d1ed70
git-committer:
D.J. Capelis <dev@capelis.dj> / 2010-03-16T19:26:52Z-0700
Message:

This is the version of fived that was used in the testing for CMPS232 at UCSC.

An important bug is fixed in this commit that allows for fived to
actually work correctly when there's a bunch of data heading at it.
Fived incorrect assumed at one point that a read would read the entire
range.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • handler.c

    rfc4ae5a rafa113a  
    4545        { 
    4646incoming: 
    47             if(!s->ssl) 
     47            if(!s->ssl)  //TODO: re-write everything here to use gettalk() 
    4848            { 
    4949                if(!s->multiplex) 
     
    324324        if(mode == 1) 
    325325        { 
    326             int chunk = 0; 
    327326            len = 0; 
    328327            while(1) 
     
    334333                    if(s->multiplex) 
    335334                    { 
    336                         printf("fd %d has an event\n", events[i].data.fd); 
     335                        //printf("fd %d has an event\n", events[i].data.fd); 
    337336                        if(events[i].data.fd != s->sock) 
    338337                        { 
     
    355354                        else 
    356355                            len = SSL_read(s->ssl, &s->header, 16); 
     356                        //printf("%x | %x | %x | %x\n", ntohl(s->ptr[0]), ntohl(s->ptr[1]), ntohl(s->ptr[2]), ntohl(s->ptr[3])); 
    357357                        //if(len < 1) 
    358358                        if(len != 16) 
    359359                            goto kill; 
    360                         chunk = ntohl(s->ptr[3]); 
     360                        s->multiplex_xtra = ntohl(s->ptr[3]); 
    361361                        if(ntohl(s->ptr[1]) == 0 && ntohl(s->ptr[3]) != 0) //They're talking to tcpmux 
    362362                        { 
    363363                            if(ntohl(s->ptr[2]) != 0) 
    364364                                printf("Client is sending flags about id 0, something is wrong\n"); 
    365                             len = chunk; 
     365                            len = s->multiplex_xtra; 
     366                            s->multiplex_xtra = 0; //TODO: revise this when you refactor the incoming module 
    366367                            goto incoming; 
    367368                        } 
    368                         if(ntohl(s->ptr[2]) == 2) 
     369                        if(ntohl(s->ptr[2]) == DEL_PLEX) 
    369370                        { 
    370                             close(ntohl(s->ptr[1])); //Yeah, we should actually have our own table and be verifying 
     371                            close(ntohl(s->ptr[1])); //TODO: Yeah, we should actually have our own table and be verifying 
    371372                            continue; 
    372373                        } 
    373                         while(chunk > BUFFER) 
     374                        while(s->multiplex_xtra != 0) 
    374375                        { 
     376                            if(s->multiplex_xtra > BUFFER) 
     377                                len = BUFFER; 
     378                            else 
     379                                len = s->multiplex_xtra; 
    375380                            if(!s->ssl) 
    376                                 len = read(s->sock, netbuffer, BUFFER); 
     381                                len = read(s->sock, netbuffer, len); 
    377382                            else 
    378                                 SSL_read(s->ssl, netbuffer, chunk); 
    379                             write(ntohl(s->ptr[1]), netbuffer, len); 
    380                             chunk -= len; 
     383                                len = SSL_read(s->ssl, netbuffer, len); 
     384                            chk_error(write(ntohl(s->ptr[1]), netbuffer, len) != len); 
     385                            //printf("Wrote %d bytes to fd %d\n", len, ntohl(s->ptr[1])); 
     386                            s->multiplex_xtra -= len; 
    381387                        } 
    382                         if(!s->ssl) 
    383                             read(s->sock, netbuffer, chunk); 
    384                         else 
    385                             SSL_read(s->ssl, netbuffer, chunk); 
    386                         write(ntohl(s->ptr[1]), netbuffer, chunk); 
    387                         printf("Wrote %d bytes to fd %d\n", chunk, ntohl(s->ptr[1])); 
    388388                        continue; 
    389389                    } 
     
    407407        } 
    408408    } 
     409 
     410err: 
     411    perror("Error"); 
    409412 
    410413    return NULL; 
     
    502505void send_header(struct session * s, int id, int flags, int len) 
    503506{ 
    504     printf("Sending to id %d len %d with flags %d\n", id, len, flags); 
     507    //printf("Sending to id %d len %d with flags %d\n", id, len, flags); 
    505508    char header[16]; 
    506509    int * ptr = (int *) &header;