NATS C Client with JetStream and Streaming support 3.6.1 The nats.io C Client, Supported by Synadia Communications Inc.

Loading...
Searching...
No Matches
Functions
Libuv Adapter

## Functions
void | natsLibuv_Init (void)
| Initialize the adapter.
void | natsLibuv_SetThreadLocalLoop (uv_loop_t *loop)
| Register the event loop with the thread running `uv_run()`.
natsStatus | natsLibuv_Attach (void **userData, void *loop, natsConnection *nc, natsSock socket)
| Attach a connection to the given event loop.
natsStatus | natsLibuv_Read (void *userData, bool add)
| Start or stop polling on READ events.
natsStatus | natsLibuv_Write (void *userData, bool add)
| Start or stop polling on WRITE events.
natsStatus | natsLibuv_Detach (void *userData)
| The connection is closed, it can be safely detached.

## Detailed Description

Adapter to plug a `NATS` connection to a `libuv` event loop.

## Function Documentation

## ◆ natsLibuv_Init()

void natsLibuv_Init | ( | void |  | ) |

Needs to be called once so that the adapter can initialize some state.

## ◆ natsLibuv_SetThreadLocalLoop()

void natsLibuv_SetThreadLocalLoop | ( | uv_loop_t * | loop | ) |

Since `libuv` is not thread-safe, the adapter needs to know in which thread `uv_run()` will run for the given `loop`. It allows the adapter to schedule events so that they are executed in the event loop thread.

Parameters

  loop | an event loop.

## ◆ natsLibuv_Attach()

natsStatus natsLibuv_Attach | ( | void ** | userData,
|  | void * | loop,
|  | natsConnection * | nc,
|  | natsSock | socket
| ) |  |

This callback is invoked after `NATS` library has connected, or reconnected. For a reconnect event, `*userData` will not be `NULL`. This function will start polling on READ events for the given `socket`.

Parameters

  userData | the location where the adapter stores the user object passed to the other callbacks.
  loop | the event loop as a generic pointer. Cast to appropriate type.
  nc | the connection to attach to the event loop
  socket | the socket to start polling on.

## ◆ natsLibuv_Read()

natsStatus natsLibuv_Read | ( | void * | userData,
|  | bool | add
| ) |  |

This callback is invoked to notify that the event library should start or stop polling for READ events.

Parameters

  userData | the user object created in natsLibuv_Attach
  add | `true` if the library needs to start polling, `false` otherwise.

## ◆ natsLibuv_Write()

natsStatus natsLibuv_Write | ( | void * | userData,
|  | bool | add
| ) |  |

This callback is invoked to notify that the event library should start or stop polling for WRITE events.

Parameters

  userData | the user object created in natsLibuv_Attach
  add | `true` if the library needs to start polling, `false` otherwise.

## ◆ natsLibuv_Detach()

natsStatus natsLibuv_Detach | ( | void * | userData | ) |

When a connection is closed (not disconnected, pending a reconnect), this callback will be invoked. This is the opportunity to cleanup the state maintained by the adapter for this connection.

Parameters

  userData | the user object created in natsLibuv_Attach