Merge "Mark gles pipe connected after callback invoked"
diff --git a/android/hw-pipe-net.c b/android/hw-pipe-net.c
index 5a25401..3e8dc70 100644
--- a/android/hw-pipe-net.c
+++ b/android/hw-pipe-net.c
@@ -204,10 +204,9 @@
         }
 
         loopIo_init(pipe->io, looper, fd, netPipe_io_func, pipe);
-        asyncConnector_init(pipe->connector, address, pipe->io);
+        status = asyncConnector_init(pipe->connector, address, pipe->io);
         pipe->state = STATE_CONNECTING;
 
-        status = asyncConnector_run(pipe->connector);
         if (status == ASYNC_ERROR) {
             D("%s: Could not connect to socket: %s",
               __FUNCTION__, errno_str);
@@ -234,6 +233,17 @@
     netPipe_free(pipe);
 }
 
+static int netPipeReadySend(NetPipe *pipe)
+{
+    if (pipe->state == STATE_CONNECTED)
+        return 0;
+    else if (pipe->state == STATE_CONNECTING)
+        return PIPE_ERROR_AGAIN;
+    else if (pipe->hwpipe == NULL)
+        return PIPE_ERROR_INVAL;
+    else
+        return PIPE_ERROR_IO;
+}
 
 static int
 netPipe_sendBuffers( void* opaque, const GoldfishPipeBuffer* buffers, int numBuffers )
@@ -245,6 +255,10 @@
     const GoldfishPipeBuffer* buff = buffers;
     const GoldfishPipeBuffer* buffEnd = buff + numBuffers;
 
+    ret = netPipeReadySend(pipe);
+    if (ret != 0)
+        return ret;
+
     for (; buff < buffEnd; buff++)
         count += buff->size;