Esempio n. 1
0
        public void Listen(int backlog)
        {
            int r = listen(Handle, backlog);

            if (r < 0)
            {
                throw UnixError.GetLastUnixException();
            }
        }
Esempio n. 2
0
        //assigns a name to the socket
        public void Bind(byte[] localEnd)
        {
            int r = bind(Handle, localEnd, (uint)localEnd.Length);

            if (r < 0)
            {
                throw UnixError.GetLastUnixException();
            }
        }
Esempio n. 3
0
        public UnixSocket()
        {
            //TODO: don't hard-code PF_UNIX and SOCK_STREAM or SocketType.Stream
            //AddressFamily family, SocketType type, ProtocolType proto

            int r = socket(AF_UNIX, SOCK_STREAM, 0);

            if (r < 0)
            {
                throw UnixError.GetLastUnixException();
            }

            Handle      = r;
            _ownsHandle = true;
        }
Esempio n. 4
0
        public int Write(byte *bufP, int count)
        {
            int r = 0;

            do
            {
                r = (int)write(Handle, bufP, (SizeT)count);
            }while (r < 0 && UnixError.ShouldRetry);

            if (r < 0)
            {
                throw UnixError.GetLastUnixException();
            }

            return(r);
        }
Esempio n. 5
0
        //TODO: consider memory management
        public void Connect(byte[] remote_end)
        {
            int r = 0;

            do
            {
                r = connect(Handle, remote_end, (uint)remote_end.Length);
            } while (r < 0 && UnixError.ShouldRetry);

            if (r < 0)
            {
                throw UnixError.GetLastUnixException();
            }

            Connected = true;
        }
Esempio n. 6
0
        public void Connect()
        {
            int r = 0;

            do
            {
                r = connect(Handle, null, 0);
            } while (r < 0 && UnixError.ShouldRetry);

            if (r < 0)
            {
                throw UnixError.GetLastUnixException();
            }

            Connected = true;
        }
Esempio n. 7
0
        //TODO: consider memory management
        public void Close()
        {
            int r = 0;

            do
            {
                r = close(Handle);
            } while (r < 0 && UnixError.ShouldRetry);

            if (r < 0)
            {
                throw UnixError.GetLastUnixException();
            }

            Handle    = -1;
            Connected = false;
        }
Esempio n. 8
0
        public UnixSocket Accept()
        {
            byte[] addr    = new byte[110];
            uint   addrlen = (uint)addr.Length;

            fixed(byte *addrP = addr)
            {
                int r = 0;

                do
                {
                    r = accept(Handle, addrP, ref addrlen);
                } while (r < 0 && UnixError.ShouldRetry);

                if (r < 0)
                {
                    throw UnixError.GetLastUnixException();
                }

                return(new UnixSocket(r, true));
            }
        }
Esempio n. 9
0
        public int Read(byte *bufP, int count)
        {
            int r = 0;

            do
            {
                r = (int)read(Handle, bufP, (SizeT)count);
            }while (r < 0 && UnixError.ShouldRetry);

            /* Read was successful */
            if (r >= 0)
            {
                return(r);
            }

            var error = Marshal.GetLastWin32Error();

            if (error == 11)              /* EAGAIN (ignore for blocking sockets) */
            {
                return(-error);
            }
            else if (error >= 103 && error <= 113)             /* Bundle common socket errno identifiers */
            {
                /* ECONNABORTED, ECONNRESET, ENOBUFS, ETIMEDOUT, ... */
                // Console.WriteLine ("IO-Error " + error);
                throw new UnixSocketException(error);
            }
            else if (error == 9)             /* EBADF */
            {
                // Console.WriteLine ("Socket closed: bad file descriptor");
                throw new UnixSocketException(error);
            }
            else
            {
                // Console.WriteLine ("Error " + error);
                throw UnixError.GetLastUnixException();
            }
        }
Esempio n. 10
0
 public UnixException(int errno)
     : base($"Error {errno}: {UnixError.GetErrorString(errno)}")
 {
     Errno = errno;
 }