0

我对 GIO 有疑问。我正在通过网络传输数据,它对于接收到的一定百分比的字节(通过 STRINGSIZE 更改)非常有效,但之后它什么也不复制。例如,如果 STRINGSIZE 为 350,它只复制超过 50 个字节。有任何想法吗?

    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);
     }
4

2 回答 2

0

德拉恩是对的。如果您想一次获取所有数据,请改用g_input_stream_read_all

于 2013-06-11T21:41:53.787 回答
0

您没有评估实际读取的字节数g_input_stream_read返回 - 这可能与请求的字节数不同。

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

更多的输出和带有随机字符串的示例传输会很好。

于 2013-06-11T15:25:55.530 回答