예제 #1
0
        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));
            }
        }
예제 #2
0
 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;
 }
예제 #3
0
 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);
         }
     }
 }
예제 #4
0
 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);
     }
 }
예제 #5
0
        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);
                }
            }
        }
예제 #6
0
        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));
            }
        }
예제 #7
0
파일: CFStream.cs 프로젝트: baulig/maccore
        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);
            }
        }
예제 #8
0
파일: CFHost.cs 프로젝트: baulig/maccore
 public static CFHost CreateWithAddress(IPAddress address)
 {
     using (var data = new CFSocketAddress (new IPEndPoint (address, 0))) {
         return new CFHost (CFHostCreateWithAddress (IntPtr.Zero, data.Handle));
     }
 }
예제 #9
0
파일: CFHost.cs 프로젝트: polipo/maccore
		public static CFHost Create (IPEndPoint endpoint)
		{
			using (var data = new CFSocketAddress (endpoint))
				return new CFHost (CFHostCreateWithAddress (IntPtr.Zero, data.Handle));
		}
예제 #10
0
		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;
		}
예제 #11
0
		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);
			}
		}
예제 #12
0
		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);
			}
		}
예제 #13
0
		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);
			}
		}