FS-7933 [mod_v8] Implement timeout property for Socket() class in javascript.
This commit is contained in:
parent
ddf48b8602
commit
3f3cd7343b
|
@ -1233,6 +1233,19 @@ SWITCH_DECLARE(switch_status_t) switch_socket_recv(switch_socket_t *sock, char *
|
|||
*/
|
||||
SWITCH_DECLARE(switch_status_t) switch_socket_opt_set(switch_socket_t *sock, int32_t opt, int32_t on);
|
||||
|
||||
/**
|
||||
* Query socket timeout for the specified socket
|
||||
* @param sock The socket to query
|
||||
* @param t Socket timeout returned from the query.
|
||||
* <PRE>
|
||||
* t > 0 -- read and write calls return APR_TIMEUP if specified time
|
||||
* elapsess with no data read or written
|
||||
* t == 0 -- read and write calls never block
|
||||
* t < 0 -- read and write calls block
|
||||
* </PRE>
|
||||
*/
|
||||
SWITCH_DECLARE(switch_status_t) switch_socket_timeout_get(switch_socket_t *sock, switch_interval_time_t *t);
|
||||
|
||||
/**
|
||||
* Setup socket timeout for the specified socket
|
||||
* @param sock The socket to set up.
|
||||
|
|
|
@ -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}
|
||||
};
|
||||
|
||||
|
|
|
@ -859,6 +859,11 @@ SWITCH_DECLARE(switch_status_t) switch_socket_opt_set(switch_socket_t *sock, int
|
|||
return apr_socket_opt_set(sock, opt, on);
|
||||
}
|
||||
|
||||
SWITCH_DECLARE(switch_status_t) switch_socket_timeout_get(switch_socket_t *sock, switch_interval_time_t *t)
|
||||
{
|
||||
return apr_socket_timeout_get(sock, t);
|
||||
}
|
||||
|
||||
SWITCH_DECLARE(switch_status_t) switch_socket_timeout_set(switch_socket_t *sock, switch_interval_time_t t)
|
||||
{
|
||||
return apr_socket_timeout_set(sock, t);
|
||||
|
|
Loading…
Reference in New Issue