mirror of
https://github.com/siemens-mobile-hacks/node-serialport-bindings-cpp.git
synced 2026-11-25 18:37:19 +00:00
Update the errors for unix to always include the err string and tests for close (#790)
This commit is contained in:
parent
c446c8d53d
commit
cf41ef76bd
4 changed files with 33 additions and 9 deletions
|
|
@ -386,17 +386,15 @@ NAN_METHOD(Close) {
|
|||
|
||||
void EIO_AfterClose(uv_work_t* req) {
|
||||
Nan::HandleScope scope;
|
||||
|
||||
CloseBaton* data = static_cast<CloseBaton*>(req->data);
|
||||
|
||||
v8::Local<v8::Value> argv[1];
|
||||
if (data->errorString[0]) {
|
||||
argv[0] = v8::Exception::Error(Nan::New<v8::String>(data->errorString).ToLocalChecked());
|
||||
} else {
|
||||
argv[0] = Nan::Undefined();
|
||||
argv[0] = Nan::Null();
|
||||
|
||||
// We don't have an error, so clean up the write queue for that fd
|
||||
|
||||
_WriteQueue *q = qForFD(data->fd);
|
||||
if (q) {
|
||||
q->lock();
|
||||
|
|
@ -407,7 +405,6 @@ void EIO_AfterClose(uv_work_t* req) {
|
|||
del_q->remove();
|
||||
}
|
||||
q->unlock();
|
||||
|
||||
deleteQForFD(data->fd);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -129,7 +129,7 @@ void EIO_Open(uv_work_t* req) {
|
|||
int fd = open(data->path, flags);
|
||||
|
||||
if (-1 == fd) {
|
||||
snprintf(data->errorString, sizeof(data->errorString), "Cannot open %s", data->path);
|
||||
snprintf(data->errorString, sizeof(data->errorString), "Error: %s, cannot open %s", strerror(errno), data->path);
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -353,7 +353,7 @@ void EIO_Write(uv_work_t* req) {
|
|||
|
||||
// The write call might be interrupted, if it is we just try again immediately.
|
||||
if (errno != EINTR) {
|
||||
snprintf(data->errorString, sizeof(data->errorString), "Error %s calling write(...)", strerror(errno) );
|
||||
snprintf(data->errorString, sizeof(data->errorString), "Error: %s, calling write", strerror(errno));
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -372,7 +372,7 @@ void EIO_Write(uv_work_t* req) {
|
|||
void EIO_Close(uv_work_t* req) {
|
||||
CloseBaton* data = static_cast<CloseBaton*>(req->data);
|
||||
if (-1 == close(data->fd)) {
|
||||
snprintf(data->errorString, sizeof(data->errorString), "Unable to close fd %d, errno: %d", data->fd, errno);
|
||||
snprintf(data->errorString, sizeof(data->errorString), "Error: %s, unable to close fd %d", strerror(errno), data->fd);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -15,6 +15,8 @@ switch (process.platform) {
|
|||
platform = 'unix';
|
||||
}
|
||||
|
||||
console.log('Testing on ' + platform);
|
||||
|
||||
var defaultPortOpenOptions = {
|
||||
baudRate: 9600,
|
||||
parity: 'none',
|
||||
|
|
@ -47,7 +49,7 @@ describe('SerialPortBinding', function () {
|
|||
});
|
||||
|
||||
if (!testPort) {
|
||||
it('Cannot be tested as we have no test ports on ' + platform);
|
||||
it('Cannot be tested further. Set the TEST_PORT env var with an available serialport for more testing.');
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -60,6 +62,31 @@ describe('SerialPortBinding', function () {
|
|||
});
|
||||
});
|
||||
|
||||
describe('#close', function() {
|
||||
it('errors when providing a bad file descriptor', function(done) {
|
||||
SerialPortBinding.close(-1, function(err) {
|
||||
assert.instanceOf(err, Error);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
if (!testPort) {
|
||||
it('Cannot be tested further. Set the TEST_PORT env var with an available serialport for more testing.');
|
||||
return;
|
||||
}
|
||||
|
||||
it('closes an open file descriptor', function(done) {
|
||||
SerialPortBinding.open(testPort, defaultPortOpenOptions, function(err, fd) {
|
||||
assert.isNull(err);
|
||||
assert.isNumber(fd);
|
||||
SerialPortBinding.close(fd, function(err) {
|
||||
assert.isNull(err);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('#list', function() {
|
||||
it('returns an array', function(done) {
|
||||
SerialPortBinding.list(function(err, data) {
|
||||
|
|
|
|||
|
|
@ -31,7 +31,7 @@ describe('SerialPort', function () {
|
|||
var testPort = process.env.TEST_PORT;
|
||||
|
||||
if (!testPort) {
|
||||
it('Cannot be tested as we have no test ports');
|
||||
it('Cannot be tested further. Set the TEST_PORT env var with an available serialport for more testing.');
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue