ext/iodine/websockets.c
/**
 * Enables (or disables) broadcast optimizations.
 *
 * When using WebSocket pub/sub system is originally optimized for either
 * non-direct transmission (messages are handled by callbacks) or direct
 * transmission to 1-3 clients per channel (on average), meaning that the
 * majority of the messages are meant for a single recipient (or multiple
 * callback recipients) and only some are expected to be directly transmitted to
 * a group.
 *
 * However, when most messages are intended for direct transmission to more than
 * 3 clients (on average), certain optimizations can be made to improve memory
 * consumption (minimize duplication or WebSocket network data).
 *
 * This function allows enablement (or disablement) of these optimizations.
 * These optimizations include:
 *
 * * WEBSOCKET_OPTIMIZE_PUBSUB - optimize all direct transmission messages,
 *                               best attempt to detect Text vs. Binary data.
 * * WEBSOCKET_OPTIMIZE_PUBSUB_TEXT - optimize direct pub/sub text messages.
 * * WEBSOCKET_OPTIMIZE_PUBSUB_BINARY - optimize direct pub/sub binary messages.
 *
 * Note: to disable an optimization it should be disabled the same amount of
 * times it was enabled - multiple optimization enablements for the same type
 * are merged, but reference counted (disabled when reference is zero).
 */
Enables (or disables) broadcast optimizations.
When using WebSocket pub/sub system is originally optimized for either
non-direct transmission (messages are handled by callbacks) or direct
transmission to 1-3 clients per channel (on average), meaning that the
majority of the messages are meant for a single recipient (or multiple
callback recipients) and only some are expected to be directly transmitted to
a group.

However, when most messages are intended for direct transmission to more than
3 clients (on average), certain optimizations can be made to improve memory
consumption (minimize duplication or WebSocket network data).

This function allows enablement (or disablement) of these optimizations.
These optimizations include.

optimize all direct transmission messages,
best attempt to detect Text vs. Binary data.
WEBSOCKET_OPTIMIZE_PUBSUB_TEXT - optimize direct pub/sub text messages.
WEBSOCKET_OPTIMIZE_PUBSUB_BINARY - optimize direct pub/sub binary messages.

to disable an optimization it should be disabled the same amount of
times it was enabled - multiple optimization enablements for the same type
are merged, but reference counted (disabled when reference is zero).
Enables ( or disables ) broadcast optimizations . When using WebSocket pub / sub system is originally optimized for either non - direct transmission ( messages are handled by callbacks ) or direct transmission to 1 - 3 clients per channel ( on average ) meaning that the majority of the messages are meant for a single recipient ( or multiple callback recipients ) and only some are expected to be directly transmitted to a group . However when most messages are intended for direct transmission to more than 3 clients ( on average ) certain optimizations can be made to improve memory consumption ( minimize duplication or WebSocket network data ) . This function allows enablement ( or disablement ) of these optimizations . These optimizations include . optimize all direct transmission messages best attempt to detect Text vs . Binary data . WEBSOCKET_OPTIMIZE_PUBSUB_TEXT - optimize direct pub / sub text messages . WEBSOCKET_OPTIMIZE_PUBSUB_BINARY - optimize direct pub / sub binary messages . to disable an optimization it should be disabled the same amount of times it was enabled - multiple optimization enablements for the same type are merged but reference counted ( disabled when reference is zero ) .
void websocket_optimize4broadcasts(intptr_t type, int enable) {
  static intptr_t generic = 0;
  static intptr_t text = 0;
  static intptr_t binary = 0;
  fio_msg_metadata_s (*callback)(fio_str_info_s, fio_str_info_s, uint8_t);
  intptr_t *counter;
  switch ((0 - type)) {
  case (0 - WEBSOCKET_OPTIMIZE_PUBSUB):
    counter = &generic;
    callback = websocket_optimize_generic;
    break;
  case (0 - WEBSOCKET_OPTIMIZE_PUBSUB_TEXT):
    counter = &text;
    callback = websocket_optimize_text;
    break;
  case (0 - WEBSOCKET_OPTIMIZE_PUBSUB_BINARY):
    counter = &binary;
    callback = websocket_optimize_binary;
    break;
  default:
    return;
  }
  if (enable) {
    if (fio_atomic_add(counter, 1) == 1) {
      fio_message_metadata_callback_set(callback, 1);
    }
  } else {
    if (fio_atomic_sub(counter, 1) == 0) {
      fio_message_metadata_callback_set(callback, 0);
    }
  }
}
void websocket_optimize4broadcasts ( intptr_t type , int enable ) { static intptr_t generic = 0 ; static intptr_t text = 0 ; static intptr_t binary = 0 ; fio_msg_metadata_s ( * callback ) ( fio_str_info_s , fio_str_info_s , uint8_t ) ; intptr_t * counter ; switch ( ( 0 - type ) ) { case ( 0 - WEBSOCKET_OPTIMIZE_PUBSUB ) : counter = & generic ; callback = websocket_optimize_generic ; break ; case ( 0 - WEBSOCKET_OPTIMIZE_PUBSUB_TEXT ) : counter = & text ; callback = websocket_optimize_text ; break ; case ( 0 - WEBSOCKET_OPTIMIZE_PUBSUB_BINARY ) : counter = & binary ; callback = websocket_optimize_binary ; break ; default : return ; } if ( enable ) { if ( fio_atomic_add ( counter , 1 ) == 1 ) { fio_message_metadata_callback_set ( callback , 1 ) ; } } else { if ( fio_atomic_sub ( counter , 1 ) == 0 ) { fio_message_metadata_callback_set ( callback , 0 ) ; } } }
Enables (or disables) broadcast optimizations.
Enables ( or disables ) broadcast optimizations .