Skip to content

Fix/multiple addresses loop #215

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 7 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 41 additions & 30 deletions core/pubnub_pubsubapi.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,45 +22,45 @@ pubnub_t* pubnub_init(pubnub_t* p, const char* publish_key, const char* subscrib
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;
p->transaction_timeout_ms = PUBNUB_DEFAULT_TRANSACTION_TIMER;
p->wait_connect_timeout_ms = PUBNUB_DEFAULT_WAIT_CONNECT_TIMER;
#if defined(PUBNUB_CALLBACK_API)
#if defined(PUBNUB_NTF_RUNTIME_SELECTION)
if (PNA_CALLBACK == p->api_policy) {
p->previous = p->next = NULL;
}
#else
#else
p->previous = p->next = NULL;
#endif /* PUBNUB_NTF_RUNTIME_SELECTION */
#endif /* defined(PUBNUB_CALLBACK_API) */
}
#if defined(PUBNUB_CALLBACK_API)
#if defined(PUBNUB_NTF_RUNTIME_SELECTION)
if (PNA_CALLBACK == p->api_policy) {
p->cb = NULL;
p->user_data = NULL;
p->cb = NULL;
p->user_data = NULL;
p->flags.sent_queries = 0;
}
#else
p->cb = NULL;
p->user_data = NULL;
p->cb = NULL;
p->user_data = NULL;
p->flags.sent_queries = 0;
#endif /* PUBNUB_NTF_RUNTIME_SELECTION */
#endif /* defined(PUBNUB_CALLBACK_API) */
if (PUBNUB_ORIGIN_SETTABLE) {
p->origin = PUBNUB_ORIGIN;
p->port = INITIAL_PORT_VALUE;
p->port = INITIAL_PORT_VALUE;
}
#if PUBNUB_BLOCKING_IO_SETTABLE
#if defined(PUBNUB_CALLBACK_API)
#if defined(PUBNUB_NTF_RUNTIME_SELECTION)
switch (p->api_policy) {
case PNA_CALLBACK:
p->options.use_blocking_io = false;
break;
case PNA_SYNC:
p->options.use_blocking_io = true;
break;
case PNA_CALLBACK:
p->options.use_blocking_io = false;
break;
case PNA_SYNC:
p->options.use_blocking_io = true;
break;
}
#else
p->options.use_blocking_io = false;
Expand All @@ -70,14 +70,14 @@ pubnub_t* pubnub_init(pubnub_t* p, const char* publish_key, const char* subscrib
#endif
#endif /* PUBNUB_BLOCKING_IO_SETTABLE */
#if PUBNUB_USE_AUTO_HEARTBEAT
p->thumperIndex = UNASSIGNED;
p->channelInfo.channel = NULL;
p->thumperIndex = UNASSIGNED;
p->channelInfo.channel = NULL;
p->channelInfo.channel_group = NULL;
#endif /* PUBNUB_AUTO_HEARTBEAT */

p->state = PBS_IDLE;
p->trans = PBTT_NONE;
p->options.use_http_keep_alive = true;
p->state = PBS_IDLE;
p->trans = PBTT_NONE;
p->options.use_http_keep_alive = true;
#if PUBNUB_USE_IPV6
/* IPv4 connectivity type by default. */
p->options.ipv6_connectivity = false;
Expand All @@ -89,6 +89,16 @@ pubnub_t* pubnub_init(pubnub_t* p, const char* publish_key, const char* subscrib
p->keep_alive.timeout = 50;
#endif
pbpal_init(p);
#if PUBNUB_USE_MULTIPLE_ADDRESSES
memset(&(p->spare_addresses.ipv4_addresses),
0,
sizeof p->spare_addresses.ipv4_addresses);
#if PUBNUB_USE_IPV6
memset(&(p->spare_addresses.ipv6_addresses),
0,
sizeof p->spare_addresses.ipv6_addresses);
#endif /* PUBNUB_USE_IPV6 */
#endif /* PUBNUB_USE_MULTIPLE_ADDRESSES */
#if PUBNUB_PROXY_API
p->proxy_type = pbproxyNONE;
p->proxy_hostname[0] = '\0';
Expand All @@ -112,7 +122,7 @@ pubnub_t* pubnub_init(pubnub_t* p, const char* publish_key, const char* subscrib
p->proxy_auth_scheme = pbhtauNone;
p->proxy_auth_username = NULL;
p->proxy_auth_password = NULL;
p->realm[0] = '\0';
p->realm[0] = '\0';
#endif /* PUBNUB_PROXY_API */

#if PUBNUB_RECEIVE_GZIP_RESPONSE
Expand Down Expand Up @@ -156,9 +166,7 @@ enum pubnub_res pubnub_publish(pubnub_t* pb, const char* channel, const char* me
}


enum pubnub_res pubnub_signal(pubnub_t* pb,
const char* channel,
const char* message)
enum pubnub_res pubnub_signal(pubnub_t* pb, const char* channel, const char* message)
{
enum pubnub_res rslt;

Expand Down Expand Up @@ -222,7 +230,8 @@ enum pubnub_res pubnub_subscribe(pubnub_t* p,
pubnub_mutex_unlock(p->monitor);
return PNR_IN_PROGRESS;
}
rslt = pbauto_heartbeat_prepare_channels_and_ch_groups(p, &channel, &channel_group);
rslt = pbauto_heartbeat_prepare_channels_and_ch_groups(
p, &channel, &channel_group);
if (rslt != PNR_OK) {
return rslt;
}
Expand Down Expand Up @@ -256,7 +265,8 @@ enum pubnub_cancel_res pubnub_cancel(pubnub_t* pb)
}


enum pubnub_res pubnub_set_uuid(pubnub_t* p, const char* uuid) {
enum pubnub_res pubnub_set_uuid(pubnub_t* p, const char* uuid)
{
return pubnub_set_user_id(p, uuid);
}

Expand All @@ -270,7 +280,8 @@ enum pubnub_res pubnub_set_user_id(pubnub_t* pb, const char* user_id)
return res;
}

char const* pubnub_uuid_get(pubnub_t* p) {
char const* pubnub_uuid_get(pubnub_t* p)
{
return pubnub_user_id_get(p);
}

Expand Down Expand Up @@ -368,8 +379,8 @@ static char const* do_last_publish_result(pubnub_t* pb)
if (PUBNUB_DYNAMIC_REPLY_BUFFER && (NULL == pb->core.http_reply)) {
return "";
}
if (((pb->trans != PBTT_PUBLISH) && (pb->trans != PBTT_SIGNAL)) ||
(pb->core.http_reply[0] == '\0')) {
if (((pb->trans != PBTT_PUBLISH) && (pb->trans != PBTT_SIGNAL))
|| (pb->core.http_reply[0] == '\0')) {
return "";
}

Expand Down Expand Up @@ -418,7 +429,7 @@ char const* pubnub_get_origin(pubnub_t* pb)


int pubnub_origin_set(pubnub_t* pb, char const* origin)
{
{
PUBNUB_ASSERT(pb_valid_ctx_ptr(pb));
if (PUBNUB_ORIGIN_SETTABLE) {
bool origin_set = false;
Expand All @@ -440,11 +451,11 @@ int pubnub_origin_set(pubnub_t* pb, char const* origin)
}

int pubnub_port_set(pubnub_t* pb, uint16_t port)
{
{
PUBNUB_ASSERT(pb_valid_ctx_ptr(pb));
if (PUBNUB_ORIGIN_SETTABLE) {
pubnub_mutex_lock(pb->monitor);
pb->port = port;
pb->port = port;
bool port_set = (PBS_IDLE == pb->state);
pubnub_mutex_unlock(pb->monitor);

Expand Down
Loading
Loading