Changeset 625
- Timestamp:
- 12/27/07 20:25:05 (11 months ago)
- Files:
-
- version_0/ext/em.cpp (modified) (8 diffs)
- version_0/ext/em.h (modified) (1 diff)
- version_0/ext/extconf.rb (modified) (1 diff)
- version_0/ext/rubymain.cpp (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
version_0/ext/em.cpp
r594 r625 385 385 assert (epfd != -1); 386 386 struct epoll_event ev [MaxEpollDescriptors]; 387 int s = epoll_wait (epfd, ev, MaxEpollDescriptors, 10);387 int s = epoll_wait (epfd, ev, MaxEpollDescriptors, 50); 388 388 if (s > 0) { 389 389 for (int i=0; i < s; i++) { … … 491 491 492 492 493 494 /************************** 495 SelectData_t::SelectData_t 496 **************************/ 497 498 SelectData_t::SelectData_t() 499 { 500 maxsocket = 0; 501 FD_ZERO (&fdreads); 502 FD_ZERO (&fdwrites); 503 } 504 505 506 /***************** 507 _SelectDataSelect 508 *****************/ 509 510 static VALUE _SelectDataSelect (void *v) 511 { 512 SelectData_t *sd = (SelectData_t*)v; 513 sd->nSockets = select (sd->maxsocket+1, &(sd->fdreads), &(sd->fdwrites), NULL, &(sd->tv)); 514 return Qnil; 515 } 516 517 /********************* 518 SelectData_t::_Select 519 *********************/ 520 521 int SelectData_t::_Select() 522 { 523 #ifdef HAVE_TBR 524 rb_thread_blocking_region (_SelectDataSelect, (void*)this, RB_UBF_DFL, 0); 525 return nSockets; 526 #endif 527 528 #ifndef HAVE_TBR 529 return rb_thread_select (maxsocket+1, &fdreads, &fdwrites, NULL, &tv); 530 #endif 531 } 532 533 534 493 535 /****************************** 494 536 EventMachine_t::_RunSelectOnce … … 526 568 */ 527 569 570 SelectData_t SelectData; 571 /* 528 572 fd_set fdreads, fdwrites; 529 573 FD_ZERO (&fdreads); … … 531 575 532 576 int maxsocket = 0; 577 */ 533 578 534 579 // Always read the loop-breaker reader. … … 537 582 // Windows has a version of the Unix pipe() library function, but it doesn't 538 583 // give you back descriptors that are selectable. 539 FD_SET (LoopBreakerReader, & fdreads);540 if ( maxsocket < LoopBreakerReader)541 maxsocket = LoopBreakerReader;584 FD_SET (LoopBreakerReader, &(SelectData.fdreads)); 585 if (SelectData.maxsocket < LoopBreakerReader) 586 SelectData.maxsocket = LoopBreakerReader; 542 587 543 588 // prepare the sockets for reading and writing … … 550 595 551 596 if (ed->SelectForRead()) 552 FD_SET (sd, & fdreads);597 FD_SET (sd, &(SelectData.fdreads)); 553 598 if (ed->SelectForWrite()) 554 FD_SET (sd, & fdwrites);555 556 if ( maxsocket < sd)557 maxsocket = sd;599 FD_SET (sd, &(SelectData.fdwrites)); 600 601 if (SelectData.maxsocket < sd) 602 SelectData.maxsocket = sd; 558 603 } 559 604 … … 561 606 { // read and write the sockets 562 607 //timeval tv = {1, 0}; // Solaris fails if the microseconds member is >= 1000000. 563 timeval tv = Quantum; 564 int s = EmSelect (maxsocket+1, &fdreads, &fdwrites, NULL, &tv); 608 //timeval tv = Quantum; 609 SelectData.tv = Quantum; 610 int s = SelectData._Select(); 611 //rb_thread_blocking_region(xxx,(void*)&SelectData,RB_UBF_DFL,0); 612 //int s = EmSelect (SelectData.maxsocket+1, &(SelectData.fdreads), &(SelectData.fdwrites), NULL, &(SelectData.tv)); 613 //int s = SelectData.nSockets; 565 614 if (s > 0) { 566 615 /* Changed 01Jun07. We used to handle the Loop-breaker right here. … … 580 629 assert (sd != INVALID_SOCKET); 581 630 582 if (FD_ISSET (sd, & fdwrites))631 if (FD_ISSET (sd, &(SelectData.fdwrites))) 583 632 ed->Write(); 584 if (FD_ISSET (sd, & fdreads))633 if (FD_ISSET (sd, &(SelectData.fdreads))) 585 634 ed->Read(); 586 635 } 587 636 588 if (FD_ISSET (LoopBreakerReader, & fdreads))637 if (FD_ISSET (LoopBreakerReader, &(SelectData.fdreads))) 589 638 _ReadLoopBreaker(); 590 639 } version_0/ext/em.h
r592 r625 137 137 138 138 139 /******************* 140 struct SelectData_t 141 *******************/ 142 143 struct SelectData_t 144 { 145 SelectData_t(); 146 147 int _Select(); 148 149 int maxsocket; 150 fd_set fdreads; 151 fd_set fdwrites; 152 timeval tv; 153 int nSockets; 154 }; 155 139 156 140 157 version_0/ext/extconf.rb
r533 r625 117 117 end 118 118 119 if have_func('rb_thread_blocking_region') and have_macro('RB_UBF_DFL', 'ruby.h') 120 flags << "-DHAVE_TBR" 121 end 122 119 123 dir_config('ssl', "#{ENV['OPENSSL']}/include", ENV['OPENSSL']) 120 124 # Check for libcrypto twice, before and after ssl. That's because on some platforms version_0/ext/rubymain.cpp
r591 r625 32 32 33 33 static VALUE Intern_at_signature; 34 static VALUE Intern_at_timers; 35 static VALUE Intern_at_conns; 36 static VALUE Intern_event_callback; 37 static VALUE Intern_run_deferred_callbacks; 38 static VALUE Intern_delete; 39 static VALUE Intern_call; 40 static VALUE Intern_receive_data; 34 41 35 42 … … 40 47 static void event_callback (const char *a1, int a2, const char *a3, int a4) 41 48 { 42 rb_funcall (EmModule, rb_intern ("event_callback"), 3, rb_str_new2(a1), (a2 << 1) | 1, rb_str_new(a3,a4)); 49 if (a2 == EM_CONNECTION_READ) { 50 VALUE t = rb_ivar_get (EmModule, Intern_at_conns); 51 VALUE q = rb_hash_aref (t, rb_str_new2(a1)); 52 if (q == Qnil) 53 rb_raise (rb_eRuntimeError, "no connection"); 54 rb_funcall (q, Intern_receive_data, 1, rb_str_new (a3, a4)); 55 } 56 else if (a2 == EM_LOOPBREAK_SIGNAL) { 57 rb_funcall (EmModule, Intern_run_deferred_callbacks, 0); 58 } 59 else if (a2 == EM_TIMER_FIRED) { 60 VALUE t = rb_ivar_get (EmModule, Intern_at_timers); 61 VALUE q = rb_funcall (t, Intern_delete, 1, rb_str_new(a3, a4)); 62 if (q == Qnil) 63 rb_raise (rb_eRuntimeError, "no timer"); 64 rb_funcall (q, Intern_call, 0); 65 } 66 else 67 rb_funcall (EmModule, Intern_event_callback, 3, rb_str_new2(a1), (a2 << 1) | 1, rb_str_new(a3,a4)); 43 68 } 44 69 … … 497 522 // Tuck away some symbol values so we don't have to look 'em up every time we need 'em. 498 523 Intern_at_signature = rb_intern ("@signature"); 524 Intern_at_timers = rb_intern ("@timers"); 525 Intern_at_conns = rb_intern ("@conns"); 526 527 Intern_event_callback = rb_intern ("event_callback"); 528 Intern_run_deferred_callbacks = rb_intern ("run_deferred_callbacks"); 529 Intern_delete = rb_intern ("delete"); 530 Intern_call = rb_intern ("call"); 531 Intern_receive_data = rb_intern ("receive_data"); 499 532 500 533 // INCOMPLETE, we need to define class Connections inside module EventMachine
