0

I have a problem with GIO. I am transmitting data over a network and it works perfectly for a percentage of bytes received (changed via STRINGSIZE) but after that it copies nothing. For Example if STRINGSIZE is 350 it only copies over 50 bytes. Any ideas?

    gboolean recieve_complete(GSocketService *socket, GSocketConnection *connection,      GObject *source_object, gpointer user_data){
          GInputStream * input;
          int i;
          int *recieved_data = malloc(sizeof(int) * (STRINGSIZE + 50));
          for(i = 0; i < (STRINGSIZE + 50); i++)
              recieved_data[i] = 0;  //Sets register to empty.

          input = g_io_stream_get_input_stream(G_IO_STREAM(connection));
          g_input_stream_read (input, recieved_data, (STRINGSIZE + 50), NULL, NULL);
          proccess_data(recieved_data);
          free(recieved_data);
     }
liberforce
  • 11,189
  • 37
  • 48
hein13
  • 69
  • 1
  • 4
  • possibly your input stream does not have length upto STRINGSIZE+50.so it is getting copied upto its length only? – Dayal rai Jun 11 '13 at 13:02
  • Input Stream is STRINGSIZE+50 as well. Both confirm the full STRINGSIZE+50 is sent and received. Yet on the receiving end most of it is empty – hein13 Jun 11 '13 at 13:04

2 Answers2

0

You are not evaluating the number of actually read bytes g_input_stream_read returns - this may differ from the requested number of bytes.

https://developer.gnome.org/gio/2.32/GInputStream.html#g-input-stream-read

Some more output and a example transfer with a random string would be nice.

drahnr
  • 6,782
  • 5
  • 48
  • 75
0

drahnr is right. If you want to get all the data at once, use g_input_stream_read_all instead.

liberforce
  • 11,189
  • 37
  • 48