Well, it looks good except for one problem: If I am not incorrect this no longer bypass the pike-level code when reading from 'pure' FD:s.
That was the reason for the check for t->fd, anyway.
/ Per Hedbor ()
Previous text:
2004-06-21 04:11: Subject: Bilaga till: Re: Bilaga till: Drowning in the Shuffler (SEGV)
Index: Shuffler.cmod
RCS file: /pike/data/cvsroot/Pike/7.7/src/post_modules/Shuffler/Shuffler.cmod,v retrieving revision 1.29 diff -u -r1.29 Shuffler.cmod --- Shuffler.cmod 4 Apr 2004 15:03:37 -0000 1.29 +++ Shuffler.cmod 21 Jun 2004 01:45:20 -0000 @@ -81,6 +81,8 @@
PIKECLASS Shuffle {
- CVAR struct fd_callback_box box; /* must be first? */
- PIKEVAR object shuffler; /*! @decl Shuffler shuffler; *! The @[Shuffler] that owns this @[Shuffle] object
@@ -102,52 +104,41 @@ CVAR struct object *this_obj; /* callbacks only have the struct */ CVAR struct object *file_obj; CVAR int callback;
CVAR int write_callback;
CVAR int fd; CVAR int sent; CVAR ShuffleState state;
CVAR struct data leftovers;
static void _send_more( int fd, struct Shuffle_struct *t );
- static void _send_more( struct Shuffle_struct *t ); static void __set_callbacks( struct Shuffle_struct *t ) {
- SHUFFLE_DEBUG2("__set_calllbacks(%s)\n", t,(t->fd>0?"C":"Pike") );
- if( t->fd >= 0 )
set_write_callback( t->fd, (void *)_send_more, t );
- else if( t->file_obj && t->file_obj->prog )
- {
ref_push_object( t->this_obj );
Pike_sp[-1].type = PIKE_T_FUNCTION;
Pike_sp[-1].subtype = t->write_callback;
safe_apply( t->file_obj, "set_write_callback", 1 );
pop_stack();
- }
- SHUFFLE_DEBUG2("__set_calllbacks(%s)\n", t,(t->box.fd>0?"C":"Pike") );
- if( t->box.fd >= 0 || t->file_obj && t->file_obj->prog )
elseset_fd_callback_events(&t->box, PIKE_BIT_FD_WRITE);
{ SHUFFLE_DEBUG1("EEP: No destination! Cannot set callbacks\n",t);
} }
static void __remove_callbacks( struct Shuffle_struct *t ) {
SHUFFLE_DEBUG2("__remove_calllbacks(%s)\n", t, (t->fd>=0?"C":"Pike") );
if( t->fd >= 0 )
set_write_callback( t->fd, 0,0 );
else if( t->file_obj && t->file_obj->prog )
{
push_int(0);
safe_apply( t->file_obj, "set_write_callback", 1 );
pop_stack();
}
- SHUFFLE_DEBUG2("__remove_calllbacks(%s)\n", t, (t->box.fd>=0?"C":"Pike") );
- if( t->box.fd >= 0 || t->file_obj && t->file_obj->prog )
elseset_fd_callback_events(&t->box, 0);
- { SHUFFLE_DEBUG1("EEP: No destination! Cannot remove callbacks\n",t);
- } }
- static int got_shuffler_event(struct fd_callback_box*box, int event) {
- struct Shuffle_struct*u = (struct Shuffle_struct*) box;
+#ifdef PIKE_DEBUG
- if (event != PIKE_FD_WRITE)
Pike_fatal ("Got unexpected event %d.\n", event);
+#endif
- _send_more(u);
- }
- PIKEFUN void set_throttler( object t ) /*! @decl void set_throttler(Throttler t) *! Calling this function overrides the @[Shuffler] global throttler.
@@ -212,9 +203,8 @@ debug_malloc_touch(THIS->this_obj); THIS->callback = find_identifier("send_more_callback",Pike_fp->current_object->prog);
- THIS->write_callback =
find_identifier("write_callback",Pike_fp->current_object->prog);
INIT_FD_CALLBACK_BOX (&THIS->box, default_backend, 0,
-1, 0, got_shuffler_event);
SHUFFLE_DEBUG1("init()\n", THIS ); }
@@ -222,7 +212,7 @@ EXIT { SHUFFLE_DEBUG1("exit()\n", THIS );
- THIS->fd = -1;
- THIS->box.fd = -1; if( THIS->file_obj ) { free_object( THIS->file_obj );
@@ -266,10 +256,10 @@ __send_more_callback( t, amount ); }
- static void _send_more( int fd, struct Shuffle_struct *t )
- static void _send_more(struct Shuffle_struct *t) { int l = BLOCK;
- SHUFFLE_DEBUG2("_send_more(%d)\n", t, fd );
- SHUFFLE_DEBUG2("_send_more(%d)\n", t, t->box.fd ); if( t->leftovers.len ) l = t->leftovers.len; _request( t, l );
@@ -454,10 +444,10 @@ SHUFFLE_DEBUG2("__send_more_callback(): sending(%d)\n", t, MINIMUM(amount,t->leftovers.len)); sent = -1;
- if( t->fd >= 0 )
- if( t->box.fd >= 0 ) { THREADS_ALLOW();
sent = fd_write( t->fd, t->leftovers.data+t->leftovers.off,
}sent = fd_write( t->box.fd, t->leftovers.data+t->leftovers.off, MINIMUM(amount,t->leftovers.len) ); THREADS_DISALLOW();
@@ -519,15 +509,6 @@ _give_back( THIS, amount ); }
- /*! @decl void write_callback( mixed|void x )
- */
- PIKEFUN void write_callback( mixed|void x )
- optflags OPT_SIDE_EFFECT;
- {
- SHUFFLE_DEBUG1("write_callback()\n", THIS );
- _send_more( 0,THIS );
- }
- /*! @decl void create(object fd, object shuffler, mixed throttler,@ *! mixed backend) */
@@ -553,20 +534,17 @@ }
if (find_identifier("query_fd", fd->prog) < 0)
THIS->fd = -1;
else { safe_apply( fd, "query_fd", 0 );THIS->box.fd = -1;
THIS->fd = Pike_sp[-1].u.integer;
}THIS->box.fd = Pike_sp[-1].u.integer; pop_stack();
- if( THIS->fd >= 0 )
- if( THIS->box.fd >= 0 ) {
set_nonblocking( THIS->fd, 1 );
set_read_callback( THIS->fd, 0, 0 );
set_write_callback( THIS->fd, 0, 0 );
set_read_oob_callback( THIS->fd, 0, 0 );
set_write_oob_callback( THIS->fd, 0, 0 );
set_nonblocking( THIS->box.fd, 1 );
} else {set_fd_callback_events(&THIS->box, 0);
@@ -577,7 +555,7 @@ pop_stack(); }
- if( (THIS->fd >= 0) && (backend->type == PIKE_T_OBJECT) )
- if( (THIS->box.fd >= 0) && (backend->type == PIKE_T_OBJECT) ) { ref_push_object( THIS->file_obj ); safe_apply( backend->u.object, "add_file", 1 );
/ Brevbäraren