diff --git a/lo/lo_lowlevel.h b/lo/lo_lowlevel.h index b521e96f..83d74edc 100644 --- a/lo/lo_lowlevel.h +++ b/lo/lo_lowlevel.h @@ -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 * diff --git a/src/send.c b/src/send.c index ea74e14d..cc0a7203 100644 --- a/src/send.c +++ b/src/send.c @@ -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) {