Beispiel #1
0
        //assigns a name to the socket
        public void Bind(byte[] local_end)
        {
            int r = bind(Handle, local_end, (uint)local_end.Length);

            if (r < 0)
            {
                throw UnixError.GetLastUnixException();
            }
        }
Beispiel #2
0
        public void Listen(int backlog)
        {
            int r = listen(Handle, backlog);

            if (r < 0)
            {
                throw UnixError.GetLastUnixException();
            }
        }
Beispiel #3
0
        public int WriteV(IOVector *iov, int count)
        {
            //FIXME: Handle EINTR here or elsewhere
            //FIXME: handle r != count
            //TODO: check offset correctness

            int r = (int)writev(Handle, iov, count);

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

            return(r);
        }
Beispiel #4
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;
        }
Beispiel #5
0
        public int SendMsg(void *bufP, int flags)
        {
            int r = 0;

            do
            {
                r = (int)sendmsg(Handle, bufP, flags);
            } while (r < 0 && UnixError.ShouldRetry);

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

            return(r);
        }
Beispiel #6
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);
        }
Beispiel #7
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;
        }
Beispiel #8
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;
        }
Beispiel #9
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;
        }
Beispiel #10
0
        public int Write(IOVector[] iov, int offset, int count)
        {
            //FIXME: Handle EINTR here or elsewhere
            //FIXME: handle r != count
            //TODO: check offset correctness

            fixed(IOVector *bufP = &iov[offset])
            {
                int r = (int)writev(Handle, bufP + offset, count);

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

                return(r);
            }
        }
Beispiel #11
0
        unsafe public int Read(byte *bufP, int count)
        {
            int r = 0;

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

            if (r < 0)
            {
                var error = Marshal.GetLastWin32Error();
                System.Console.WriteLine("Error " + error);

                throw UnixError.GetLastUnixException();
            }

            return(r);
        }
Beispiel #12
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();
                }

                //TODO: use the returned addr
                //string str = Encoding.Default.GetString (addr, 0, (int)addrlen);
                return(new UnixSocket(r, true));
            }
        }