That's a good suggestion.
Please don't. :-)
The real code in my daemons is closer to this:
void read_callback( mixed ignore, string x ) { while( strlen( x ) ) { int len; if( strlen( x ) < 4 ) x += fd->read( 4-strlen(x) ); sscanf( x, "%4c%s", len, x ); if( strlen( x ) < len ) x += fd->read( len-strlen(x) ); if( mixed e = catch(handle_command( x[..len-1] )) ) { werror( describe_backtrace( e ) ); exit( 1 ); } x = x[len..]; } }
Please note that I am reading data in the read callback.
It seems somewhat pointless to have to add fd->set_read_callback( 0 ) at the beginning and fd->set_read_callback( read_callback ) at the end.
What I would really like, btw, is a read callback that does not do the actual read() call.
/ Per Hedbor ()
Previous text:
2003-03-19 15:47: Subject: I/O callbacks in blocking mode
How would there be a "disastrous hang"? /.../
It has been discussed later on in this thread. I suggest you read it through before responding.
If you want to "protect" the user from shooting himself in the foot, I'd rather suggest a check in the read() function that you don't have a read_callback at the same time as you are manually doing a read(). That would break fewer programs. I still think it would be unnecessary pampering though.
That's a good suggestion. I see it as a good measure to track down bugs more efficiently; in a high level language I don't see any real point in allowing error prone situations just because it would be "pampering" otherwise. That's rather one of the points with high level languages.
/ Martin Stjernholm, Roxen IS