*/
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.
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 {
} 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},
static const js_property_t socket_props[] = {
{"address", FSSocket::GetProperty, JSBase::DefaultSetProperty},
{"port", FSSocket::GetProperty, JSBase::DefaultSetProperty},
+ {"timeout", FSSocket::GetProperty, FSSocket::SetPropertyTimeOut},
{0}
};
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);