Skip to content

Commit

Permalink
cleaned and documented unix header
Browse files Browse the repository at this point in the history
  • Loading branch information
256dpi committed Aug 17, 2017
1 parent a49e41a commit df4bc6d
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 14 deletions.
2 changes: 1 addition & 1 deletion example/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ int main() {

while (true) {
int available = 0;
err = lwmqtt_unix_network_peek(&client, &network, &available);
err = lwmqtt_unix_network_peek(&network, &available);
if (err != LWMQTT_SUCCESS) {
printf("failed lwmqtt_unix_network_peek: %d\n", err);
exit(1);
Expand Down
10 changes: 5 additions & 5 deletions include/lwmqtt.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ typedef struct lwmqtt_client_t lwmqtt_client_t;
* The callbacks is expected to read up to the amount of bytes in to the passed buffer. It should block the specified
* timeout and wait for more incoming data.
*/
typedef lwmqtt_err_t (*lwmqtt_network_read_t)(lwmqtt_client_t *c, void *ref, void *buf, int len, int *read,
typedef lwmqtt_err_t (*lwmqtt_network_read_t)(lwmqtt_client_t *client, void *ref, void *buf, int len, int *read,
int timeout);

/**
Expand All @@ -94,18 +94,18 @@ typedef lwmqtt_err_t (*lwmqtt_network_read_t)(lwmqtt_client_t *c, void *ref, voi
* The callback is expected to write up to the amount of bytes from the passed buffer. It should wait up to the
* specified timeout to write the specified data to the network.
*/
typedef lwmqtt_err_t (*lwmqtt_network_write_t)(lwmqtt_client_t *c, void *ref, void *buf, int len, int *sent,
typedef lwmqtt_err_t (*lwmqtt_network_write_t)(lwmqtt_client_t *client, void *ref, void *buf, int len, int *sent,
int timeout);

/**
* The callback used to set a timer.
*/
typedef void (*lwmqtt_timer_set_t)(lwmqtt_client_t *c, void *ref, int timeout);
typedef void (*lwmqtt_timer_set_t)(lwmqtt_client_t *client, void *ref, int timeout);

/**
* The callback used to get a timers value.
*/
typedef int (*lwmqtt_timer_get_t)(lwmqtt_client_t *c, void *ref);
typedef int (*lwmqtt_timer_get_t)(lwmqtt_client_t *client, void *ref);

/**
* The callback used to forward incoming messages.
Expand All @@ -116,7 +116,7 @@ typedef int (*lwmqtt_timer_get_t)(lwmqtt_client_t *c, void *ref);
* recommended to call any further lwmqtt methods in the callback as this might result in weird call stacks. The
* callback should place the received messages in a queue and dispatch them after the caller has returned.
*/
typedef void (*lwmqtt_callback_t)(lwmqtt_client_t *, void *ref, lwmqtt_string_t *, lwmqtt_message_t *);
typedef void (*lwmqtt_callback_t)(lwmqtt_client_t *client, void *ref, lwmqtt_string_t *str, lwmqtt_message_t *msg);

/**
* The client object.
Expand Down
41 changes: 40 additions & 1 deletion include/lwmqtt/unix.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,60 @@

#include <lwmqtt.h>

/**
* The UNIX timer object.
*/
typedef struct { struct timeval end; } lwmqtt_unix_timer_t;

/**
* Callback to set the UNIX timer object.
*/
void lwmqtt_unix_timer_set(lwmqtt_client_t *client, void *ref, int timeout);

/**
* Callback to read the UNIX timer object.
*/
int lwmqtt_unix_timer_get(lwmqtt_client_t *client, void *ref);

/**
* The UNIX network object.
*/
typedef struct { int socket; } lwmqtt_unix_network_t;

/**
* Function to establish a UNIX network connection.
*
* @param network - The network object.
* @param host - The host.
* @param port - The port.
* @return An error value.
*/
lwmqtt_err_t lwmqtt_unix_network_connect(lwmqtt_unix_network_t *network, char *host, int port);

/**
* Function to disconnect a UNIX network connection.
*
* @param network - The network object.
*/
void lwmqtt_unix_network_disconnect(lwmqtt_unix_network_t *network);

lwmqtt_err_t lwmqtt_unix_network_peek(lwmqtt_client_t *client, lwmqtt_unix_network_t *network, int *available);
/**
* Function to peek available bytes on a UNIX network connection.
*
* @param network - The network object.
* @param available - The available bytes.
* @return An error value.
*/
lwmqtt_err_t lwmqtt_unix_network_peek(lwmqtt_unix_network_t *network, int *available);

/**
* Callback to read from a UNIX network connection.
*/
lwmqtt_err_t lwmqtt_unix_network_read(lwmqtt_client_t *client, void *ref, void *buf, int len, int *read, int timeout);

/**
* Callback to write to a UNIX network connection.
*/
lwmqtt_err_t lwmqtt_unix_network_write(lwmqtt_client_t *client, void *ref, void *buf, int len, int *sent, int timeout);

#endif // LWMQTT_UNIX_H
2 changes: 1 addition & 1 deletion src/os/unix.c
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ void lwmqtt_unix_network_disconnect(lwmqtt_unix_network_t *network) {
}
}

lwmqtt_err_t lwmqtt_unix_network_peek(lwmqtt_client_t *client, lwmqtt_unix_network_t *network, int *available) {
lwmqtt_err_t lwmqtt_unix_network_peek(lwmqtt_unix_network_t *network, int *available) {
// get the available bytes on the socket
int rc = ioctl(network->socket, FIONREAD, available);
if (rc < 0) {
Expand Down
12 changes: 6 additions & 6 deletions tests/client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ TEST(Client, PublishSubscribeQOS0) {

while (counter < 5) {
int available = 0;
err = lwmqtt_unix_network_peek(&client, &network, &available);
err = lwmqtt_unix_network_peek(&network, &available);
ASSERT_EQ(err, LWMQTT_SUCCESS);

if (available > 0) {
Expand Down Expand Up @@ -141,7 +141,7 @@ TEST(Client, PublishSubscribeQOS1) {

while (counter < 5) {
int available = 0;
err = lwmqtt_unix_network_peek(&client, &network, &available);
err = lwmqtt_unix_network_peek(&network, &available);
ASSERT_EQ(err, LWMQTT_SUCCESS);

if (available > 0) {
Expand Down Expand Up @@ -200,7 +200,7 @@ TEST(Client, PublishSubscribeQOS2) {

while (counter < 5) {
int available = 0;
err = lwmqtt_unix_network_peek(&client, &network, &available);
err = lwmqtt_unix_network_peek(&network, &available);
ASSERT_EQ(err, LWMQTT_SUCCESS);

if (available > 0) {
Expand Down Expand Up @@ -257,7 +257,7 @@ TEST(Client, BufferOverflowProtection) {

while (counter < 1) {
int available = 0;
err = lwmqtt_unix_network_peek(&client, &network, &available);
err = lwmqtt_unix_network_peek(&network, &available);
ASSERT_EQ(err, LWMQTT_SUCCESS);

if (available > 0) {
Expand Down Expand Up @@ -314,7 +314,7 @@ TEST(Client, BigBuffersAndPayload) {

while (counter < 5) {
int available = 0;
err = lwmqtt_unix_network_peek(&client, &network, &available);
err = lwmqtt_unix_network_peek(&network, &available);
ASSERT_EQ(err, LWMQTT_SUCCESS);

if (available > 0) {
Expand Down Expand Up @@ -376,7 +376,7 @@ TEST(Client, MultipleSubscriptions) {

while (counter < 5) {
int available = 0;
err = lwmqtt_unix_network_peek(&client, &network, &available);
err = lwmqtt_unix_network_peek(&network, &available);
ASSERT_EQ(err, LWMQTT_SUCCESS);

if (available > 0) {
Expand Down

0 comments on commit df4bc6d

Please sign in to comment.