2
* Copyright 2015-2016 DataStax, Inc.
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
* you may not use this file except in compliance with the License.
6
* You may obtain a copy of the License at
8
* http://www.apache.org/licenses/LICENSE-2.0
10
* Unless required by applicable law or agreed to in writing, software
11
* distributed under the License is distributed on an "AS IS" BASIS,
12
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
* See the License for the specific language governing permissions and
14
* limitations under the License.
17
#include "php_driver.h"
18
#include "php_driver_types.h"
22
php_driver_future_wait_timed(CassFuture *future, zval *timeout TSRMLS_DC)
24
cass_duration_t timeout_us;
26
if (cass_future_ready(future)) return SUCCESS;
28
#if PHP_MAJOR_VERSION >= 7
29
if (timeout == NULL ||
30
Z_TYPE_P(timeout) == IS_NULL ||
31
Z_TYPE_P(timeout) == IS_UNDEF) {
33
if (timeout == NULL || Z_TYPE_P(timeout) == IS_NULL) {
36
cass_future_wait(future);
38
if ((Z_TYPE_P(timeout) == IS_LONG && Z_LVAL_P(timeout) > 0)) {
39
timeout_us = Z_LVAL_P(timeout) * 1000000;
40
} else if ((Z_TYPE_P(timeout) == IS_DOUBLE && Z_DVAL_P(timeout) > 0)) {
41
timeout_us = ceil(Z_DVAL_P(timeout) * 1000000);
43
INVALID_ARGUMENT_VALUE(timeout, "an positive number of seconds or null", FAILURE);
46
if (!cass_future_wait_timed(future, timeout_us)) {
47
zend_throw_exception_ex(php_driver_timeout_exception_ce, 0 TSRMLS_CC,
48
"Future hasn't resolved within %f seconds", timeout_us / 1000000.0);
57
php_driver_future_is_error(CassFuture *future TSRMLS_DC)
59
int rc = cass_future_error_code(future);
63
cass_future_error_message(future, &message, &message_len);
64
zend_throw_exception_ex(exception_class(rc), rc TSRMLS_CC,
65
"%.*s", (int) message_len, message);