private static void ReceiveAsync(IntPtr info) { InternalReceiveAsync(info, false, (socket, socketobject, data, buffer, ofs, count, flags, remoteep, callback) => { bool success = false; if ((success = SocketExtension.BeginReceive(socket, buffer, ofs, count, flags, (result) => { int len = SocketExtension.EndReceive(socket, result, out SocketError error); NSJSVirtualMachine machine = socketobject.VirtualMachine; machine.Join((sender, state) => { if (len > 0) { for (int i = ofs; i < len; i++) { data[i] = buffer[i]; } } if (callback != null) { callback.Call(socketobject, NSJSInt32.New(machine, unchecked ((int)error)), NSJSInt32.New(machine, len)); } }); }))) { if (callback != null) { callback.CrossThreading = true; } data.CrossThreading = true; } return(success); });
private unsafe void ProcessReceive(IAsyncResult result) { if (_buffer == null) { _buffer = new byte[SocketExtension.MSS]; } if (result == null) { int len = SocketExtension.MSS; if (frame != null) { long surplus = frame.payload_surplus; if (surplus < len) { len = (int)surplus; } } if (!SocketExtension.BeginReceive(socket, _buffer, 0, len, ProcessReceive)) { CloseOrError(true); } } else { int len = SocketExtension.EndReceive(socket, result); if (len <= 0) { CloseOrError(false); } else { fixed(byte *pinned = _buffer) { ProcessReceive(pinned, len); } } } }