public override void Connect(IPEndPoint endpoint, Action callback, Action <Exception> error) { CheckDisposed(); if (endpoint == null) { throw new ArgumentNullException("endpoint"); } if (callback == null) { throw new ArgumentNullException("callback"); } if (error == null) { throw new ArgumentNullException("error"); } int err; ManosIPEndpoint ep = endpoint; err = SocketFunctions.manos_socket_connect_ip(fd, ref ep, out err); if (err != 0) { throw Errors.SocketFailure("Connect failure", err); } else { localname = endpoint; } IsConnected = true; callback(); }
public override void Connect(IPEndPoint endpoint, Action callback, Action <Exception> error) { CheckDisposed(); if (endpoint == null) { throw new ArgumentNullException("endpoint"); } if (callback == null) { throw new ArgumentNullException("callback"); } if (error == null) { throw new ArgumentNullException("error"); } if (localname != null && localname.AddressFamily != endpoint.AddressFamily) { throw new ArgumentException(); } if (IsConnected) { throw new InvalidOperationException(); } int err; ManosIPEndpoint ep = endpoint; err = SocketFunctions.manos_socket_connect_ip(fd, ref ep, out err); if (err != 0) { throw Errors.SocketFailure("Connect failure", err); } else { var connectWatcher = new IOWatcher(new IntPtr(fd), EventTypes.Write, Context.Loop, (watcher, revents) => { watcher.Stop(); watcher.Dispose(); var result = SocketFunctions.manos_socket_peername_ip(fd, out ep, out err); if (result < 0) { error(Errors.SocketFailure("Connect failure", err)); } else { peername = endpoint; IsConnected = true; callback(); } }); connectWatcher.Start(); } }
public override void Bind(IPEndPoint endpoint) { CheckDisposed(); if (endpoint == null) { throw new ArgumentNullException("endpoint"); } int err; ManosIPEndpoint ep = endpoint; var result = SocketFunctions.manos_socket_bind_ip(fd, ref ep, out err); if (result < 0) { throw Errors.SocketFailure("Could not bind to address", err); } else { localname = endpoint; } IsBound = true; }
public static extern int manos_socket_localname_ip(int fd, out ManosIPEndpoint ep, out int err);
public static extern int manos_socket_receivefrom_ip(int fd, byte[] buffer, int length, out ManosIPEndpoint source, out int err);
public static extern int manos_socket_sendto_ip(int fd, byte[] buffer, int offset, int length, ref ManosIPEndpoint to, out int err);
public static extern int manos_socket_accept(int fd, out ManosIPEndpoint remote, out int err);
public static extern int manos_socket_connect_ip(int fd, ref ManosIPEndpoint ep, out int err);
public static extern int manos_socket_peername_ip(int fd, out ManosIPEndpoint ep, out int err);