@@ -204,7 +204,7 @@ Handle<Value> IOWatcher::Set(const Arguments& args) {
204204// make clean all
205205#ifdef DUMP_DEBUG
206206#define DEBUG_PRINT (fmt,...) \
207- fprintf (stderr, " %s :%d " fmt " \n " , __FILE__, __LINE__, ##__VA_ARGS__)
207+ fprintf (stderr, " (dump :%d) " fmt " \n " , __LINE__, ##__VA_ARGS__)
208208#else
209209#define DEBUG_PRINT (fmt,...)
210210#endif
@@ -285,6 +285,7 @@ void IOWatcher::Dump(EV_P_ ev_prepare *watcher, int revents) {
285285 size_t l = Buffer::Length (buf_object);
286286
287287 if (first /* ugly */ ) {
288+ first = false ; // ugly
288289 assert (offset < l);
289290 iov[iovcnt].iov_base = Buffer::Data (buf_object) + offset;
290291 iov[iovcnt].iov_len = l - offset;
@@ -294,8 +295,6 @@ void IOWatcher::Dump(EV_P_ ev_prepare *watcher, int revents) {
294295 }
295296 to_write += iov[iovcnt].iov_len ;
296297 iovcnt++;
297-
298- first = false ; // ugly
299298 }
300299
301300 ssize_t written = writev (io->watcher_ .fd , iov, iovcnt);
@@ -348,13 +347,15 @@ void IOWatcher::Dump(EV_P_ ev_prepare *watcher, int revents) {
348347 // serialized onto a buffer.
349348 size_t bucket_len = Buffer::Length (data_v->ToObject ());
350349
351- DEBUG_PRINT (" %ld bucket len: %ld" , bucket_index, bucket_len);
352350
353351 if (first) {
352+ assert (bucket_len > offset);
353+ first = false ;
354+ DEBUG_PRINT (" [%ld] bucket_len: %ld, offset: %ld" , bucket_index, bucket_len, offset);
354355 // Only on the first bucket does the offset matter.
355356 if (offset + written < bucket_len) {
356357 // we have not written the entire first bucket
357- DEBUG_PRINT (" %ld Only wrote part of the first buffer. "
358+ DEBUG_PRINT (" [ %ld] Only wrote part of the first buffer. "
358359 " setting watcher.offset = %ld" ,
359360 bucket_index,
360361 offset + written);
@@ -363,18 +364,22 @@ void IOWatcher::Dump(EV_P_ ev_prepare *watcher, int revents) {
363364 Integer::NewFromUnsigned (offset + written));
364365 break ;
365366 } else {
366- DEBUG_PRINT (" %ld wrote the whole first bucket. discarding." ,
367+ DEBUG_PRINT (" [ %ld] wrote the whole first bucket. discarding." ,
367368 bucket_index);
368369 // We have written the entire bucket, discard it.
369370 written -= bucket_len - offset;
370371 writer_node->Set (buckets_sym, bucket->Get (next_sym));
372+
373+ // Offset is now zero
374+ writer_node->Set (offset_sym, Integer::NewFromUnsigned (0 ));
371375 }
372376 } else {
373377 // not first
378+ DEBUG_PRINT (" [%ld] bucket_len: %ld" , bucket_index, bucket_len);
374379
375380 if (static_cast <size_t >(written) < bucket_len) {
376381 // Didn't write the whole bucket.
377- DEBUG_PRINT (" %ld Only wrote part of the buffer. "
382+ DEBUG_PRINT (" [ %ld] Only wrote part of the buffer. "
378383 " setting watcher.offset = %ld" ,
379384 bucket_index,
380385 offset + written);
@@ -383,13 +388,11 @@ void IOWatcher::Dump(EV_P_ ev_prepare *watcher, int revents) {
383388 break ;
384389 } else {
385390 // Wrote the whole bucket, drop it.
386- DEBUG_PRINT (" %ld wrote the whole bucket. discarding." , bucket_index);
391+ DEBUG_PRINT (" [ %ld] wrote the whole bucket. discarding." , bucket_index);
387392 written -= bucket_len;
388393 writer_node->Set (buckets_sym, bucket->Get (next_sym));
389394 }
390395 }
391-
392- first = false ;
393396 }
394397
395398 /*
0 commit comments