protected virtual void Dispose(bool disposing) { if (data != null) { data.Dispose(); data = null; } }
public unsafe CFDataBuffer(byte[] buffer) { this.buffer = buffer; /* * Copy the buffer to allow the native side to take ownership. */ fixed(byte *ptr = buffer) data = CFData.FromData((IntPtr)ptr, buffer.Length); }
static void OnCallback(IntPtr s, nuint type, IntPtr address, IntPtr data, IntPtr info) { var socket = GCHandle.FromIntPtr(info).Target as CFSocket; if (socket is null) { return; } CFSocketCallBackType cbType = (CFSocketCallBackType)(ulong)type; if (cbType == CFSocketCallBackType.AcceptCallBack) { var ep = CFSocketAddress.EndPointFromAddressPtr(address); var handle = new CFSocketNativeHandle(Marshal.ReadInt32(data)); socket.OnAccepted(new CFSocketAcceptEventArgs(handle, ep)); } else if (cbType == CFSocketCallBackType.ConnectCallBack) { CFSocketError result; if (data == IntPtr.Zero) { result = CFSocketError.Success; } else { // Note that we read a 32bit value even if CFSocketError is a nint: // 'or a pointer to an SInt32 error code if the connect failed.' result = (CFSocketError)Marshal.ReadInt32(data); } socket.OnConnect(new CFSocketConnectEventArgs(result)); } else if (cbType == CFSocketCallBackType.DataCallBack) { var ep = CFSocketAddress.EndPointFromAddressPtr(address); using (var cfdata = new CFData(data, false)) socket.OnData(new CFSocketDataEventArgs(ep, cfdata.GetBuffer())); } else if (cbType == CFSocketCallBackType.NoCallBack) { // nothing to do } else if (cbType == CFSocketCallBackType.ReadCallBack) { socket.OnRead(new CFSocketReadEventArgs()); } else if (cbType == CFSocketCallBackType.WriteCallBack) { socket.OnWrite(new CFSocketWriteEventArgs()); } }
private string CFData() { CFData typeArray = new CFData(typeRef); return(Convert.ToBase64String(typeArray.ToByteArray())); }
private string CFData() { CFData typeArray = new CFData(typeRef); return Convert.ToBase64String(typeArray.ToByteArray()); }
public CFDataBuffer(IntPtr ptr) { data = new CFData(ptr, false); buffer = data.GetBuffer(); }