diff --git a/src/serialport.cpp b/src/serialport.cpp index 26837e5..0b4ae23 100644 --- a/src/serialport.cpp +++ b/src/serialport.cpp @@ -151,6 +151,14 @@ void EIO_AfterWrite(uv_work_t* req) { QueuedWrite* queuedWrite = static_cast(req->data); WriteBaton* data = static_cast(queuedWrite->baton); + if (data->offset < data->bufferLength && !data->errorString[0]) { + // We're not done with this baton, so throw it right back onto the queue. + // Don't re-push the write in the event loop if there was an error; because same error could occur again! + // TODO: Add a uv_poll here for unix... + uv_queue_work(uv_default_loop(), req, EIO_Write, (uv_after_work_cb)EIO_AfterWrite); + return; + } + v8::Handle argv[2]; if(data->errorString[0]) { argv[0] = v8::Exception::Error(NanNew(data->errorString)); @@ -161,14 +169,6 @@ void EIO_AfterWrite(uv_work_t* req) { } data->callback->Call(2, argv); - if (data->offset < data->bufferLength && !data->errorString[0]) { - // We're not done with this baton, so throw it right back onto the queue. - // Don't re-push the write in the event loop if there was an error; because same error could occur again! - // TODO: Add a uv_poll here for unix... - uv_queue_work(uv_default_loop(), req, EIO_Write, (uv_after_work_cb)EIO_AfterWrite); - return; - } - uv_mutex_lock(&write_queue_mutex); QUEUE_REMOVE(&queuedWrite->queue);