Skip to content
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

add send_serialized_message() #75

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
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
25 changes: 25 additions & 0 deletions lo/lo_lowlevel.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,31 @@ int lo_send_message(lo_address targ, const char *path, lo_message msg);
int lo_send_message_from(lo_address targ, lo_server serv,
const char *path, lo_message msg);


/**
* \brief Send a serialized lo_message object to target targ
*
* This is slightly more efficient than lo_send() if you want to send a lot of
* similar messages. The messages are constructed with the lo_message_new() and
* \ref lo_message_add_int32 "lo_message_add*()" functions.
*/
int lo_send_serialized_message(lo_address targ, char *serialized_message, const size_t length);

/**
* \brief Send a serialized lo_message object to target targ from address of serv
*
* it's up to the caller to free serialized message.
*
* \param targ The address to send the message to
* \param serv The server socket to send the message from
* (can be NULL to use new socket)
* \param serialized_message The serialized message
* \param serialized_data_length length of the serialized message
*/

int lo_send_serialized_message_from(lo_address targ, lo_server serv,
char *serialized_message, const size_t serialized_data_length);

/**
* \brief Send a lo_bundle object to address targ
*
Expand Down
21 changes: 21 additions & 0 deletions src/send.c
Original file line number Diff line number Diff line change
Expand Up @@ -576,6 +576,27 @@ int lo_send_message_from(lo_address a, lo_server from, const char *path,
return ret;
}

int lo_send_serialized_message(lo_address a, char *serialized_data, const size_t length)
{
return lo_send_serialized_message_from(a, NULL, serialized_data, length);
}

int lo_send_serialized_message_from(lo_address a, lo_server from, char *serialized_data, const size_t serialized_data_length)
{

// Send the message
int ret = send_data(a, from, serialized_data, serialized_data_length);

// For TCP, retry once if it failed. The first try will return
// error if the connection was closed, so the second try will
// attempt to re-open the connection.
if (ret == -1 && a->protocol == LO_TCP)
ret = send_data(a, from, serialized_data, data_len);

// it's up to the caller to free serialized message

return ret;
}

int lo_send_bundle(lo_address a, lo_bundle b)
{
Expand Down