本文整理汇总了C++中PUBNUB_ASSERT函数的典型用法代码示例。如果您正苦于以下问题:C++ PUBNUB_ASSERT函数的具体用法?C++ PUBNUB_ASSERT怎么用?C++ PUBNUB_ASSERT使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了PUBNUB_ASSERT函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: prepare_port_and_hostname
static void prepare_port_and_hostname(pubnub_t *pb, uint16_t* p_port, char const** p_origin)
{
PUBNUB_ASSERT(pb_valid_ctx_ptr(pb));
PUBNUB_ASSERT_OPT((pb->state == PBS_READY) || (pb->state == PBS_WAIT_DNS_SEND));
*p_origin = PUBNUB_ORIGIN_SETTABLE ? pb->origin : PUBNUB_ORIGIN;
#if PUBNUB_USE_SSL
if (pb->flags.trySSL) {
PUBNUB_ASSERT(pb->options.useSSL);
*p_port = TLS_PORT;
}
#endif
#if PUBNUB_PROXY_API
switch (pb->proxy_type) {
case pbproxyHTTP_CONNECT:
if (!pb->proxy_tunnel_established) {
*p_origin = pb->proxy_hostname;
}
*p_port = pb->proxy_port;
break;
case pbproxyHTTP_GET:
*p_origin = pb->proxy_hostname;
*p_port = pb->proxy_port;
PUBNUB_LOG_TRACE("Using proxy: %s : %hu\n", *p_origin, *p_port);
break;
default:
break;
}
#endif
return;
}
示例2: pbpal_check_resolv_and_connect
enum pbpal_resolv_n_connect_result pbpal_check_resolv_and_connect(pubnub_t *pb)
{
#ifdef PUBNUB_CALLBACK_API
struct sockaddr_in dns_server;
struct sockaddr_in dest;
uint16_t port = HTTP_PORT;
pbpal_native_socket_t skt;
PUBNUB_ASSERT(pb_valid_ctx_ptr(pb));
PUBNUB_ASSERT_OPT(pb->state == PBS_WAIT_DNS_RCV);
#if PUBNUB_USE_SSL
if (pb->flags.trySSL) {
PUBNUB_ASSERT(pb->options.useSSL);
port = TLS_PORT;
}
#endif
#if PUBNUB_PROXY_API
if (pbproxyNONE != pb->proxy_type) {
port = pb->proxy_port;
}
#endif
skt = pb->pal.socket;
PUBNUB_ASSERT(SOCKET_INVALID != skt);
dns_server.sin_family = AF_INET;
dns_server.sin_port = htons(DNS_PORT);
get_dns_ip(&dns_server);
memset(&dest, '\0', sizeof dest);
switch (read_dns_response(skt, (struct sockaddr*)&dns_server, &dest)) {
case -1:
return pbpal_resolv_failed_rcv;
case +1:
return pbpal_resolv_rcv_wouldblock;
case 0:
break;
}
socket_close(skt);
return connect_TCP_socket(pb, dest, port);
#else
PUBNUB_UNUSED(pb);
/* Under regular BSD-ish sockets, this function should not be
called unless using async DNS, so this is an error */
return pbpal_connect_failed;
#endif /* PUBNUB_CALLBACK_API */
}
示例3: pubnub_init
pubnub_t* pubnub_init(pubnub_t *p, const char *publish_key, const char *subscribe_key)
{
PUBNUB_ASSERT(pb_valid_ctx_ptr(p));
pubnub_mutex_init(p->monitor);
pubnub_mutex_lock(p->monitor);
pbcc_init(&p->core, publish_key, subscribe_key);
if (PUBNUB_TIMERS_API) {
p->transaction_timeout_ms = PUBNUB_DEFAULT_TRANSACTION_TIMER;
#if defined(PUBNUB_DEFAULT_CONNECTION_TIMER)
p->connection_timeout_s = PUBNUB_DEFAULT_CONNECTION_TIMER;
#endif
#if defined(PUBNUB_CALLBACK_API)
p->previous = p->next = NULL;
#endif
}
#if defined(PUBNUB_CALLBACK_API)
p->cb = NULL;
p->user_data = NULL;
#endif
if (PUBNUB_ORIGIN_SETTABLE) {
p->origin = PUBNUB_ORIGIN;
}
p->state = PBS_IDLE;
p->trans = PBTT_NONE;
pbpal_init(p);
pubnub_mutex_unlock(p->monitor);
return p;
}
示例4: pbpal_resolv_and_connect
enum pubnub_res pbpal_resolv_and_connect(pubnub_t *pb)
{
struct freertos_sockaddr addr;
PUBNUB_ASSERT(pb_valid_ctx_ptr(pb));
PUBNUB_ASSERT_OPT((pb->state == PBS_IDLE) || (pb->state == PBS_WAIT_DNS));
addr.sin_port = FreeRTOS_htons(HTTP_PORT);
addr.sin_addr = FreeRTOS_gethostbyname(PUBNUB_ORIGIN_SETTABLE ? pb->origin : PUBNUB_ORIGIN);
if (addr.sin_addr == 0) {
return PNR_CONNECT_FAILED;
}
pb->pal.socket = FreeRTOS_socket(FREERTOS_AF_INET, FREERTOS_SOCK_STREAM, FREERTOS_IPPROTO_TCP);
if (pb->pal.socket == SOCKET_INVALID) {
return PNR_CONNECT_FAILED;
}
if (FreeRTOS_connect(pb->pal.socket, &addr, sizeof addr) != 0) {
FreeRTOS_closesocket(pb->pal.socket);
pb->pal.socket = SOCKET_INVALID;
return PNR_CONNECT_FAILED;
}
{
TickType_t tmval = pdMS_TO_TICKS(pb->transaction_timeout_ms);
FreeRTOS_setsockopt(pb->pal.socket, 0, FREERTOS_SO_RCVTIMEO, &tmval, sizeof tmval);
}
return PNR_OK;
}
示例5: pubnub_set_auth
void pubnub_set_auth(pubnub_t *pb, const char *auth)
{
PUBNUB_ASSERT(pb_valid_ctx_ptr(pb));
pubnub_mutex_lock(pb->monitor);
pbcc_set_auth(&pb->core, auth);
pubnub_mutex_unlock(pb->monitor);
}
示例6: pubnub_free
int pubnub_free(pubnub_t* pb)
{
int result = -1;
PUBNUB_ASSERT(check_ctx_ptr(pb));
PUBNUB_LOG_TRACE("pubnub_free(%p)\n", pb);
pubnub_mutex_lock(pb->monitor);
pbnc_stop(pb, PNR_CANCELLED);
if (PBS_IDLE == pb->state) {
PUBNUB_LOG_TRACE("pubnub_free(%p) PBS_IDLE\n", pb);
pb->state = PBS_NULL;
#if defined(PUBNUB_CALLBACK_API)
pbntf_requeue_for_processing(pb);
pubnub_mutex_unlock(pb->monitor);
#else
pubnub_mutex_unlock(pb->monitor);
pballoc_free_at_last(pb);
#endif
result = 0;
}
else {
PUBNUB_LOG_TRACE("pubnub_free(%p) pb->state=%d\n", pb, pb->state);
pubnub_mutex_unlock(pb->monitor);
}
return result;
}
示例7: save_socket
static void save_socket(struct SocketWatcherData *watcher, pubnub_t *pb)
{
size_t i;
pbpal_native_socket_t sockt = pubnub_get_native_socket(pb);
PUBNUB_ASSERT(watcher->apoll_size <= watcher->apoll_cap);
if (INVALID_SOCKET == sockt) {
return;
}
for (i = 0; i < watcher->apoll_size; ++i) {
PUBNUB_ASSERT_OPT(watcher->apoll[i].fd != sockt);
}
if (watcher->apoll_size == watcher->apoll_cap) {
size_t newcap = watcher->apoll_cap + 2;
WSAPOLLFD *npapoll = (WSAPOLLFD*)realloc(watcher->apoll, sizeof watcher->apoll[0] * newcap);
if (NULL == npapoll) {
return;
}
else {
pubnub_t **npapb = (pubnub_t**)realloc(watcher->apb, sizeof watcher->apb[0] * newcap);
watcher->apoll = npapoll;
if (NULL == npapb) {
return;
}
watcher->apb = npapb;
}
watcher->apoll_cap = newcap;
}
watcher->apoll[watcher->apoll_size].fd = sockt;
watcher->apoll[watcher->apoll_size].events = POLLOUT;
watcher->apb[watcher->apoll_size] = pb;
++watcher->apoll_size;
}
示例8: pubnub_await
enum pubnub_res pubnub_await(pubnub_t* pb)
{
pbmsref_t t0;
enum pubnub_res result;
bool stopped = false;
PUBNUB_ASSERT(pb_valid_ctx_ptr(pb));
pubnub_mutex_lock(pb->monitor);
t0 = pbms_start();
while (!pbnc_can_start_transaction(pb)) {
pbms_t delta;
pbnc_fsm(pb);
delta = pbms_elapsed(t0);
if (delta > pb->transaction_timeout_ms) {
if (!stopped) {
pbnc_stop(pb, PNR_TIMEOUT);
t0 = pbms_start();
stopped = true;
}
else {
break;
}
}
}
result = pb->core.last_result;
pubnub_mutex_unlock(pb->monitor);
return result;
}
示例9: pubnub_get_decrypted
enum pubnub_res pubnub_get_decrypted(pubnub_t *pb, char const* cipher_key, char *s, size_t *n)
{
char *msg;
size_t msg_len;
uint8_t decoded_msg[PUBNUB_BUF_MAXLEN];
pubnub_bymebl_t data = { (uint8_t*)s, *n };
pubnub_bymebl_t buffer = { decoded_msg, PUBNUB_BUF_MAXLEN };
PUBNUB_ASSERT(pb_valid_ctx_ptr(pb));
PUBNUB_ASSERT_OPT(cipher_key != NULL);
PUBNUB_ASSERT_OPT(s != NULL);
PUBNUB_ASSERT_OPT(n != NULL);
msg = (char*)pubnub_get(pb);
if (NULL == msg) {
return PNR_INTERNAL_ERROR;
}
msg_len = strlen(msg);
if ((msg[0] != '"') || (msg[msg_len-1] != '"')) {
return PNR_FORMAT_ERROR;
}
msg[msg_len - 1] = '\0';
++msg;
pubnub_json_string_unescape_slash(msg);
if (0 != pubnub_decrypt_buffered(cipher_key, msg, &data, &buffer)) {
return PNR_INTERNAL_ERROR;
}
*n = data.size;
data.ptr[data.size] = '\0';
return PNR_OK;
}
示例10: PUBNUB_ASSERT_OPT
pubnub_t *pubnub_timer_list_as_time_goes_by(pubnub_t **pplist, int time_passed_ms)
{
pubnub_t *list;
pubnub_t *expired_list = NULL;
PUBNUB_ASSERT_OPT(pplist != NULL);
PUBNUB_ASSERT_OPT(time_passed_ms > 0);
list = *pplist;
if (NULL == list) {
return NULL;
}
if (list->timeout_left_ms > time_passed_ms) {
list->timeout_left_ms -= time_passed_ms;
return NULL;
}
expired_list = list;
while (list->timeout_left_ms <= time_passed_ms) {
time_passed_ms -= list->timeout_left_ms;
if (NULL == list->next) {
*pplist = NULL;
return expired_list;
}
list = list->next;
}
list->timeout_left_ms -= time_passed_ms;
PUBNUB_ASSERT(list->previous != NULL);
list->previous->next = NULL;
list->previous = NULL;
*pplist = list;
return expired_list;
}
示例11: pubnub_get_decrypted_alloc
pubnub_bymebl_t pubnub_get_decrypted_alloc(pubnub_t *pb, char const* cipher_key)
{
char *msg;
size_t msg_len;
pubnub_bymebl_t result = { NULL, 0 };
PUBNUB_ASSERT(pb_valid_ctx_ptr(pb));
PUBNUB_ASSERT_OPT(cipher_key != NULL);
msg = (char*)pubnub_get(pb);
if (NULL == msg) {
return result;
}
msg_len = strlen(msg);
if ((msg[0] != '"') || (msg[msg_len-1] != '"')) {
return result;
}
msg[msg_len - 1] = '\0';
++msg;
pubnub_json_string_unescape_slash(msg);
result = pubnub_decrypt_alloc(cipher_key, msg);
if (NULL != result.ptr) {
result.ptr[result.size] = '\0';
}
return result;
}
示例12: pubnub_register_callback
enum pubnub_res pubnub_register_callback(pubnub_t *pb, pubnub_callback_t cb, void *user_data)
{
PUBNUB_ASSERT(pb_valid_ctx_ptr(pb));
pb->cb = cb;
pb->user_data = user_data;
return PNR_OK;
}
示例13: pubnub_set_uuid
void pubnub_set_uuid(pubnub_t *pb, const char *uuid)
{
PUBNUB_ASSERT(pb_valid_ctx_ptr(pb));
pubnub_mutex_lock(pb->monitor);
pbcc_set_uuid(&pb->core, uuid);
pubnub_mutex_unlock(pb->monitor);
}
示例14: pubnub_await
enum pubnub_res pubnub_await(pubnub_t *pb)
{
PUBNUB_ASSERT(pb_valid_ctx_ptr(pb));
while (pb->state != PBS_IDLE) {
pbnc_fsm(pb);
}
return pb->core.last_result;
}
示例15: PUBNUB_ASSERT
char const *pubnub_get_origin(pubnub_t const *pb)
{
PUBNUB_ASSERT(pb_valid_ctx_ptr(pb));
if (PUBNUB_ORIGIN_SETTABLE) {
return pb->origin;
}
return PUBNUB_ORIGIN;
}