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(); }
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 (); }
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(); }
public override void Close() { if (stream != null) { stream.Close (); stream = null; } base.Close (); }
public override void Close() { if (stream != null) { stream.Close(); stream = null; } base.Close(); }
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); } }
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 (); }
PlainSocket(Context context, SocketInfo info) : base(context, info) { stream = new PlainSocketStream (this, new IntPtr (info.fd)); this.state = Socket.SocketState.Open; }
PlainSocket(IOLoop loop, SocketInfo info) : base(loop, info) { stream = new PlainSocketStream (this, new IntPtr (info.fd)); this.state = Socket.SocketState.Open; }
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); } }
PlainSocket(Context context, SocketInfo info) : base(context, info) { stream = new PlainSocketStream(this, new IntPtr(info.fd)); this.state = Socket.SocketState.Open; }
PlainSocket(IOLoop loop, SocketInfo info) : base(loop, info) { stream = new PlainSocketStream(this, new IntPtr(info.fd)); this.state = Socket.SocketState.Open; }