+ gint file = GPOINTER_TO_INT (handle);
+ guint32 len = mono_array_length (arry);
+ guchar *buf = mono_array_addr (arry, guchar, 0);
+
+ if (egd) {
+ const char *socket_path = g_getenv ("MONO_EGD_SOCKET");
+ /* exception will be thrown in managed code */
+ if (socket_path == NULL)
+ return NULL;
+ get_entropy_from_server (socket_path, mono_array_addr (arry, guchar, 0), mono_array_length (arry));
+ return (gpointer) -1;
+ } else {
+ /* Read until the buffer is filled. This may block if using NAME_DEV_RANDOM. */
+ gint count = 0;
+ gint err;
+
+ do {
+ err = read (file, buf + count, len - count);
+ if (err < 0) {
+ if (errno == EINTR)
+ continue;
+ break;
+ }
+ count += err;
+ } while (count < len);
+
+ if (err < 0) {
+ g_warning("Entropy error! Error in read (%s).", strerror (errno));
+ /* exception will be thrown in managed code */
+ return NULL;
+ }
+ }
+
+ /* We do not support PRNG seeding right now but the class library is this */
+
+ return handle;