Beispiel #1
0
        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();
        }
Beispiel #2
0
        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();
            }
        }
Beispiel #3
0
        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;
        }
Beispiel #4
0
 public static extern int manos_socket_localname_ip(int fd, out ManosIPEndpoint ep, out int err);
Beispiel #5
0
 public static extern int manos_socket_receivefrom_ip(int fd, byte[] buffer, int length,
                                                      out ManosIPEndpoint source, out int err);
Beispiel #6
0
 public static extern int manos_socket_sendto_ip(int fd, byte[] buffer, int offset, int length,
                                                 ref ManosIPEndpoint to, out int err);
Beispiel #7
0
 public static extern int manos_socket_accept(int fd, out ManosIPEndpoint remote, out int err);
Beispiel #8
0
 public static extern int manos_socket_connect_ip(int fd, ref ManosIPEndpoint ep, out int err);
Beispiel #9
0
 public static extern int manos_socket_accept(int fd, out ManosIPEndpoint remote, out int err);
Beispiel #10
0
 public static extern int manos_socket_sendto_ip(int fd, byte[] buffer, int offset, int length,
                                                 ref ManosIPEndpoint to, out int err);
Beispiel #11
0
 public static extern int manos_socket_receivefrom_ip(int fd, byte[] buffer, int length,
                                                      out ManosIPEndpoint source, out int err);
Beispiel #12
0
 public static extern int manos_socket_peername_ip(int fd, out ManosIPEndpoint ep, out int err);
Beispiel #13
0
 public static extern int manos_socket_connect_ip(int fd, ref ManosIPEndpoint ep, out int err);