示例#1
0
        unsafe public int Read(byte *bufP, int count)
        {
            int r = 0;

            var fdarray = new PollFD[1];

            fdarray[0].fd     = Handle;
            fdarray[0].events = PollEvents.POLLIN | PollEvents.EPOLLRDHUP | PollEvents.EPOLLHUP | PollEvents.EPOLLERR;

            do
            {
                if (poll(fdarray, 1, -1) == -1)
                {
                    break;
                }
                if ((fdarray[0].revents & PollEvents.POLLIN) == 0)
                {
                    break;
                }
                r = (int)read(Handle, bufP, (SizeT)count);
            } while (r < 0 && UnixError.ShouldRetry);

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

            return(r);
        }
示例#2
0
        public void Listen(int backlog)
        {
            int r = listen(Handle, backlog);

            if (r < 0)
            {
                throw UnixError.GetLastUnixException();
            }
        }
示例#3
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();
            }
        }
示例#4
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);
        }
示例#5
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;
        }
示例#6
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);
        }
示例#7
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);
        }
示例#8
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;
        }
示例#9
0
        public void Shutdown()
        {
            int r = 0;

            if (Handle == -1 && connected == false)
            {
                return;
            }

            r = shutdown(Handle, ShutdownOptions.SHUT_RDWR);

            if (r < 0)
            {
                throw UnixError.GetLastUnixException();
            }
        }
示例#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);
            }
        }
示例#11
0
        //TODO: consider memory management
        public void Close()
        {
            int r = 0;

            if (Handle == -1 && connected == false)
            {
                return;
            }

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

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

            Handle    = -1;
            connected = false;
        }
示例#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));
            }
        }