static void OnCallback(IntPtr s, int type, IntPtr address, IntPtr data, IntPtr info) { var socket = GCHandle.FromIntPtr(info).Target as CFSocket; CFSocketCallBackType cbType = (CFSocketCallBackType)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 { result = (CFSocketError)Marshal.ReadInt32(data); } socket.OnConnect(new CFSocketConnectEventArgs(result)); } }
public CFSocketSignature(AddressFamily family, SocketType type, ProtocolType proto, CFSocketAddress address) { this.protocolFamily = AddressFamilyToInt(family); this.socketType = SocketTypeToInt(type); this.protocol = ProtocolToInt(proto); this.address = address.Handle; }
public void Connect(IPEndPoint endpoint, double timeout) { using (var address = new CFSocketAddress(endpoint)) { var error = CFSocketConnectToAddress(Handle, address.Handle, timeout); if (error != CFSocketError.Success) { throw new CFSocketException(error); } } }
public static void CreatePairWithPeerSocketSignature(AddressFamily family, SocketType type, ProtocolType proto, IPEndPoint endpoint, out CFReadStream readStream, out CFWriteStream writeStream) { using (var address = new CFSocketAddress(endpoint)) { var sig = new CFSocketSignature(family, type, proto, address); IntPtr read, write; CFStreamCreatePairWithPeerSocketSignature(IntPtr.Zero, ref sig, out read, out write); readStream = new CFReadStream(read); writeStream = new CFWriteStream(write); } }
public void SetAddress(IPEndPoint endpoint) { EnableCallBacks(CFSocketCallBackType.AcceptCallBack); var flags = GetSocketFlags(); flags |= CFSocketFlags.AutomaticallyReenableAcceptCallBack; SetSocketFlags(flags); using (var address = new CFSocketAddress(endpoint)) { var error = CFSocketSetAddress(Handle, address.Handle); if (error != CFSocketError.Success) { throw new CFSocketException(error); } } }
public static CFSocket CreateConnectedToSocketSignature(AddressFamily family, SocketType type, ProtocolType proto, IPEndPoint endpoint, double timeout) { var cbTypes = CFSocketCallBackType.ConnectCallBack | CFSocketCallBackType.DataCallBack; using (var address = new CFSocketAddress(endpoint)) { var sig = new CFSocketSignature(family, type, proto, address); var handle = CFSocketCreateConnectedToSocketSignature( IntPtr.Zero, ref sig, cbTypes, OnCallback, IntPtr.Zero, timeout); if (handle == IntPtr.Zero) { throw new CFSocketException(CFSocketError.Error); } return(new CFSocket(handle)); } }
public static void CreatePairWithPeerSocketSignature(AddressFamily family, SocketType type, ProtocolType proto, IPEndPoint endpoint, out CFReadStream readStream, out CFWriteStream writeStream) { using (var address = new CFSocketAddress (endpoint)) { var sig = new CFSocketSignature (family, type, proto, address); IntPtr read, write; CFStreamCreatePairWithPeerSocketSignature (IntPtr.Zero, ref sig, out read, out write); readStream = new CFReadStream (read); writeStream = new CFWriteStream (write); } }
public static CFHost CreateWithAddress(IPAddress address) { using (var data = new CFSocketAddress (new IPEndPoint (address, 0))) { return new CFHost (CFHostCreateWithAddress (IntPtr.Zero, data.Handle)); } }
public static CFHost Create (IPEndPoint endpoint) { using (var data = new CFSocketAddress (endpoint)) return new CFHost (CFHostCreateWithAddress (IntPtr.Zero, data.Handle)); }
public CFSocketSignature (AddressFamily family, SocketType type, ProtocolType proto, CFSocketAddress address) { this.protocolFamily = AddressFamilyToInt (family); this.socketType = SocketTypeToInt (type); this.protocol = ProtocolToInt (proto); this.address = address.Handle; }
public void Connect (IPEndPoint endpoint, double timeout) { using (var address = new CFSocketAddress (endpoint)) { var error = CFSocketConnectToAddress (handle, address.Handle, timeout); if (error != CFSocketError.Success) throw new CFSocketException (error); } }
public void SetAddress (IPEndPoint endpoint) { EnableCallBacks (CFSocketCallBackType.AcceptCallBack); var flags = GetSocketFlags (); flags |= CFSocketFlags.AutomaticallyReenableAcceptCallBack; SetSocketFlags (flags); using (var address = new CFSocketAddress (endpoint)) { var error = CFSocketSetAddress (handle, address.Handle); if (error != CFSocketError.Success) throw new CFSocketException (error); } }
public static CFSocket CreateConnectedToSocketSignature (AddressFamily family, SocketType type, ProtocolType proto, IPEndPoint endpoint, double timeout) { var cbTypes = CFSocketCallBackType.ConnectCallBack | CFSocketCallBackType.DataCallBack; using (var address = new CFSocketAddress (endpoint)) { var sig = new CFSocketSignature (family, type, proto, address); var handle = CFSocketCreateConnectedToSocketSignature ( IntPtr.Zero, ref sig, cbTypes, OnCallback, IntPtr.Zero, timeout); if (handle == IntPtr.Zero) throw new CFSocketException (CFSocketError.Error); return new CFSocket (handle); } }