Handle error on recv
This commit is contained in:
parent
6b9a74fec8
commit
78a25f9e1d
1 changed files with 8 additions and 0 deletions
|
|
@ -16,6 +16,10 @@ Napi::Object NodeSRT::Init(Napi::Env env, Napi::Object exports) {
|
|||
InstanceMethod("close", &NodeSRT::Close),
|
||||
InstanceMethod("read", &NodeSRT::Read),
|
||||
InstanceMethod("write", &NodeSRT::Write),
|
||||
|
||||
StaticValue("SRTO_MSS", Napi::Number::New(env, 0)),
|
||||
StaticValue("SRTO_SNDSYN", Napi::Number::New(env, 1)),
|
||||
|
||||
});
|
||||
|
||||
constructor = Napi::Persistent(func);
|
||||
|
|
@ -161,6 +165,10 @@ Napi::Value NodeSRT::Read(const Napi::CallbackInfo& info) {
|
|||
memset(&buffer, 0, bufferSize);
|
||||
|
||||
int nb = srt_recvmsg(socketValue, (char *)buffer, (int)bufferSize);
|
||||
if (nb == SRT_ERROR) {
|
||||
Napi::Error::New(env, srt_getlasterror_str()).ThrowAsJavaScriptException();
|
||||
return Napi::Number::New(env, SRT_ERROR);
|
||||
}
|
||||
return Napi::Buffer<uint8_t>::Copy(env, buffer, nb);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue