public void Post(AsyncIOOperation op) { lock (ops) { ops.Add(op); evt.Set(); } }
public void ReceiveAsync(byte[] buffer, int offset, int count, OnIOComplete completionHandler) { unsafe { AsyncIOOperation op = new AsyncIOOperation(); op.overlapped = GCHandle.Alloc(new Overlapped(), GCHandleType.Pinned); Overlapped *overlapped = (Overlapped *)op.overlapped.AddrOfPinnedObject(); overlapped->hEvent = CreateEventW(IntPtr.Zero, true, false, IntPtr.Zero); op.buffy = GCHandle.Alloc(new WSABuf(), GCHandleType.Pinned); WSABuf *buffy = (WSABuf *)op.buffy.AddrOfPinnedObject(); op.bytes = GCHandle.Alloc(buffer, GCHandleType.Pinned); buffy->buf = op.bytes.AddrOfPinnedObject() + offset; buffy->len = (uint)count; op.flags = GCHandle.Alloc(0, GCHandleType.Pinned); int r = WSARecv(Handle, new IntPtr(buffy), 1, IntPtr.Zero, op.flags.AddrOfPinnedObject(), new IntPtr(overlapped), IntPtr.Zero); int a = WSAGetLastError(); op.fd = Handle; op.cb = completionHandler; IOLoop.dispatch_loop.Post(op); } }