mirror of
https://github.com/signalwire/freeswitch.git
synced 2026-07-24 05:02:10 +00:00
FS-7933 [mod_v8] Implement timeout property for Socket() class in javascript.
This commit is contained in:
@@ -67,6 +67,7 @@ public:
|
||||
JS_SOCKET_FUNCTION_DEF(ReadBytes);
|
||||
JS_SOCKET_FUNCTION_DEF(Read);
|
||||
JS_SOCKET_GET_PROPERTY_DEF(GetProperty);
|
||||
JS_SOCKET_SET_PROPERTY_DEF(SetPropertyTimeOut);
|
||||
};
|
||||
|
||||
#endif /* FS_SOCKET_H */
|
||||
|
||||
@@ -175,7 +175,7 @@ JS_SOCKET_FUNCTION_IMPL(ReadBytes)
|
||||
|
||||
ret = switch_socket_recv(this->_socket, this->_read_buffer, &len);
|
||||
if (ret != SWITCH_STATUS_SUCCESS) {
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "switch_socket_send failed: %d.\n", ret);
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "switch_socket_recv failed: %d.\n", ret);
|
||||
info.GetReturnValue().Set(false);
|
||||
return;
|
||||
} else {
|
||||
@@ -282,11 +282,27 @@ JS_SOCKET_GET_PROPERTY_IMPL(GetProperty)
|
||||
} else {
|
||||
info.GetReturnValue().Set(Integer::New(info.GetIsolate(), 0));
|
||||
}
|
||||
} else if (!strcmp(js_safe_str(*str), "timeout")) {
|
||||
switch_interval_time_t timeout;
|
||||
|
||||
switch_socket_timeout_get(this->_socket, &timeout);
|
||||
|
||||
info.GetReturnValue().Set(Int32::New(info.GetIsolate(), (int32_t)timeout));
|
||||
} else {
|
||||
info.GetIsolate()->ThrowException(String::NewFromUtf8(info.GetIsolate(), "Bad property"));
|
||||
}
|
||||
}
|
||||
|
||||
JS_SOCKET_SET_PROPERTY_IMPL(SetPropertyTimeOut)
|
||||
{
|
||||
if (!this->_socket) {
|
||||
info.GetIsolate()->ThrowException(String::NewFromUtf8(info.GetIsolate(), "Socket is not active"));
|
||||
return;
|
||||
}
|
||||
|
||||
switch_socket_timeout_set(this->_socket, value->Int32Value());
|
||||
}
|
||||
|
||||
static const js_function_t socket_methods[] = {
|
||||
{"connect", FSSocket::Connect},
|
||||
{"close", FSSocket::Close},
|
||||
@@ -299,6 +315,7 @@ static const js_function_t socket_methods[] = {
|
||||
static const js_property_t socket_props[] = {
|
||||
{"address", FSSocket::GetProperty, JSBase::DefaultSetProperty},
|
||||
{"port", FSSocket::GetProperty, JSBase::DefaultSetProperty},
|
||||
{"timeout", FSSocket::GetProperty, FSSocket::SetPropertyTimeOut},
|
||||
{0}
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user