Changeset afa113a315cc3a8540fbd86ca2667b9be278dd0b
- 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:
-
Legend:
- Unmodified
- Added
- Removed
-
|
rfc4ae5a
|
rafa113a
|
|
| 45 | 45 | { |
| 46 | 46 | incoming: |
| 47 | | if(!s->ssl) |
| | 47 | if(!s->ssl) //TODO: re-write everything here to use gettalk() |
| 48 | 48 | { |
| 49 | 49 | if(!s->multiplex) |
| … |
… |
|
| 324 | 324 | if(mode == 1) |
| 325 | 325 | { |
| 326 | | int chunk = 0; |
| 327 | 326 | len = 0; |
| 328 | 327 | while(1) |
| … |
… |
|
| 334 | 333 | if(s->multiplex) |
| 335 | 334 | { |
| 336 | | printf("fd %d has an event\n", events[i].data.fd); |
| | 335 | //printf("fd %d has an event\n", events[i].data.fd); |
| 337 | 336 | if(events[i].data.fd != s->sock) |
| 338 | 337 | { |
| … |
… |
|
| 355 | 354 | else |
| 356 | 355 | 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])); |
| 357 | 357 | //if(len < 1) |
| 358 | 358 | if(len != 16) |
| 359 | 359 | goto kill; |
| 360 | | chunk = ntohl(s->ptr[3]); |
| | 360 | s->multiplex_xtra = ntohl(s->ptr[3]); |
| 361 | 361 | if(ntohl(s->ptr[1]) == 0 && ntohl(s->ptr[3]) != 0) //They're talking to tcpmux |
| 362 | 362 | { |
| 363 | 363 | if(ntohl(s->ptr[2]) != 0) |
| 364 | 364 | 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 |
| 366 | 367 | goto incoming; |
| 367 | 368 | } |
| 368 | | if(ntohl(s->ptr[2]) == 2) |
| | 369 | if(ntohl(s->ptr[2]) == DEL_PLEX) |
| 369 | 370 | { |
| 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 |
| 371 | 372 | continue; |
| 372 | 373 | } |
| 373 | | while(chunk > BUFFER) |
| | 374 | while(s->multiplex_xtra != 0) |
| 374 | 375 | { |
| | 376 | if(s->multiplex_xtra > BUFFER) |
| | 377 | len = BUFFER; |
| | 378 | else |
| | 379 | len = s->multiplex_xtra; |
| 375 | 380 | if(!s->ssl) |
| 376 | | len = read(s->sock, netbuffer, BUFFER); |
| | 381 | len = read(s->sock, netbuffer, len); |
| 377 | 382 | 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; |
| 381 | 387 | } |
| 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])); |
| 388 | 388 | continue; |
| 389 | 389 | } |
| … |
… |
|
| 407 | 407 | } |
| 408 | 408 | } |
| | 409 | |
| | 410 | err: |
| | 411 | perror("Error"); |
| 409 | 412 | |
| 410 | 413 | return NULL; |
| … |
… |
|
| 502 | 505 | void send_header(struct session * s, int id, int flags, int len) |
| 503 | 506 | { |
| 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); |
| 505 | 508 | char header[16]; |
| 506 | 509 | int * ptr = (int *) &header; |