[gnome-network-displays/cc-tmp: 8/80] cc: some cleanup and add PONG message type




commit 2f7ae24a14e0eb0a8e3174aff8cd206b1724e5f1
Author: Anupam Kumar <kyteinsky gmail com>
Date:   Mon Jul 25 10:01:03 2022 +0530

    cc: some cleanup and add PONG message type

 src/nd-cc-sink.c | 27 ++++++++++++---------------
 src/nd-cc-sink.h |  1 +
 2 files changed, 13 insertions(+), 15 deletions(-)
---
diff --git a/src/nd-cc-sink.c b/src/nd-cc-sink.c
index 1a7cc17..b6784c0 100644
--- a/src/nd-cc-sink.c
+++ b/src/nd-cc-sink.c
@@ -23,7 +23,8 @@
 #include "wfd/wfd-server.h"
 #include "cc/cast_channel.pb-c.h"
 
-#define MAX_MSG_SIZE 4096
+#define MAX_MSG_SIZE 64 * 1024
+// TODO: add cancellable everywhere
 
 struct _NdCCSink
 {
@@ -422,7 +423,7 @@ tls_send (NdCCSink      * sink,
           GError        * error)
 {
   NdCCSink * self = ND_CC_SINK (sink);
-   GSocket * socket;
+  GSocket * socket;
   GInputStream * istream;
   GOutputStream * ostream;
   gssize io_bytes;
@@ -458,14 +459,10 @@ tls_send (NdCCSink      * sink,
     size -= io_bytes;
   }
 
-  // wait for response
   if (!expect_input) return TRUE;
 
-  g_debug("before");
   g_socket_condition_check (socket, G_IO_IN);
-  g_debug("after");
   io_bytes = g_input_stream_read (istream, buffer, MAX_MSG_SIZE, NULL, &error);
-  g_debug("after2");
 
   if (io_bytes <= 0)
   {
@@ -523,15 +520,9 @@ send_request (NdCCSink *sink, enum MessageType message_type, char * utf8_payload
   g_autoptr(GError) error = NULL;
   gboolean send_ok;
   Castchannel__CastMessage message;
-  // ProtobufCBinaryData binary_payload;
-  // binary_payload.data = NULL;
-  // binary_payload.len = 0;
   guint32 packed_size = 0;
   gboolean expect_input = TRUE;
-
-  // TODO: how to do this again?
-  // g_autoptr(uint8_t) *sock_buffer = NULL;
-  uint8_t *sock_buffer = NULL;
+  g_autofree uint8_t *sock_buffer = NULL;
 
   g_debug("Send request: %d", message_type);
 
@@ -563,6 +554,14 @@ send_request (NdCCSink *sink, enum MessageType message_type, char * utf8_payload
       "{ \"type\": \"PING\" }");
     break;
 
+  case MESSAGE_TYPE_PONG:
+    message = build_message(
+      "urn:x-cast:com.google.cast.tp.heartbeat",
+      CASTCHANNEL__CAST_MESSAGE__PAYLOAD_TYPE__STRING,
+      NULL,
+      "{ \"type\": \"PONG\" }");
+    break;
+
   case MESSAGE_TYPE_RECEIVER:
     message = build_message(
       "urn:x-cast:com.google.cast.receiver",
@@ -578,8 +577,6 @@ send_request (NdCCSink *sink, enum MessageType message_type, char * utf8_payload
   packed_size = castchannel__cast_message__get_packed_size(&message);
   sock_buffer = malloc(4 + packed_size);
 
-  // TODO: look for gobject way of doing this: like with g_autoptr
-
   guint32 packed_size_be = GUINT32_TO_BE(packed_size);
   memcpy(sock_buffer, &packed_size_be, 4);
   castchannel__cast_message__pack(&message, 4 + sock_buffer);
diff --git a/src/nd-cc-sink.h b/src/nd-cc-sink.h
index f40d911..e58c4a2 100644
--- a/src/nd-cc-sink.h
+++ b/src/nd-cc-sink.h
@@ -37,6 +37,7 @@ enum MessageType {
     MESSAGE_TYPE_CONNECT,
     MESSAGE_TYPE_DISCONNECT,
     MESSAGE_TYPE_PING,
+    MESSAGE_TYPE_PONG,
     MESSAGE_TYPE_RECEIVER,
 };
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]