+ * gst_rtsp_watch_write_data:
+ * @watch: a #GstRTSPWatch
+ * @data: the data to queue
+ * @size: the size of @data
+ * @id: location for a message ID or %NULL
+ *
+ * Write @data using the connection of the @watch. If it cannot be sent
+ * immediately, it will be queued for transmission in @watch. The contents of
+ * @message will then be serialized and transmitted when the connection of the
+ * @watch becomes writable. In case the @message is queued, the ID returned in
+ * @id will be non-zero and used as the ID argument in the message_sent
+ * callback.
+ *
+ * This function will take ownership of @data and g_free() it after use.
+ *
+ * Returns: #GST_RTSP_OK on success.
+ *
+ * Since: 0.10.25
+ */
+GstRTSPResult
+gst_rtsp_watch_write_data (GstRTSPWatch * watch, const guint8 * data,
+ guint size, guint * id)
+{
+ GstRTSPResult res;
+ GstRTSPRec *rec;
+ guint off = 0;
+ GMainContext *context = NULL;
+
+ g_return_val_if_fail (watch != NULL, GST_RTSP_EINVAL);
+ g_return_val_if_fail (data != NULL, GST_RTSP_EINVAL);
+ g_return_val_if_fail (size != 0, GST_RTSP_EINVAL);
+
+ g_mutex_lock (watch->mutex);
+
+ /* try to send the message synchronously first */
+ if (watch->messages->length == 0) {
+ res = write_bytes (watch->writefd.fd, data, &off, size);
+ if (res != GST_RTSP_EINTR) {
+ if (id != NULL)
+ *id = 0;
+ g_free ((gpointer) data);
+ goto done;
+ }
+ }
+
+ /* make a record with the data and id for sending async */
+ rec = g_slice_new (GstRTSPRec);
+ if (off == 0) {
+ rec->data = (guint8 *) data;
+ rec->size = size;
+ } else {
+ rec->data = g_memdup (data + off, size - off);
+ rec->size = size - off;
+ g_free ((gpointer) data);
+ }
+
+ do {
+ /* make sure rec->id is never 0 */
+ rec->id = ++watch->id;
+ } while (G_UNLIKELY (rec->id == 0));
+
+ /* add the record to a queue. FIXME we would like to have an upper limit here */
+ g_queue_push_head (watch->messages, rec);
+
+ /* make sure the main context will now also check for writability on the
+ * socket */
+ if (watch->writefd.events != WRITE_COND) {
+ watch->writefd.events = WRITE_COND;
+ context = ((GSource *) watch)->context;
+ }
+
+ if (id != NULL)
+ *id = rec->id;
+ res = GST_RTSP_OK;
+
+done:
+ g_mutex_unlock (watch->mutex);
+
+ if (context)
+ g_main_context_wakeup (context);
+
+ return res;
+}
+
+/**
+ * gst_rtsp_watch_send_message:
+ * @watch: a #GstRTSPWatch
+ * @message: a #GstRTSPMessage
+ * @id: location for a message ID or %NULL
+ *
+ * Send a @message using the connection of the @watch. If it cannot be sent
+ * immediately, it will be queued for transmission in @watch. The contents of
+ * @message will then be serialized and transmitted when the connection of the
+ * @watch becomes writable. In case the @message is queued, the ID returned in
+ * @id will be non-zero and used as the ID argument in the message_sent
+ * callback.
+ *
+ * Returns: #GST_RTSP_OK on success.
+ *
+ * Since: 0.10.25
+ */
+GstRTSPResult
+gst_rtsp_watch_send_message (GstRTSPWatch * watch, GstRTSPMessage * message,
+ guint * id)
+{
+ GString *str;
+ guint size;
+
+ g_return_val_if_fail (watch != NULL, GST_RTSP_EINVAL);
+ g_return_val_if_fail (message != NULL, GST_RTSP_EINVAL);
+
+ /* make a record with the message as a string and id */
+ str = message_to_string (watch->conn, message);
+ size = str->len;
+ return gst_rtsp_watch_write_data (watch,
+ (guint8 *) g_string_free (str, FALSE), size, id);
+}
+
+/**