Changeset 483
- Timestamp:
- 07/26/07 23:32:51 (1 year ago)
- Files:
-
- version_0/ext/cmain.cpp (modified) (3 diffs)
- version_0/ext/rubymain.cpp (modified) (1 diff)
- version_0/lib/em/streamer.rb (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
version_0/ext/cmain.cpp
r433 r483 383 383 * TODO, given that we want this to work only with small files, how about allocating 384 384 * the buffer on the stack rather than the heap? 385 * 386 * Modified 25Jul07. This now returns -1 on file-too-large; 0 for success, and a positive 387 * errno in case of other errors. 388 * 385 389 /* Contributed by Kirk Haines. 386 390 */ 387 391 388 char *data; 392 char data[32*1024]; 393 int r; 389 394 390 395 if (!EventMachine) … … 392 397 393 398 int Fd = open (filename, O_RDONLY); 399 394 400 if (Fd < 0) 395 throw runtime_error (strerror (errno)); 401 return errno; 402 // From here on, all early returns MUST close Fd. 396 403 397 404 struct stat st; 398 if (fstat (Fd, &st)) 399 throw runtime_error (strerror (errno)); 405 if (fstat (Fd, &st)) { 406 int e = errno; 407 close (Fd); 408 return e; 409 } 400 410 401 411 int filesize = st.st_size; … … 404 414 return 0; 405 415 } 406 407 data = (char*) malloc (filesize); 408 if (!data) 409 throw runtime_error ("No allocation"); 410 int r = read (Fd, data, filesize); 411 if (r < filesize) 412 throw runtime_error (strerror (errno)); 413 int rd = evma_send_data_to_connection (binding, data, r); 416 else if (filesize > sizeof(data)) { 417 close (Fd); 418 return -1; 419 } 420 421 422 r = read (Fd, data, filesize); 423 if (r != filesize) { 424 int e = errno; 425 close (Fd); 426 return e; 427 } 428 evma_send_data_to_connection (binding, data, r); 414 429 close (Fd); 415 free (data); 416 417 return rd; 418 } 419 420 421 422 430 431 return 0; 432 } 433 434 435 436 version_0/ext/rubymain.cpp
r433 r483 380 380 static VALUE t_send_file_data (VALUE self, VALUE signature, VALUE filename) 381 381 { 382 383 /* The current implementation of evma_send_file_data_to_connection enforces a strict 384 * upper limit on the file size it will transmit (currently 32K). The function returns 385 * zero on success, -1 if the requested file exceeds its size limit, and a positive 386 * number for other errors. 387 * TODO: Positive return values are actually errno's, which is probably the wrong way to 388 * do this. For one thing it's ugly. For another, we can't be sure zero is never a real errno. 389 */ 390 382 391 int b = evma_send_file_data_to_connection (StringValuePtr(signature), StringValuePtr(filename)); 383 return INT2NUM (b); 392 if (b == -1) 393 rb_raise(rb_eRuntimeError, "File too large. send_file_data() supports files under 32k."); 394 if (b > 0) { 395 char *err = strerror (b); 396 char buf[1024]; 397 memset (buf, 0, sizeof(buf)); 398 snprintf (buf, sizeof(buf)-1, ": %s %s", StringValuePtr(filename),(err?err:"???")); 399 400 rb_raise (rb_eIOError, buf); 401 } 402 403 return INT2NUM (0); 384 404 } 385 405 version_0/lib/em/streamer.rb
r472 r483 27 27 module EventMachine 28 28 class FileStreamer 29 MappingThreshold = 819229 MappingThreshold = 16384 30 30 BackpressureLevel = 50000 31 ChunkSize = 409631 ChunkSize = 16384 32 32 33 33 include Deferrable … … 50 50 def stream_without_mapping filename 51 51 if @http_chunks 52 @connection.send_data "#{format("%x",@size)}\r\n" 52 #@connection.send_data "#{format("%x",@size)}\r\n" 53 @connection.send_data "#{@size.to_s(16)}\r\n" 53 54 @connection.send_file_data filename 54 55 @connection.send_data "\r\n0\r\n\r\n" … … 74 75 if @connection.get_outbound_data_size > BackpressureLevel 75 76 EventMachine::next_tick {stream_one_chunk} 77 break 76 78 else 77 79 len = @size - @position 78 80 len = ChunkSize if (len > ChunkSize) 79 81 80 @connection.send_data( "#{format("%x",len)}\r\n" ) if @http_chunks 82 #@connection.send_data( "#{format("%x",len)}\r\n" ) if @http_chunks 83 @connection.send_data( "#{len.to_s(16)}\r\n" ) if @http_chunks 81 84 @connection.send_data( @mapping.get_chunk( @position, len )) 82 85 @connection.send_data("\r\n") if @http_chunks