Example #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();
        }
Example #2
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 ();
        }
Example #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();
        }
Example #4
0
 public override void Close()
 {
     if (stream != null) {
         stream.Close ();
         stream = null;
     }
     base.Close ();
 }
Example #5
0
 public override void Close()
 {
     if (stream != null)
     {
         stream.Close();
         stream = null;
     }
     base.Close();
 }
Example #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);
            }
        }
Example #7
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 ();
        }
Example #8
0
 PlainSocket(Context context, SocketInfo info)
     : base(context, info)
 {
     stream = new PlainSocketStream (this, new IntPtr (info.fd));
     this.state = Socket.SocketState.Open;
 }
Example #9
0
 PlainSocket(IOLoop loop, SocketInfo info)
     : base(loop, info)
 {
     stream = new PlainSocketStream (this, new IntPtr (info.fd));
     this.state = Socket.SocketState.Open;
 }
Example #10
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);
            }
        }
Example #11
0
 PlainSocket(Context context, SocketInfo info)
     : base(context, info)
 {
     stream     = new PlainSocketStream(this, new IntPtr(info.fd));
     this.state = Socket.SocketState.Open;
 }
Example #12
0
 PlainSocket(IOLoop loop, SocketInfo info)
     : base(loop, info)
 {
     stream     = new PlainSocketStream(this, new IntPtr(info.fd));
     this.state = Socket.SocketState.Open;
 }