コード例 #1
0
        public override void Listen(string host, int port, Action <Socket> callback)
        {
            if (callback == null)
            {
                throw new ArgumentNullException("callback");
            }

            if (state != Socket.SocketState.Invalid)
            {
                throw new InvalidOperationException("Socket already in use");
            }

            this.acceptCallback = callback;

            int error;
            int fd = manos_socket_listen(host, port, 128, out error);

            if (fd < 0)
            {
                if (error == 98)
                {
                    throw new Exception(String.Format("Address {0}::{1} is already in use.", host, port));
                }
                throw new Exception(String.Format("An error occurred while trying to liste to {0}:{1} errno: {2}", host, port, error));
            }

            state = Socket.SocketState.Listening;

            stream = new PlainSocketStream(this, new IntPtr(fd));
            stream.ResumeReading();
        }
コード例 #2
0
ファイル: PlainSocket.cs プロジェクト: toptensoftware/manos
        public override void Connect(string host, int port, Action callback)
        {
            if (state != Socket.SocketState.Invalid)
                throw new InvalidOperationException ("Socket already in use");

            int error;
            var fd = manos_socket_connect (host, port, out error);

            if (fd < 0)
                throw new Exception (String.Format ("An error occurred while trying to connect to {0}:{1} errno: {2}", host, port, error));

            stream = new PlainSocketStream (this, new IntPtr (fd));

            var connectWatcher = new IOWatcher (new IntPtr (fd), EventTypes.Write, Context.Loop, (watcher, revents) => {
                watcher.Stop ();
                watcher.Dispose ();

                this.address = host;
                this.port = port;

                this.state = Socket.SocketState.Open;

                callback ();
            });
            connectWatcher.Start ();
        }
コード例 #3
0
        public override void Connect(string host, int port, Action callback)
        {
            if (state != Socket.SocketState.Invalid)
            {
                throw new InvalidOperationException("Socket already in use");
            }

            int error;
            var fd = manos_socket_connect(host, port, out error);

            if (fd < 0)
            {
                throw new Exception(String.Format("An error occurred while trying to connect to {0}:{1} errno: {2}", host, port, error));
            }

            stream = new PlainSocketStream(this, new IntPtr(fd));

            var connectWatcher = new IOWatcher(new IntPtr(fd), EventTypes.Write, Context.Loop, (watcher, revents) => {
                watcher.Stop();
                watcher.Dispose();

                this.address = host;
                this.port    = port;

                this.state = Socket.SocketState.Open;

                callback();
            });

            connectWatcher.Start();
        }
コード例 #4
0
ファイル: PlainSocket.cs プロジェクト: toptensoftware/manos
 public override void Close()
 {
     if (stream != null) {
         stream.Close ();
         stream = null;
     }
     base.Close ();
 }
コード例 #5
0
 public override void Close()
 {
     if (stream != null)
     {
         stream.Close();
         stream = null;
     }
     base.Close();
 }
コード例 #6
0
        protected override void AcceptConnections()
        {
            int error;

            int amount = manos_socket_accept_many(fd, accept_infos, MAX_ACCEPT, out error);

            if (amount < 0)
            {
                throw new Exception(String.Format("Exception while accepting. errno: {0}", error));
            }

//			Console.WriteLine ("Accepted: '{0}' connections.", amount);
            for (int i = 0; i < amount; i++)
            {
//				Console.WriteLine ("Accepted: '{0}'", accept_infos [i]);
                SocketStream iostream = new PlainSocketStream(accept_infos [i], EVIOLoop);
                OnConnectionAccepted(iostream);
            }
        }
コード例 #7
0
ファイル: PlainSocket.cs プロジェクト: toptensoftware/manos
        public override void Listen(string host, int port, Action<Socket> callback)
        {
            if (callback == null)
                throw new ArgumentNullException ("callback");

            if (state != Socket.SocketState.Invalid)
                throw new InvalidOperationException ("Socket already in use");

            this.acceptCallback = callback;

            int error;
            int fd = manos_socket_listen (host, port, 128, out error);

            if (fd < 0) {
                if (error == 98)
                    throw new Exception (String.Format ("Address {0}::{1} is already in use.", host, port));
                throw new Exception (String.Format ("An error occurred while trying to liste to {0}:{1} errno: {2}", host, port, error));
            }

            state = Socket.SocketState.Listening;

            stream = new PlainSocketStream (this, new IntPtr (fd));
            stream.ResumeReading ();
        }
コード例 #8
0
ファイル: PlainSocket.cs プロジェクト: toptensoftware/manos
 PlainSocket(Context context, SocketInfo info)
     : base(context, info)
 {
     stream = new PlainSocketStream (this, new IntPtr (info.fd));
     this.state = Socket.SocketState.Open;
 }
コード例 #9
0
ファイル: PlainSocket.cs プロジェクト: restrepo/manos
 PlainSocket(IOLoop loop, SocketInfo info)
     : base(loop, info)
 {
     stream = new PlainSocketStream (this, new IntPtr (info.fd));
     this.state = Socket.SocketState.Open;
 }
コード例 #10
0
ファイル: PlainSocketStream.cs プロジェクト: aaronfeng/manos
        protected override void AcceptConnections()
        {
            int error;

            int amount = manos_socket_accept_many (fd, accept_infos, MAX_ACCEPT, out error);
            if (amount < 0)
                throw new Exception (String.Format ("Exception while accepting. errno: {0}", error));

            //			Console.WriteLine ("Accepted: '{0}' connections.", amount);
            for (int i = 0; i < amount; i++) {
            //				Console.WriteLine ("Accepted: '{0}'", accept_infos [i]);
                SocketStream iostream = new PlainSocketStream (accept_infos [i], EVIOLoop);
                OnConnectionAccepted (iostream);
            }
        }
コード例 #11
0
 PlainSocket(Context context, SocketInfo info)
     : base(context, info)
 {
     stream     = new PlainSocketStream(this, new IntPtr(info.fd));
     this.state = Socket.SocketState.Open;
 }
コード例 #12
0
 PlainSocket(IOLoop loop, SocketInfo info)
     : base(loop, info)
 {
     stream     = new PlainSocketStream(this, new IntPtr(info.fd));
     this.state = Socket.SocketState.Open;
 }